0

It appears that I cannot unmount dev after mounting it. I am running on Ubuntu 18.04.2 LTS with 4.15.0-1052-aws.

mkdir -p ~/jail/dev
pushd ~/jail
sudo mount --rbind /dev dev/
sudo umount  dev/
umount: /home/ubuntu/Code/conversations/jail/dev: target is busy.

Is there some way I can unmount it without rebooting my machine?

Alternately, is there a way I can mount it so that it is easier to unmount?

Update: This is the output of lsof:

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
kdevtmpfs  55 root  cwd    DIR    0,6     2980    2 dev
kdevtmpfs  55 root  rtd    DIR    0,6     2980    2 dev
4
mount --make-rprivate dev/
umount -l dev/

The first command is needed for safety. It makes sure you will not propagate an unmount to any submounts of /dev.

The second command is a lazy unmount. The programs that had opened files will generally still be able to access them. Until they close them, the filesystem is still open. However, the filesystem is "detached" immediately. It won't clutter up the namespace anymore. It also won't show up in findmnt and so on.

The lazy unmount can be a useful approach when disassembling a whole tree of bind mounts.

`umount -R` on bind mounts takes a non-neglible amount of time, why?

If you're not confident that it's all bind mounts and virtual filesystems, or about the use of umount -l in general, then replace the second command with umount -R dev/.

  • this issue probably appeared with systemd: debian - systemd - Known Issues and Workarounds - Shared bind mounts – A.B Nov 1 at 21:04
  • @A.B That's the main reason you need the first command, yes. Note it's just following a design that comes from the kernel. The kernel just didn't update the default themselves, because they consider it very important that new kernels can still run old, unmodified userspace. – sourcejedi Nov 2 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.