Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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...

share|improve this question
    
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
up vote 11 down vote accepted
  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.

share|improve this answer
1  
thanks, that's it... my mistake was trying to unmount /sys/ instead of /mnt/rescue/sys/ ... – 5chdn 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

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
share|improve this answer

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

share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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