4

I have two partitions, one mounted at / and one at /crypt. I'm using a bind mount to mount /crypt/home at /home/ (and various others).

Problem is that I kinda need to look at the original /home dir now, but of course I just see the contents of /crypt/home.

I can't unmount this because to do so I have to be logged in, which means /home is in use...

Is there a way (perhaps another bind mount or something) that I can access the files under the original /home dir, without resorting to booting from a USB stick etc.?

mikeserv
  • 58,310
artfulrobot
  • 2,929

1 Answers1

7

If you just login as root then you shouldn't have any problems with the /home mount. Still, if that is not possible, then you can simply mount --bind / /elsewhere. By default --bind type mounts are not recursive - and so the filesystems mounted to / will not follow it when it is --bind mounted somewhere else. You can recursively --rbind a mount elsewhere though.

For example:

findmnt /esp; findmnt /

TARGET SOURCE    FSTYPE OPTIONS
/esp   /dev/sda1 vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro

TARGET SOURCE                FSTYPE OPTIONS
/      /dev/sda2[/arch_root] btrfs  rw,relatime,compress-force=lzo,ssd,space_cache,autodefrag

As you can see, /esp is mounted on /.

mkdir /tmp/root
sudo mount --bind / /tmp/root
ls /esp /tmp/root/esp

/esp:
EFI/  shellia32.efi*  shellx64.efi*

/tmp/root/esp:

Now I'll get a file into /tmp/root/esp:

sudo touch /tmp/root/esp/blank_file
ls /esp /tmp/root/esp

/esp:
EFI/  shellia32.efi*  shellx64.efi*

/tmp/root/esp:
blank_file

So I've created a file in the directory where /esp is mounted. See?

sudo umount /boot /esp; ls /esp
blank_file

sudo mount -a; ls /esp
EFI/  shellia32.efi*  shellx64.efi*

I had to umount /boot and /esp because /boot is actually sourced from a bind mounted folder on /esp. Both of these are defined in /etc/fstab - which is why mount -a brought them back.

mikeserv
  • 58,310
  • 1
    Thanks, mount --bind / /elsewhere did the trick /elsewhere/home was the 'original' version, as you pointed out. Many thanks for such a full explanation. – artfulrobot Dec 02 '14 at 23:15