6

I accidentally left two different devices mounted on /opt:

/dev/xvdf on /opt type ext4 (rw,relatime,seclabel,data=ordered)
/dev/md0 on /opt type ext4 (rw,relatime,seclabel,stripe=256,data=ordered)

It would be a problem to umount /dev/md0, and things are using /opt. /dev/md0 should be mounted on top of /dev/xvdf. Any suggestions how I can just unmount /dev/xvdf?

Tried:

[root@redacted ~]# umount /dev/xvdf
umount: /dev/xvdf: umount failed: Invalid argument

[root@redacted ~]# mount --move /dev/xvdf /temp
mount: bad option. Note that moving a mount residing under a shared
       mount is unsupported.

Also I've had AWS support for volumes yell at me about force detaching in-use volumes, so that's not an option.

Some Linux Nerd
  • 3,157
  • 3
  • 18
  • 20

3 Answers3

4

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.

kasperd
  • 29,894
  • 16
  • 72
  • 122
1

@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.

david.perez
  • 111
  • 5
  • The solution to this error might be to switch all mounts into private mode with `mount --make-rprivate /`, execute the moves, and then switch the mounts back into shared mode with `mount --make-rshared /`. Check the propagation states before trying this with `findmnt -o TARGET,PROPAGATION` and adjust accordingly. – Rogach Oct 16 '21 at 10:22
0

You should be able to run:

umount /dev/xvdf /opt
  • 3
    Didn't work, but thanks! umount saw it as a list of things to unmount. TBH there probably is no way of doing this, since /opt is busy anyway. – Some Linux Nerd Oct 25 '17 at 18:40