The Problem
On CentOS/RHEL 7, Any filesystem volumes are not getting mounted in order as per the /etc/fstab entries.
The Solution
Unlike CentOS/RHEL 6 and earlier versions, on CentOS/RHEL 7 the boot process is faster. Because of the parallel nature of process startup, specific target units startup orders are not deterministic. All the Filesystems are a systemd unit, hence their order for mounting is no longer as per the /etc/fstab entry.
Filesystems are system “unit” type. More specifically they are a unit of type “mount“. When the filesystem names are given in the /etc/fstab, the system will convert these entries into dynamic “mount” unit types.
Mounting filesystems in order
To mount filesytems in order, create the mount unit and place them in /etc/systemd/system/. Dynamically created mount unit types are in /run/systemd/generator/ location. Copy the unit files in /run/systemd/generator/ directory to use as a template for the static ones. After creating the mount unit file, copy the file into location /etc/systemd/system/. Below are some examples of setting the mount order in CentOS/RHEL 7 systems:
Filename: /etc/systemd/system/test-data1.mount
# cat /etc/systemd/system/test-data1.mount [Unit] Description=My test mount Requires=boot.mount tmp.mount After=boot.mount tmp.mount [Mount] What=/dev/datavg/data1lv Where=/test/data1 Type=xfs [Install] WantedBy=multi-user.target
The “Requires” option means this filesystem will not be mounted unless the /boot and /tmp filesystems exist. The “After” option means the /test/data1 filesystem will only be mounted after the /boot and /tmp filesystems are mounted.
Now look at the /test/data1/data2 filesystem unit file.
Filename: /etc/systemd/system/test-data1-data2.mount
# cat /etc/systemd/system/test-data1-data2.mount [Unit] Description=My test mount 2 [Mount] What=/dev/datavg/data2lv Where=/test/data1/data2 Type=xfs [Install] WantedBy=multi-user.target
Please refer to systemd.mount man page.
# man systemd.mount "If a mount point is beneath another mount point in the file system hierarchy, a dependency between both units is created automatically."
test-data1.mount unit is configured and mounted first, the test-data1-data2.mount unit will always be mounted afterward. Though /etc/fstab order is considered here in the boot sequence. It is considered by the manual “mount” command as the above steps.