17

How to unmount a filesystem in Linux without investigating why is it busy?

I want to do it in one command. It should handle applications using that filesystem, submounts, containers (lxc-execute -n qqq <command>) and all other things.

Just "unmount. No objections!". Special kernel patches or configuration is allowed.

Filesystem should be really unmounted, so umount -l is certainly not an option. For example, for cryptsetup remove (BTW how to forcibly cryptsetup remove? Update: cryptsetup luksSuspend, but you won't be able to cryptsetup luksResume if it is not LUKS).

How to make all filehandles on that filesystem invalid?

The only reliable way I know is mounting the filesystem through the FUSE (there is usually no problem to unmount FUSE thing because of I can just kill it's process).

P.S. Already know mount fuser, lsof | grep, cat /proc/*/mounts | grep and obsolete non-working "badfs patch".

4 Answers 4

6

umount --force or umount -f (equivalent)

If that fails, then use:

umount --lazy or umount --l (equivalent)

The "lazy" option will "detach the filesystem from the filesystem hierarchy now, and cleanup all references to the filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)" It might cause instability, but it will get the thing unmounted. Any programs using the drive may crash.

1
  • Of course --force does not work. And --lazy is not real unmount - it does not release LVM, loopback or cryptsetup things.
    – Vi.
    Mar 11, 2014 at 14:44
3

Use the Magic SysRq key combo: Alt+SysRq+u

Note that you should probably do an emergency sync first: Alt+SysRq+s

Also note that on some (especially newer) keyboards, you have to use PrtSc rather than SysRq

3
  • The shift key is not necessary, just Alt+SysRq+key. Another thing worth mentioning (especially for laptop users) is that you can press Alt, press and release SysRq, then press and release the letter/digit and finally release Alt. Most importantly, this remount all filesystems as read-only, so it's a last-ditch thing before forcibly rebooting, not a general way of remounting filesystems read-only. Aug 15, 2010 at 8:00
  • @Gilles: thanks for the tip about the shift key. I've corrected my instructions.
    – sml
    Aug 16, 2010 at 7:50
  • 1. It only remounts to read-only. It is not that wanted. For example, I want to unmount it and remount using FUSE. 2. Bad thing is that I need to "-o remount,rw" root filesystem and other ones after that to return to normal work.
    – Vi.
    Aug 27, 2010 at 8:36
1

I'm afraid there's no way to do this on one command. umount -f really does not work as smoothly as one would hope. If there are submounts under some other mount, you cannot just unmount those mounts in some random order and hope they will go down.

But no worries, there's one way to make all this a one command: create a shell/Perl script which kills the wanted processes, unmounts containers, submounts and finally unmounts some other mount. Then you can just call your script on demand. Initially that's more work for you but after you get the script working, everything's a child's play. :)

1
  • 2
    These are cases when I cannot unmount even manually: 1. uninterruptible-sleep processes that cannot be resumed (crashed drivers etc.) 2. Failed storage (that also hangs each request to it). I want this "dirty unmount" to handle this.
    – Vi.
    Aug 12, 2010 at 12:51
0
umount -f

can be used to force an unmount when the filesystem is busy.

6
  • 2
    It has never worked for me: umount2: Device or resource busy The only partial success was when I experimented with badfs patch.
    – Vi.
    Aug 12, 2010 at 11:23
  • I had the same "error" message, but it was working nonetheless. The filesystem was unmounted after the umount -f
    – IanH
    Aug 12, 2010 at 11:37
  • 4
    Try "lazy umount", umount -l. It always umounts but could produce an unstable filesystem. Nov 5, 2010 at 15:20
  • I think Jimmy's comment on this answer is actually the best option. It's true that a "lazy" unmount can cause instability, but it's assumed you're already in an unstable state if you need to force-umount the filesystem. To this end, why is '-l' not an option?
    – deesto
    Oct 14, 2013 at 15:08
  • @deesto, Lazy unmount does not make the undelying block device (LVM volume, LUKS container, loopback) unreferenced.
    – Vi.
    Dec 25, 2014 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .