Does order of mount operations matter when mounting into an existing mountpoint?
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
.
Solution 1:
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.