This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes

I had to chroot into an offline system for debugging:

mount /dev/foo/root /media/chroot
mount -t proc /proc /media/chroot/proc
mount --rbind /sys /media/chroot/sys
mount --rbind /dev /media/chroot/dev
chroot /media/chroot /bin/bash

This worked fine. However, after exiting from the chroot I'm unable to remove the /dev and /sys bind-mounts. umount complains that the target is still busy:

root@localhost:~# umount /media/chroot/sys
umount: /media/chroot/sys: target is busy
        (In some cases useful info about processes that
         use the device is found by lsof(8) or fuser(1).)

fuser -m /media/chroot/sys shows several processes (including init) still accessing that mountpoint, and I don't think I should kill all those processes, and I don't want to force a umount unless it's absolutely necessary.

Is there a "normal" way to umount bind-mounted directories?

in Sysadmin
by (125)
3 20 38
edit history

Please log in or register to answer this question.

1 Answer

0 votes

Umounting a bind-mounted filesystem is usually no different from umounting any other filesystem. However, in your case you used the option --rbind instead of just --bind with the /dev and /sys filesystems, which means you did a recursive mount. From man mount:

-R, --rbind
Remount a subtree and all possible submounts somewhere else (so that its contents are available in both places). See above.

Both /dev and /sys are not just single filesystems, but have several other things mounted in them (for example there are several cgroups mounted below /sys), which the recursive mount replicates under your chroot mountpoint.

root@localhost:~# mount | grep 'chroot/sys'
sysfs on /media/chroot/sys type sysfs (rw,nosuid,nodev,noexec,relatime)
none on /media/chroot/sys/fs/cgroup type tmpfs (rw,relatime,size=4k,mode=755)
cgroup on /media/chroot/sys/fs/cgroup/cpuset type cgroup (rw,relatime,cpuset)
cgroup on /media/chroot/sys/fs/cgroup/cpu type cgroup (rw,relatime,cpu)
cgroup on /media/chroot/sys/fs/cgroup/cpuacct type cgroup (rw,relatime,cpuacct)
cgroup on /media/chroot/sys/fs/cgroup/blkio type cgroup (rw,relatime,blkio)
cgroup on /media/chroot/sys/fs/cgroup/memory type cgroup (rw,relatime,memory)

These additional mounts are not automatically removed along with their ancestor and are what's preventing you from simply umounting /media/chroot/dev and /media/chroot/sys. You need to umount all of those first before you can remove the /dev and /sys bind-mounts.

umount /media/chroot/sys/fs/cgroup/cpu
umount /media/chroot/sys/fs/cgroup/cpuset
umount /media/chroot/sys/fs/cgroup
umount /media/chroot/sys
umount /media/chroot/dev/pts
umount /media/chroot/dev
by (125)
3 20 38
edit history