systemd-fstab-generator¶
我在排查 Systemd挂载文件系统(自动) 神秘的自动挂载文件系统问题时,找到了根源是 systemd-fstab-generator
: 能够自动根据 /etc/fstab
生成 Systemd挂载文件系统(自动) 配置文件 XXXX.mount
,存放到 /run/systemd/generator/
目录下。
例如, ls -lh /run/systemd/generator/
可能会看到如下一些类似配置:
total 112K
-rw-r--r-- 1 root root 362 Jul 6 11:49 boot.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick0.mount
-rw-r--r-- 1 root root 355 Jul 6 11:49 data-brick10.mount
-rw-r--r-- 1 root root 355 Jul 6 11:49 data-brick11.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick1.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick2.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick3.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick4.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick5.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick6.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick7.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick8.mount
-rw-r--r-- 1 root root 351 Jul 6 11:49 data-brick9.mount
-rw-r--r-- 1 root root 178 Jul 6 11:49 dev-disk-by\x2dlabel-SWAP.swap
-rw-r--r-- 1 root root 260 Jul 6 11:49 disk10.mount
-rw-r--r-- 1 root root 260 Jul 6 11:49 disk11.mount
-rw-r--r-- 1 root root 260 Jul 6 11:49 disk12.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk2.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk3.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk4.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk5.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk6.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk7.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk8.mount
-rw-r--r-- 1 root root 258 Jul 6 11:49 disk9.mount
drwxr-xr-x 2 root root 60 Jul 6 11:49 getty.target.wants
-rw-r--r-- 1 root root 228 Jul 6 11:49 home.mount
-rw-r--r-- 1 root root 260 Jul 6 11:49 home-t4.mount
drwxr-xr-x 2 root root 580 Jul 6 11:49 local-fs.target.requires
drwxr-xr-x 2 root root 60 Jul 6 11:49 local-fs.target.wants
-rw-r--r-- 1 root root 220 Jul 6 11:49 -.mount
drwxr-xr-x 2 root root 60 Jul 6 11:49 multi-user.target.wants
drwxr-xr-x 2 root root 60 Jul 6 11:49 swap.target.requires
这些由 systemd-fstab-generator
生成的 units
没有对应的 unit-files
,所以需要使用以下命令查看:
systemctl list-units --type mount
输出案例如下:
UNIT LOAD ACTIVE SUB DESCRIPTION
-.mount loaded active mounted /
boot.mount loaded active mounted /boot
data-brick0.mount loaded active mounted /data/brick0
data-brick1.mount loaded active mounted /data/brick1
data-brick10.mount loaded active mounted /data/brick10
data-brick11.mount loaded active mounted /data/brick11
data-brick2.mount loaded active mounted /data/brick2
data-brick3.mount loaded active mounted /data/brick3
data-brick4.mount loaded active mounted /data/brick4
data-brick5.mount loaded active mounted /data/brick5
data-brick6.mount loaded active mounted /data/brick6
data-brick7.mount loaded active mounted /data/brick7
data-brick8.mount loaded active mounted /data/brick8
data-brick9.mount loaded active mounted /data/brick9
dev-hugepages.mount loaded active mounted Huge Pages File System
dev-mqueue.mount loaded active mounted POSIX Message Queue File System
● disk10.mount loaded failed failed /disk10
● disk11.mount loaded failed failed /disk11
● disk12.mount loaded failed failed /disk12
● disk2.mount loaded failed failed /disk2
● disk3.mount loaded failed failed /disk3
● disk4.mount loaded failed failed /disk4
● disk5.mount loaded failed failed /disk5
● disk6.mount loaded failed failed /disk6
● disk7.mount loaded failed failed /disk7
● disk8.mount loaded failed failed /disk8
● disk9.mount loaded failed failed /disk9
● home-t4.mount loaded failed failed /home/t4
home.mount loaded active mounted /home
proc-sys-fs-binfmt_misc.mount loaded active mounted Arbitrary Executable File Formats File System
sys-fs-fuse-connections.mount loaded active mounted FUSE Control File System
sys-kernel-config.mount loaded active mounted Configuration File System
sys-kernel-debug.mount loaded active mounted Debug File System
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
33 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
检查
data-brick0.mount
unit:
标准方法¶
对应于 systemd-fstab-generator 自动生成的 .mount
unit文件,不需要手工去停止或删除,只需要正确修改 /etc/fstab
,然后执行
systemctl daemon-reload
就可以完全同步刷新配置。之后就可以手工 umount
挂载文件系统以及做磁盘初始化了
上述步骤非常重要 否则直接umount曾经配置过 /etc/fstab
挂载配置的文件系统,都会遇到反复自动挂载。一定要遵循 Systemd挂载文件系统(自动) 经验教训