mkunit mount

Create a systemd mount unit for filesystem mounts.

mkunit mount <mount-point> [flags]

Description

The mount command creates a .mount unit file for managing filesystem mounts through systemd. This provides better dependency management, logging, and integration with other systemd units compared to /etc/fstab.

Unit naming

Mount unit names are derived from the mount point path. For example, /mnt/data becomes mnt-data.mount. mkunit handles this conversion automatically.

Arguments

Argument Description
<mount-point> Absolute path where the filesystem will be mounted

Flags

Flag Description Default
--what <source> Device, partition, or remote path to mount
--type <fstype> Filesystem type (ext4, nfs, cifs, etc.)
--options <opts> Mount options (comma-separated)
--automount Create automount unit (mount on access) false
--timeout <seconds> Timeout for mount operation 90
--lazy-unmount Use lazy unmount on stop false
--force-unmount Force unmount on stop false
--description <text> Human-readable description Auto-generated
--after <unit> Mount after this unit
--requires <unit> Require this unit
--system Create a system mount (usually required) true
--install Install the unit file false
--start Mount immediately false
--enable Mount on boot false
--dry-run Print without writing false

Examples

Mount a local partition

sudo mkunit mount /mnt/data \
  --what /dev/sdb1 \
  --type ext4 \
  --options defaults,noatime \
  --install --enable

Mount NFS share

sudo mkunit mount /mnt/nfs-share \
  --what "192.168.1.100:/exports/data" \
  --type nfs \
  --options "rw,soft,timeo=100" \
  --after network-online.target \
  --install --enable

Mount CIFS/SMB share

sudo mkunit mount /mnt/windows-share \
  --what "//server/share" \
  --type cifs \
  --options "credentials=/etc/samba/creds,uid=1000,gid=1000" \
  --install

Automount on access

sudo mkunit mount /mnt/backup \
  --what /dev/sdc1 \
  --type ext4 \
  --automount \
  --install --enable

With --automount, the mount is only activated when something accesses the mount point, saving resources.

tmpfs mount

sudo mkunit mount /mnt/ramdisk \
  --what tmpfs \
  --type tmpfs \
  --options "size=1G,mode=1777" \
  --install --start

Bind mount

sudo mkunit mount /var/www/uploads \
  --what /mnt/storage/uploads \
  --options bind \
  --install --enable

See Also

  • mkunit service - Create services that depend on mounts
  • mkunit status - Check mount status
  • man systemd.mount - Full mount unit documentation