Mount Filesystem with systemd on RHEL, Rocky Linux, AlmaLinux, CentOS Stream and Oracle Linux

Mount a local filesystem with a systemd mount unit on RHEL 8–10, Rocky Linux, AlmaLinux, CentOS Stream and Oracle Linux without editing fstab.

Published

Updated

Read time 8 min read

Reviewed byDeepak Prasad

Mount filesystem with a systemd mount unit on RHEL, Rocky Linux, AlmaLinux, CentOS Stream and Oracle Linux

systemd can manage a local filesystem through a native .mount unit without adding a line to /etc/fstab. The same unit layout, systemctl commands, and boot integration apply on RHEL 8 through 10, Rocky Linux, AlmaLinux, CentOS Stream, and Oracle Linux.

This guide covers a normal local filesystem that mounts during boot. On-demand .automount units, network filesystems, and custom mount ordering are separate topics.

Tested on: Rocky Linux 10.2 (Red Quartz); systemd 257; XFS on /dev/sdb1; mount point /mnt/data.

NOTE
RHEL 7 is in its Extended Life Phase. CentOS Linux 7, CentOS Linux 8, and CentOS Stream 8 are end-of-life and no longer receive normal updates. The systemd mount-unit concept also exists on those releases, but this guide focuses on maintained Enterprise Linux 8, 9, and 10 systems.

systemd mount unit compatibility

Distribution Versions covered Unit directory Procedure
RHEL 8, 9, 10 /etc/systemd/system Same native .mount unit
Rocky Linux 8, 9, 10 /etc/systemd/system Same native .mount unit
AlmaLinux 8, 9, 10 /etc/systemd/system Same native .mount unit
CentOS Stream 9, 10 /etc/systemd/system Same native .mount unit
Oracle Linux 8, 9, 10 /etc/systemd/system Same native .mount unit

No distribution-specific repository or package installation is normally required. systemd and the standard mount utilities ship with the base operating system.


systemd mount unit vs /etc/fstab

/etc/fstab remains the usual human-managed interface for persistent local mounts. systemd-fstab-generator converts fstab entries into generated mount units under /run/systemd/generator/ and related generator directories during manager startup and reload.

Native .mount files are useful when configuration-management tools need a complete unit file or when you require explicit unit dependencies. They are not universally better than /etc/fstab for every local disk.

After the system boots, you can inspect fstab-generated units under the runtime generator directory:

bash
ls -l /run/systemd/generator/

Sample output:

output
boot.mount
-.mount
local-fs.target.wants
Directory Purpose
/usr/lib/systemd/system Vendor units installed by RPM packages
/run/systemd/system Runtime unit files, overrides, masks, and transient configuration
/run/systemd/generator/, /run/systemd/generator.early/, /run/systemd/generator.late/ Units dynamically created by generators, including units derived from /etc/fstab
/etc/systemd/system Administrator-created and customized units

Custom mount units in this guide belong in /etc/systemd/system, which takes precedence over vendor and normal runtime unit paths.


Check the filesystem and mount point

This walkthrough uses one example throughout:

Item Value
Device /dev/sdb1
Filesystem XFS
Mount point /mnt/data
Unit name mnt-data.mount

Inspect the block device and its filesystem metadata:

bash
lsblk --fs /dev/sdb1

Sample output:

output
NAME FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
sdb1 xfs                9ed883cb-de4f-4cd3-865b-b9e7d51d9a6f

Read the UUID and filesystem type you will reference in the unit file:

bash
blkid /dev/sdb1

Sample output:

output
/dev/sdb1: UUID="9ed883cb-de4f-4cd3-865b-b9e7d51d9a6f" BLOCK_SIZE="512" TYPE="xfs" PARTLABEL="primary"

Confirm the target path is not already mounted:

bash
findmnt /mnt/data

When nothing is mounted there, findmnt prints no target line and exits with a non-zero status.

Create the mount-point directory explicitly so you can verify the path and its parent-directory permissions before starting the unit:

bash
mkdir -p /mnt/data

After mounting the filesystem, apply the required owner, group, permissions, and SELinux labeling to the mounted filesystem itself. The metadata of the underlying empty mount-point directory is hidden while the filesystem is mounted.

IMPORTANT
This guide assumes that /dev/sdb1 already contains a filesystem. If you are preparing a new lab disk, remember that running mkfs.xfs or mkfs.ext4 destroys any existing data on the selected partition.

Generate the correct systemd mount unit name

The .mount filename must be derived from the exact Where= path. Generate it instead of guessing:

bash
systemd-escape --path --suffix=mount /mnt/data

Sample output:

output
mnt-data.mount
Mount point Unit name
/mnt/data mnt-data.mount
/srv/app/data srv-app-data.mount
/mnt/data-backup mnt-data\x2dbackup.mount

Use systemd-escape even when a filename appears obvious. Underscores are preserved, but literal hyphens, spaces, and other special characters require escaping.

For example:

bash
systemd-escape --path --suffix=mount /mnt/data-backup

Sample output:

output
mnt-data\x2dbackup.mount

The underscore path /tmp_dir correctly maps to tmp_dir.mount, while /mnt/data-backup does not map to the manually guessed name mnt-data-backup.mount.


Create the systemd mount unit

Create the administrator-managed unit in /etc/systemd/system:

bash
vi /etc/systemd/system/mnt-data.mount

Use a minimal local-filesystem unit. Replace the UUID path with the value from blkid:

ini
[Unit]
Description=Mount data filesystem on /mnt/data

[Mount]
What=/dev/disk/by-uuid/9ed883cb-de4f-4cd3-865b-b9e7d51d9a6f
Where=/mnt/data
Type=xfs
Options=defaults

[Install]
WantedBy=local-fs.target

