5

The question Best practice when mounting a new disk within an existing mount? inspired me to ask this follow-up question:

The other question asked whether it is ok to

mount /dev/sdb1 /home
mount /dev/sdb2 /home/mythtv

so that /home/mythtv is a mountpoint within the mountpoint /home. (spoiler: Yes, it is perfectly ok.).

What if I'd change the order of commands to

mount /dev/sdb2 /home/mythtv
mount /dev/sdb1 /home

Will that yield the same result or will /home/mythtv be hidden by /home? I assume /home contains an (empty) directory /home/mythtv.

11

Yes, it matters! Your first example:

mount /dev/sdb1 /home
mount /dev/sdb2 /home/mythtv

is the only right way, when mounting you must respect the tree order.

In your second example,

mount /dev/sdb2 /home/mythtv
mount /dev/sdb1 /home

If we are assuming /home/mythtv exists on the filesystem, it is gonna mount it with no problem, but after you mount the second volume you won't be able to access the first one anymore.

This is because you let the system mount sdb2 on an existing path at /home/mythtv. When you mount on /home/, you are telling your system to mount it on the /home path which also exists but is going to "cover" existing mount point. They are both mounted, but when you type cd /home/mythtv, Bash takes you to sdb1:/home/mythtv instead sdb2:/home/mythtv because they are different paths.

I hope the explanation is clear. If not, please ask in the comments, I'll try to get it to you more clearly.

Update

as per @mook765's comment, the order is important also in the fstab files:

The fstab file is read up to down while mounting, and down to up when umounting. In another case, if you try to umount /home before /home/mythtv mount will tell you the /home resource is busy because you have the /home/mythtv mounted and it cannot handle it.

| improve this answer | |
  • 2
    @PerlDuck This is also important for /etc/fstab, line order matters. – mook765 Jan 4 '19 at 11:37
  • 1
    Yes Absolutely, @mook765 say the true, fstab file when mount is read up to down, and when umount down to up, in other case if you try to umount /home before /home/mythtv mount will say to you the /home resource is busy, because have the /home/mythtv mounted and cannot handle it. – AtomiX84 Jan 4 '19 at 11:47
  • In which cases would /etc/fstab be used for unmounting? The only thing I could think of is umount -a, but that command looks at what's actually mounted, not /etc/fstab. – kasperd Jan 4 '19 at 16:02
  • by reading here seems it also used by umount: man7.org/linux/man-pages/man5/fstab.5.html, anyway after thinking a while on this (if you can confirm to me) the umount go to read the fstab when you invoke: umount /mount/point. But I repeat, may I misunderstanding the process of umount, the mount I'm sure is gonna to work like I had describe. – AtomiX84 Jan 4 '19 at 18:44
  • Up to down? You mean bottom up or top down??? – FreeSoftwareServers Jan 4 '19 at 21:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.