How can I specify the order in which filesystems are automatically mounted?
I need a particular row in /etc/fstab
to be mounted always after two other rows:
# Always mount these first
UUID=fdf38dd4-9e9d-479d-b830-2a6989958503 / ext4 noatime,discard,errors=remount-ro 0 1
UUID=2b548eb8-fa67-46ce-a998-91d587dba62f /home/.hdd ext4 errors=remount-ro 0 2
# Always mount this second
none /home/ak aufs br:/home/.ssd/ak=rw:/home/.hdd/ak=rw 0 0
The current behavior is to often reverse the order of the last two rows in an unpredictable manner. How can I specify the necessary order?
Solution 1:
One option is to postpone mounting until after /etc/fstab
has completed, this gives you full control over the mount order.
Just add noauto
to the mount options in fstab, and mount in rc.local
.
According to the man page, mount -a
mounts the entries in fstab
sequentially, while adding the -F
('fork') option will mount them in parallell. It appears that the standard boot is using 'fork', presumably to reduce boot time, so I guess mounting (semi-)manually afterwards is the simplest way to regain control of the mount order.
Solution 2:
Systemd has now included a dependency option that enforces mount ordering. In your case add the fstab arguments:
x-systemd.requires-mounts-for=/,x-systemd.requires-mounts-for=/home/.hdd
The noauto option will not work if you need to mount over other mounted file systems. In my case the above worked see commit https://github.com/systemd/systemd/commit/3519d230c8bafe834b2dac26ace49fcfba139823 for more details.