3

I have olddevice mounted to /mnt with:

$ mount olddevice /mnt

I would like to change the device at /mnt mount point. For this purpose, I simply mount newdevice on top of it:

$ mount newdevice /mnt

With that, processes that still have file descriptors on olddevice can keeps working on old device, but new processes using /mnt will use newdevice.

I can detect when olddevice is not used anymore and decide to unmount it. My problem is how to unmount it:

$ umount olddevice
umount: olddevice: umount failed: Invalid argument.

Is it possible to directly unmount it? Or is it mandatory to unmount newdevice first (I do not want that) ?

1 Answer 1

1

If you are not already running with mount propagation enabled e.g. as per systemd defaults, run this first:

mount --make-rshared /

Then:

mkdir /root.orig
mount --rbind / /root.orig
mount --make-rprivate /root.orig/mnt

mount newdevice /mnt
...
umount -R /root.orig/mnt    # instead of umount olddevice

Then safely disassemble the magic - taking care not to unmount your entire system:

mount --make-rprivate /root.orig
umount -l /root.orig
rmdir /root.orig

Usually, I like to use the recursive variants of mount / umount commands. You say you started with only one filesystem mounted underneath /mnt. In the above sequence, I used umount -R /root.orig/mnt. If there was also a filesystem mounted on a subdirectory of /mnt, this umount -R command might fail half-way through. I.e. because there are no open files on the submount, but there are still some open files on the main mount. IMO this feels similar to how umount -l works. umount -l /path disassembles and detaches a mount tree, and each independent filesystem is shut down as soon as it has no open files.

4
  • I am doing other weird mounts with multiple mount points and I am wondering why mount --make-rprivate /root.orig does not work instead of mount --make-rprivate /root.orig/mnt.
    – rools
    Commented Feb 6, 2020 at 16:38
  • @rools It's essential that /root.orig is a "shared" copy of /, not "private". That's what makes the umount operation propagate from /root.orig/mnt, to the other copy at /mnt.
    – sourcejedi
    Commented Feb 6, 2020 at 17:05
  • (Assuming I understand what you are asking correctly. If this doesn't make sense, you might be better off writing a full scenario in a question, and pointing the question out to me).
    – sourcejedi
    Commented Feb 6, 2020 at 17:06
  • Yes you totally got it. You are right. I thought it was another problem as I have a weird behavior but it is because I have a particular scenario. I may ask a different question. Thanks!
    – rools
    Commented Feb 6, 2020 at 22:54

You must log in to answer this question.

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