Skip to content

disk

The disk module manages block device filesystems and persistent mounts. It creates filesystems, manages fstab entries using UUID, and handles mounting/unmounting.

disk "/dev/sdb1" {
fs "ext4"
mount "/mnt/data"
}
disk "/dev/sdb1" {
fs "xfs"
mount "/mnt/storage"
opts "defaults,noatime"
state "mounted"
}
disk "/dev/sdb1" {
fs "ext4"
mount "/mnt/data"
state "absent"
}
ParameterTypeDescription
(positional)stringDevice path (e.g., /dev/sdb1)
fsstringFilesystem type: ext4, xfs, btrfs, etc. (required)
mountstringMount point path (required)
optsstringfstab mount options (default: "defaults")
forcebooleanAllow reformatting an existing filesystem (default: false)
statestring"mounted" (default), "unmounted", or "absent"
  • mounted — ensure filesystem exists, fstab entry present with UUID, device mounted
  • unmounted — unmount and remove fstab entry
  • absent — unmount and remove fstab entry (does not wipe the filesystem)

The module checks:

  • Current filesystem type via blkid
  • fstab entries via grep
  • Mount status via findmnt

Only formats when the filesystem type doesn’t match. fstab entries use UUID for reliability across device name changes.

See the disk-management example for a complete disk setup with register and loop.