Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

1 Answer 1

up vote 5 down vote accepted
  1. You have to first exit the chroot session, usually a simple exit will do. You may want to do a sync first.

    sync
    exit
    
  2. Then umount ALL the binded directory

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

    umount /mnt/rescue
    
share|improve this answer
    
thanks, that's it... my mistake was trying to unmount /sys/ instead of /mnt/rescue/sys/ ... –  vertoe Jan 20 '13 at 17:21
1  
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
2  
@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

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.