How do I unmount one of two devices mounted to the same mount point?
Solution 1:
You cannot do it atomically. You can however do it with a sequence of mount --move
commands. And you will need two other directories to use as mount points.
cp /etc/mtab /root/mtab-before
mkdir /mnt/shuffle-md0 /mnt/shuffle-xvdf
mount --move /opt /mnt/shuffle-md0
mount --move /opt /mnt/shuffle-xvdf
mount --move /mnt/shuffle-md0 /opt
umount /mnt/shuffle-xvdf
cp /etc/mtab /root/mtab-after
Notice that the /etc/mtab
entry for /dev/xvdf
may end up looking pretty weird in the end. So I recommend you create a copy of /etc/mtab
before you start such that you can reconstruct that entry once you are done.
Anything opening paths through /opt
while you are shuffling around the mount points may get unexpected results. But files and directories which were opened before you started will be unaffected by this maneuver.
Solution 2:
@kasperd solution didn't work for me, because I've received the message:
It is forbidden to move a mount residing under a shared mount
The easy solution is to comment out the offending mount point in file /etc/fstab
, and reboot the server.