How to really force unmount a filesystem (without manual investigation why is it busy)
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".
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.
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
umount -f
can be used to force an unmount when the filesystem is busy.
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. :)