15

I'm using a rescue-live-system (similar to a live-cd) to fix some issues with my Debian server, like that:

# mkdir -p /mnt/rescue
# mount /dev/md2 /mnt/rescue
# mount --bind /dev /mnt/rescue/dev/
# mount --bind /proc /mnt/rescue/proc/
# mount --bind /sys /mnt/rescue/sys/

Now I can chroot to /mnt/rescue - but after I'm done, how to unmount the filesystem again?

umount: /mnt/rescue: target is busy.
    (In some cases useful info about processes that use
     the device is found by lsof(8) or fuser(1))

I guess it's because dev, proc and sys are bound to the mounted file system. But it's not possible to unmount them either...

  • What happens when you try to unmount /mnt/rescue/proc? Are you sure you don't still have processes running in that chroot? – Mat Jan 20 '13 at 9:20
  • Try lsof /mnt/rescue to see what process is using that folder. – Martín Canaval Jan 20 '13 at 9:22
  • You need to leave the chrooted shell before shutting down. – vonbrand Jan 21 '13 at 17:22
13
  1. You have to first exit the chroot session, usually a simple exit will do:

    exit
    
  2. Then umount ALL binded directories:

    umount /mnt/rescue/dev/
    umount /mnt/rescue/proc/
    umount /mnt/rescue/sys/
    
  3. Then:

    umount /mnt/rescue
    

In case you were worried that sync isn't used here, note that it has no influence on whether unmounting is possible. Unmounting flushes pending writes anyway (it has to, because there'd be nowhere for them to go after the unmounting). The presence of a chrooted process is irrelevant (except in that it prevents unmounting). In normal system operation, sync has no observable effect. sync only makes a difference if a device is physically disconnected without having been unmounted or if the system crashes while the device is mounted.

  • 1
    thanks, that's it... my mistake was trying to unmount /sys/ instead of /mnt/rescue/sys/ ... – Waqar Lim Jan 20 '13 at 17:21
  • 2
    The sync is totally useless. – Gilles Jan 20 '13 at 22:54
  • @Gilles Can you elaborate abit more why sync is useless? Does it become useless in current kernel? Or only in this case(rescue mode)? I put it there just in case there are huge pending write to disk that will prevent umount after exiting chroot. – John Siu Jan 21 '13 at 2:44
  • 4
    @JohnSiu sync has no influence on whether unmounting is possible. Unmounting flushes pending writes anyway (it has to, because there'd be nowhere for them to go after the unmounting). The presence of a chrooted process is irrelevant (except in that it prevents unmounting). In normal system operation, sync has no observable effect. sync only makes a difference if a device is physically disconnected without having been unmounted or if the system crashes while the device is mounted. – Gilles Jan 21 '13 at 10:35
  • @Gilles I understand your point now. Thank you!! – John Siu Jan 21 '13 at 10:50
13

Execute the below command to force and Detach the filesystem from the filesystem hierarchy, and cleanup all references to the filesystem as soon as it is not busy anymore.

umount -lf /mnt/rescue
4

The reason why you get the 'target is busy.' message is because the mount point (/mnt/rescue) is open in a file browser or in a terminal session, and also the order of unmounting process (here I mean dev/pts should be umounted before dev/ )

Well, in order to successfully umount all fs there :

  • Make sure the mountpoint isn't open in a file browser!
  • After exiting chroot change directory out of chroot dir (cd)!
  • Umount fs respecting the order dev/pts => dev/ => proc/ => sys/ :

    sudo umount /mnt/rescue/dev/pts
    sudo umount /mnt/rescue/dev
    sudo umount /mnt/rescue/proc
    sudo umount /mnt/rescue/sys
    sudo umount /mnt/rescue

2

This is how I do with schroot command on Ubuntu version 10.04 upward:

# list all sessions:
schroot --list --all-sessions
# if the above command does not work, just type `mount`. The bind mount
# points with something like this in the mount path is the session name you want to get:
precise-a4aac8e0-663c-4fec-8fb2-16e4b06557e3 (<chroot_name>-<id>)

# now run this to properly end the session:
schroot -e -c precise-ca6c72e4-0e9f-4721-8a0e-cca359e2c2fd
0

Exit chroot. In the host system, the command 'mount' will show all the mounted path. (Includes those path which are mounted in chroot.) For example:

binfmt_misc on /home/user/projects/jsroot/proc/sys/fs/binfmt_misc

Then enter chroot environment. In chroot environment run unmount to unmount all path in order. (Sub path must be unmount before parent path.)

unmount /proc/sys/fs/binfmt_misc
unmount /proc/sys
unmount /proc

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.