20

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?

3
  • 4
    Possible workaround (untested): Configure the last one as noauto and mount in rc.local? May 5, 2011 at 1:18
  • @j-g-faustus Thank you, the workaround appears to be successful.
    – ændrük
    May 6, 2011 at 5:19
  • @j-g-faustus This bounty is ending soon and your workaround is the closest thing to an answer. If you post it below I'll give you the +50.
    – ændrük
    Jun 15, 2011 at 17:29

5 Answers 5

19
+50

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.

14

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.

3
  • Nice citation. Can you tell what's the difference between requires-mounts-for and requires?
    – Anwar
    Feb 26, 2020 at 15:00
  • Looks like x-systemd.requires do the same thing! Don't know why there's two options
    – Anwar
    Feb 26, 2020 at 15:10
  • @Anwar The commit message inside the link provided by OP stated that x-systemd.requires-mounts-for may be specified more than once
    – ttimasdf
    Jan 12, 2021 at 17:01
4

Ubuntu uses mountall at boot time, not mount -a. Mountall waits for the underlying devices to appear and then mounts the fs on them immediately, unless the fs it is being mounted under has not yet been mounted, then it waits for that fs.

You should be able to get the order you want by setting the mount points of the 3 filesystems so they are stacked one under the other. Instead of mounting all three in /home/.something, put the first one in /home/.x, and the second one in /home/.x/.y, and the third in /home/.x/.y/.z.

3

I might consider setting up a script that mounts the second disks after the mount script has been called. In Ubuntu initd is the service that starts up all the componets of you operating system, and it is called upstart.

It is event based, meaning it looks / waits and emits events during the boot up process. As this post pointed out the initd service try to do things in parallel, which is probably what is causing your problems. So you could set your script to run straight after mount has finished and completed it processes.

The mount scripts are kept in the /etc/init/ directory. I would add your additional mount script there as well. Look at this description of the start up process. That site will probably help you get stared with your own script the fastest.

You need to have a start on section in your own script. See this section for starting a job after an other has finished.

I am still looking at how to create my own start up scripts my self, so I cant be any more helpful. If you do find a working solution please post it back here.

1

According to man fstab, the showthrough option might be what you're looking for. Try setting it on /home/ak and seeing if it works.

It's possible that mount forks when mounting filesystems during boot; if so, the order in which your partitions are mounted would be undefined.

1
  • 1
    showthrough did not solve the problem.
    – ændrük
    Jun 5, 2011 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .