How to fix mount order of filesystems in RHEL 7?
https://access.redhat.com/solutions/2057993
环境
- Red Hat Enterprise Linux (RHEL) 7
问题
- Filesystems are not mounted in the order specified in
/etc/fstab - Need to mount filesystem after some specific filesystem is mounted
决议
-
In RHEL 6 it was a relatively simple matter of configuring your filesystems within the
/etc/fstabfile, specifying the order in which you would like things mounted. -
RHEL 7 filesystems are now just another system unit type. More specifically they are a unit of type "mount". If you happen to configure your filesystems within the
/etc/fstabfile, the system will simply convert these entries into dynamic "mount" unit types for the life of the running environment. You can see these dynamically created system mount unit types in/run/systemd/generator. -
To change the order of mounting or add mount dependency you can either add
systemddependencies into the/etc/fstabor change the "mount" units and move them into user-defined units is in/etc/systemd/systemdirectory.
1. Prefered method is to add systemd mount options to the fstab.
- In this scenario, there are three LVM volumes:
vg00/test0lv,vg01/test1lv, andvg02/test2lv. Each one formatted with XFS filesystem. - We want to be sure that
/test0/test2is mounted after/test0/test1volume is mounted. However, we also want to make sure that/test0/test1is mounted only after/test0is mounted. -
To achieve this configuration, we need to add a systemd option
requires-mounts-for=/mount_point_name, where/mount_point_nameis the expected mount point, to the/etc/fstabmount options field. This will create a hard dependency on it. -
The
/etc/fstabconfiguration:
/dev/vg00/test0lv /test0 xfs defaults 0 0
/dev/vg01/test1lv /test0/test1 xfs defaults,x-systemd.requires-mounts-for=/test0 0 0
/dev/vg02/test2lv /test0/test2 xfs defaults,x-systemd.requires-mounts-for=/test0/test1 0 0
- Reload systemd to refresh the configuration and unit:
# systemctl daemon-reload
- Check if the unities were created inside
/run/systemd/generator/directory:
# cat /run/systemd/generator/test0.mount
# cat /run/systemd/generator/test0-test1.mount
- The mount unit file will be similar to this:
# Automatically generated by systemd-fstab-generator
[Unit]
SourcePath=/etc/fstab
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
Before=local-fs.target
RequiresMountsFor=/test0 <---- wait for this mount point
[Mount]
What=/dev/mapper/vg01-test1lv
Where=/test0/test1
Type=xfs
Options=defaults,x-systemd.requires-mounts-for=/test0
- If you add a hard dependency, you can also see changes in
critical-chainfor the unit:
# systemd-analyze critical-chain test0-test1.mount
The time after the unit is active or started is printed after the "@" character.
The time the unit takes to start is printed after the "+" character.
test0-test1.mount +50ms
└─test0.mount @1.153s +65ms
└─dev-vg00-test0lv.device @1.146s
- You can add more dependencies and or change force the mount to be mounted after some other service starts. You can see the full list of options in man pages
man systemd.mount.
2. Changing the auto-generated mount units and removing the record from /etc/fstab.
-
Copy each "mount" unit which you want to change from
/run/systemd/generatorto/etc/systemd/system/and make any necessary adjustments to the file. -
After it is done do not forget to remove the corresponding entry from
/etc/fstab. -
Example for
/testmount point.
Filename: /etc/systemd/system/test.mount
[Unit]
Description= test mount
Requires=tmp.mount
After=tmp.mount
[Mount]
What=/dev/testvg/testlv
Where=/test
Type=ext4
[Install]
WantedBy=multi-user.target
- The Requires option means this filesystem will not be mounted unless the
/tmpfilesystem exists. The After option means the/testfilesystem will only be mounted after the/tmpfilesystem is mounted.
Note: If a mount point is beneath another mount point in the file system hierarchy, a dependency between both units is created automatically so you don't need to create a Requires and After entry for /test/test1 to mount only after /test exists and is mounted.
根源
-
With the introduction of
systemdin RHEL 7 the boot process has become a lot faster because many services and processes are now started in parallel. -
One of those consequences is the lack of consistent order in which filesystems are mounted. Their order for mounting is no longer guaranteed based on the entries in
/etc/fstab. Filesystems are now just anothersystemdunit. Because systemd defaults to parallel units execution process startup, specific target units startup order is not consistent. -
RHEL7
systemdhandles the mount order, and not the order of mount entries in/etc/fstab. Hence, the order of entries in/etc/fstabneed not be the same in which they are mounted in RHEL 7.

本文介绍如何在RHEL7中调整文件系统的挂载顺序,通过在fstab中添加systemd依赖项或修改systemd单元文件,确保文件系统按需挂载,解决因systemd并行启动带来的挂载顺序不一致问题。
2万+

被折叠的 条评论
为什么被折叠?



