knowledge/technology/linux/systemd/Systemd-Mounts.md

1.4 KiB

obj
concept

Mounts are systemd unit files with a suffix of .mount. A unit configuration file whose name ends in ".mount" encodes information about a file system mount point controlled and supervised by systemd.

Mount Unit files like every unit file include the [Unit] and [Install] sections. Additionally all mount information is in the [Mount] section.

Mount Section

Fields inside the mount section:

  • What : Takes an absolute path of a device node, file or other resource to mount
  • Where : Takes an absolute path of a file or directory for the mount point; in particular, the destination cannot be a symbolic link. If the mount point does not exist at the time of mounting, it is created as either a directory or a file. The former is the usual case; the latter is done only if this mount is a bind mount and the source (What=) is not a directory. This string must be reflected in the unit filename (example: mountpoint=/home/me -> unit file: home-me.mount).
  • Type : Takes a string for the file system type. This setting is optional.
  • Options : Mount options to use when mounting. This takes a comma-separated list of options. This setting is optional.

Example

[Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab

[Mount]
What=/dev/sda1
Where=/mnt
Type=btrfs
Options=nosuid,nodev,nofail,compress=zstd,ro