Managing Systemd Mounts

WARNING:

This documentation is a draft and is not meant for production use. Branch: OL10-FSADMIN

Systemd provides a powerful way to manage file system mounts by using mount units.

All mount points defined in the file system mount table, or fstab, are processed by systemd at boot and are treated as ephemeral systemd mount targets.

However, by defining a systemd mount target explicitly, you can take advantage of many of systemd's broader capabilities. For example, you can set dependencies so that a mount is only performed after a certain dependency, such as network availability, is reached.

Systemd mount targets provide more configurable options, can provide better logging around system mounts, and can improve error handling and troubleshooting.

See the systemd.mount(5) manual page and Oracle Linux 10: System Management with systemd for more information.

You can view all system mounts, including the ephemeral mount targets loaded from the fstab by using the systemctl list-units -t mount command:

sudo systemctl list-units -t mount

Using systemd mount Targets

You can optionally create systemd mount targets to manage file system mounts that take advantage of other systemd capabilities.

Tip:

If you define systemd mount targets, it can be useful to include a comment in /etc/fstab so that system administrators are more aware that a newer convention is in use on the system.
  1. Create a mount unit file in the /etc/systemd/system directory.

    Use the systemctl edit command to create the new systemd unit file.

    sudo systemctl edit --force --full data.mount

    The command opens the default text file editor to create the target unit, /etc/systemd/system/data.mount.

    Note that you use the --force option to create a unit that doesn't exist yet. The target unit file suffix must be .mount to create a mount unit.

    1. To define a mount point you must enter the appropriate entry for a systemd mount unit.

      For example, you could enter something similar to:

      [Unit]
      Description=/mnt/data Mount Point
      
      [Mount]
      What=UUID="a80f8f10-75b6-45de-b63e-64b8b6a3a94b"
      Where=/mnt/data
      Type=xfs
      Options=defaults
                                      
      [Install]
      WantedBy=multi-user.target                            

      Replace the values:

      • What: the device or file system to mount, preferably using the block device UUID for stability across system reboots.
      • Where: the mount point where the file system is mounted. The directory location must already exist on the underlying file system.
      • Type: the file system type.
      • Options: the mount options.
    2. Save and exit the text editor.
      If the unit configuration is empty, the mount unit file isn't created.
  2. Reload the systemd daemon:

    Reload the systemd daemon to pick up the new mount unit:

    sudo systemctl daemon-reload
  3. Enable and start the mount unit.

    Enabling the unit ensures that it's remounted at boot.

    sudo systemctl enable --now data.mount
  4. Optionally, include a comment in /etc/fstab to help other system administrators.

    Add a line to the end of /etc/fstab by running a command similar to the following:

    echo '# data.mount systemd target added for /mnt/data' | sudo tee -a /etc/fstab