How to fix mount order of filesystems in RHEL 7?

117 篇文章 0 订阅

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/fstab file, 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/fstab file, 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 systemd dependencies into the /etc/fstab or change the "mount" units and move them into user-defined units is in /etc/systemd/system directory.

1. Prefered method is to add systemd mount options to the fstab.

  • In this scenario, there are three LVM volumes: vg00/test0lvvg01/test1lv, and vg02/test2lv. Each one formatted with XFS filesystem.
  • We want to be sure that /test0/test2 is mounted after /test0/test1 volume is mounted. However, we also want to make sure that /test0/test1 is mounted only after /test0 is mounted.
  • To achieve this configuration, we need to add a systemd option requires-mounts-for=/mount_point_name, where /mount_point_name is the expected mount point, to the /etc/fstab mount options field. This will create a hard dependency on it.

  • The /etc/fstab configuration:

Raw

/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:

Raw

# systemctl daemon-reload
  • Check if the unities were created inside /run/systemd/generator/ directory:

Raw

# cat /run/systemd/generator/test0.mount
# cat /run/systemd/generator/test0-test1.mount
  • The mount unit file will be similar to this:

Raw

# 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-chain for the unit:

Raw

# 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/generator to /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 /test mount point.

Filename: /etc/systemd/system/test.mount

Raw

[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 /tmp filesystem exists. The After option means the /testfilesystem will only be mounted after the /tmp filesystem 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 systemd in 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 another systemd unit. Because systemd defaults to parallel units execution process startup, specific target units startup order is not consistent.

  • RHEL7 systemd handles the mount order, and not the order of mount entries in /etc/fstab. Hence, the order of entries in /etc/fstab need not be the same in which they are mounted in RHEL 7.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值