Description= is the human-readable label in systemctl status. What= identifies the source filesystem. A persistent path under /dev/disk/by-uuid/ is preferred over a changing device name such as /dev/sdb1. Where= must match the path encoded in the filename. Type= names the filesystem (xfs, ext4, and so on). Options= lists comma-separated mount options. WantedBy=local-fs.target ties the mount into the boot-time local-filesystem stage when the unit is enabled.

Do not add DefaultDependencies=no, Conflicts=umount.target, Before=local-fs.target, or After=swap.target to an ordinary local mount. systemd inserts the normal device, shutdown, and local-filesystem dependencies automatically. Change ordering only when you have a demonstrated special requirement.


Validate and start the mount unit

Reload systemd after creating or editing the unit:

bash
systemctl daemon-reload

Validate the file before starting it:

bash
systemd-analyze verify /etc/systemd/system/mnt-data.mount

A valid unit exits silently. Mount and service management in the steps below use the systemctl command.

Start the mount:

bash
systemctl start mnt-data.mount

Check unit state:

bash
systemctl status mnt-data.mount

Sample output:

output
● mnt-data.mount - Mount data filesystem on /mnt/data
     Loaded: loaded (/etc/systemd/system/mnt-data.mount; disabled; preset: disabled)
     Active: active (mounted)
      Where: /mnt/data
       What: /dev/sdb1

Starting the unit mounts the filesystem for the current session. Enablement for future boots comes in the next section.

Verify the kernel mount table:

bash
findmnt /mnt/data

Sample output:

output
TARGET    SOURCE    FSTYPE OPTIONS
/mnt/data /dev/sdb1 xfs    rw,relatime,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota

For source, target, filesystem, and options in one line:

bash
findmnt --output SOURCE,TARGET,FSTYPE,OPTIONS /mnt/data

findmnt is more precise for mount verification than pasting full df -h output.


Enable the filesystem mount at boot

Enable the unit and mount it in one step:

bash
systemctl enable --now mnt-data.mount

After enablement, systemctl status mnt-data.mount shows enabled in the Loaded line.

Confirm enablement:

bash
systemctl is-enabled mnt-data.mount

Sample output:

output
enabled

Check that the unit is wired into the local filesystem target:

bash
systemctl list-dependencies local-fs.target | grep mnt-data

Sample output:

output
● ├─mnt-data.mount

After the next reboot, confirm the mount is still active:

bash
systemctl status mnt-data.mount
bash
findmnt /mnt/data

Both commands should show the same source device and mount point as before the reboot.


Stop, disable, or remove the mount unit

Stop and unmount the filesystem:

bash
systemctl stop mnt-data.mount

Disable boot-time activation:

bash
systemctl disable mnt-data.mount

Or combine stop and disable:

bash
systemctl disable --now mnt-data.mount

Remove the unit file and refresh systemd:

bash
rm -f /etc/systemd/system/mnt-data.mount
bash
systemctl daemon-reload

Confirm the path is no longer mounted:

bash
findmnt /mnt/data

Removing the unit does not delete or format the underlying filesystem.


Troubleshoot systemd mount unit errors

Unit name does not match Where

Regenerate the expected name:

bash
systemd-escape --path --suffix=mount /mnt/data

/mnt/data requires mnt-data.mount. A mismatched filename produces errors such as “Where setting does not match unit name”.

Dependency failed or device timed out

Inspect the device and unit logs:

bash
lsblk --fs
bash
blkid
bash
systemctl status mnt-data.mount
bash
journalctl -u mnt-data.mount -b

Common causes include an incorrect UUID, a missing disk, an inactive LVM volume, the wrong filesystem type, filesystem damage, or a device that appears too late during boot.

Mount point is already mounted

Check for an existing mount:

bash
findmnt /mnt/data

Remove a conflicting /etc/fstab entry or another native mount unit. Do not define the same mount in two places.

Target is busy during unmount

See which processes use the mount:

bash
fuser -vm /mnt/data

If the command is unavailable on a minimal installation, install the package that provides it:

bash
dnf install psmisc

Stop those processes, then retry:

bash
systemctl stop mnt-data.mount

Do not reach for force or lazy unmount as the first fix.

Unit works manually but not after reboot

Check enablement and boot logs:

bash
systemctl is-enabled mnt-data.mount
bash
systemctl list-dependencies local-fs.target
bash
journalctl -b -u mnt-data.mount

Confirm the unit has an [Install] section and was enabled with systemctl enable.

Symptom Likely cause Fix
Where does not match unit name Wrong filename systemd-escape --path --suffix=mount
Dependency failed / timeout Wrong UUID, missing disk, late device blkid, journalctl -u mnt-data.mount -b
Already mounted Duplicate fstab or unit Remove the duplicate definition
Target busy on stop Open files or processes fuser -vm, stop services first
Missing after reboot Unit not enabled Add [Install] and systemctl enable

When to use mount, automount, or fstab

Requirement Recommended method
Simple persistent local mount /etc/fstab
Complete native unit managed by automation .mount unit
Mount only when accessed .mount plus .automount
Network share /etc/fstab or native network mount with network-aware dependencies
Explicit ordering between filesystems or services Native systemd dependencies

For mount-on-access behavior, see automount a partition with systemd. For sequencing mounts relative to services or other filesystems, see mount filesystems in a specific order with systemd. For a one-off interactive mount that does not persist across reboot, see the mount command.


Conclusion

Match the .mount unit filename to the mount path with systemd-escape --path --suffix=mount. Place custom units in /etc/systemd/system, reference stable UUID paths under /dev/disk/by-uuid/ in What=, and keep systemd's automatic dependencies on ordinary local mounts. systemctl enable --now makes the native mount persistent across reboot when an [Install] section points at local-fs.target.

Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …