1

Trying to use a chrooted system via

mount -B stage3 gentoo
mount -t sysfs none gentoo/sys
mount -t proc none gentoo/proc
mount -R /dev gentoo/dev
mount --make-rslave gentoo/dev
unshare --fork chroot gentoo
umount -R gentoo

After the last umount, dev, dev/pts, dev/shm, dev/mqueue, dev/hugepages were still mounted under stage3.

I have two questions,

  1. Why they were mounted to stage3?
  2. How could I unmount those? Every mountpoint is busy.

OS: Ubuntu Xenial. Kernel: 4.13.4, but I have got same issue with kernel like 4.10 and others.

Magicloud
  • 733
  • 1
  • 6
  • 17

1 Answers1

1
  1. Why they were mounted to stage3?

    Because you bind-mounted stage3 onto gentoo and stage3 propagation flag is set to shared (verify this with: findmnt -o PROPAGATION stage3)

  2. How could I unmount those? Every mountpoint is busy.

    You've just spawned a chroot on the mounted tree. If you want to unmount the tree while the chroot command is running, make the mount namespace private to the chroot:

     unshare --mount --fork chroot gentoo
    
xhienne
  • 17,075
  • 2
  • 52
  • 68
  • (and the default to shared propagation is probably due to systemd: https://unix.stackexchange.com/questions/269695/mounting-new-filesystem-affects-non-recursive-bind-mounts/276700#276700) – sourcejedi Oct 07 '17 at 17:52
  • Thanks for the explanation. Shared sub-tree is always confusing me. For question 2, I ran umount after exited the chroot jail. `umount -R` unmounted gentoo, sys, proc properly. But dev and its children did not get unmounted due to "busy". – Magicloud Oct 08 '17 at 05:44
  • Sorry last comment was not editable. I mean dev and its children (on stage3) did not get unmounted due to "busy". Let me check the share part since dev on gentoo got unmounted. – Magicloud Oct 08 '17 at 06:06
  • @Magicloud It did not get unmounted with the `--mount` option? Use `lsof` to find out what is using it. – xhienne Oct 08 '17 at 09:40
  • Oh, --mount works here. And --make-private when binding stage3 to gentoo also works. – Magicloud Oct 09 '17 at 02:42