How to really force unmount a filesystem (without manual investigation why is it busy)

13

3

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

Vi.

Posted 2010-08-12T10:15:32.910

Reputation: 13 705

Answers

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

sml

Posted 2010-08-12T10:15:32.910

Reputation: 1 582

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. – Gilles 'SO- stop being evil' – 2010-08-15T08:00:08.480

@Gilles: thanks for the tip about the shift key. I've corrected my instructions. – sml – 2010-08-16T07:50:24.643

>

  • It only remounts to read-only. It is not that wanted. For example, I want to unmount it and remount using FUSE.
  • Bad thing is that I need to "-o remount,rw" root filesystem and other ones after that to return to normal work.
  • < – Vi. – 2010-08-27T08:36:23.700

    3

    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.

    Freedom_Ben

    Posted 2010-08-12T10:15:32.910

    Reputation: 260

    Of course --force does not work. And --lazy is not real unmount - it does not release LVM, loopback or cryptsetup things. – Vi. – 2014-03-11T14:44:52.183

    1

    umount -f
    

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

    lime-like

    Posted 2010-08-12T10:15:32.910

    Reputation: 66

    @deesto, Lazy unmount does not make the undelying block device (LVM volume, LUKS container, loopback) unreferenced. – Vi. – 2014-12-25T20:50:34.833

    1It has never worked for me: umount2: Device or resource busy The only partial success was when I experimented with badfs patch. – Vi. – 2010-08-12T11:23:39.967

    I had the same "error" message, but it was working nonetheless. The filesystem was unmounted after the umount -f – IanH – 2010-08-12T11:37:15.687

    3Try "lazy umount", umount -l. It always umounts but could produce an unstable filesystem. – Jimmy Hedman – 2010-11-05T15:20:51.683

    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 – 2013-10-14T15:08:09.793

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

    Janne Pikkarainen

    Posted 2010-08-12T10:15:32.910

    Reputation: 6 717

    1These 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. – 2010-08-12T12:51:32.357