- umount: device is busy. Why?
- 15 Answers 15
- Не могу размонтировать раздел в Linux: umount — device is busy
- How to Fix umount target is busy in Linux
- What is unmount target busy
- Force unmount
- Using lsof — Find and Kill the processes using the file
- Using fuser — Kill processes accessing the file
- Lazy unmount
- Conclusion
- Fixing ‘Umount Target is Busy’ Error in Linux
- The reason behind Umount target is busy
- How to solve Umount target is busy in Linux
- Method 1: Unmout target by killing the process itself (recommended)
- Method 2: Using force unmount (for Network File Systems)
- Method 3: Using the lazy unmount (Schrödinger’s unmount)
- Which one should you choose?
umount: device is busy. Why?
The filesystem is huge, so lsof +D /path is not a realistic option. lsof /path , lsof +f — /path , and fuser /path all return nothing. fuser -v /path gives:
USER PID ACCESS COMMAND /path: root kernel mount /path
which is normal for all unused mounted file systems. umount -l and umount -f is not good enough for my situation. How do I figure out why the kernel thinks this filesystem is busy?
For umount —force will try harder to unmount and -v or -vvv even will reaveal more what is the problem with mount. So try: umount -vvv —force /babdmount
@derobert: Which in my case revealed an active swapfile and was the solution to my version of the «device busy» problem. Thank you!
15 Answers 15
It seems the cause for my issue was the nfs-kernel-server was exporting the directory. The nfs-kernel-server probably goes behind the normal open files and thus is not listed by lsof and fuser .
When I stopped the nfs-kernel-server I could umount the directory.
Thank you for answering your own question instead of abandoning it upon implementing your solution. Your answer helped me sort out a similarly exported NFS share.
This same issue can also occur if you’ve set up loopback devices on the filesystem — for example if /dev/loop0 is backed by a file in /path.
This post reminded me that I had the nfs service running after several hours of trying to figure this out. In RHEL6/CentOS6, use sudo service nfs stop and you may (not) need to also do sudo exportfs -u to unexport. Remember to then sudo exportfs -r and sudo service nfs start to re-export and restart the service.
To add to BruceCran’s comment above, the cause for my manifestation of this problem just now was a stale loopback mount. I’d already checked the output of fuser -vm / lsof +D , mount and cat /proc/mounts , checked whether some old nfs-kernel-server was running, turned off quotas, attempted (but failed) a umount -f and all but resigned myself to abandoning 924 days’ uptime before finally checking the output of losetup and finding two stale configured-but-not-mounted loopbacks:
parsley:/mnt# cat /proc/mounts rootfs / rootfs rw 0 0 none /sys sysfs rw,nosuid,nodev,noexec 0 0 none /proc proc rw,nosuid,nodev,noexec 0 0 udev /dev tmpfs rw,size=10240k,mode=755 0 0 /dev/mapper/stuff-root / ext3 rw,errors=remount-ro,data=ordered 0 0 tmpfs /lib/init/rw tmpfs rw,nosuid,mode=755 0 0 usbfs /proc/bus/usb usbfs rw,nosuid,nodev,noexec 0 0 tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0 devpts /dev/pts devpts rw,nosuid,noexec,gid=5,mode=620 0 0 fusectl /sys/fs/fuse/connections fusectl rw 0 0 /dev/dm-2 /mnt/big ext3 rw,errors=remount-ro,data=ordered,jqfmt=vfsv0,usrjquota=aquota.user 0 0
parsley:/mnt# fuser -vm /mnt/big/ parsley:/mnt# lsof +D big parsley:/mnt# umount -f /mnt/big/ umount2: Device or resource busy umount: /mnt/big: device is busy umount2: Device or resource busy umount: /mnt/big: device is busy parsley:/mnt# losetup -a /dev/loop0: [fd02]:59 (/mnt/big/dot-dropbox.ext2) /dev/loop1: [fd02]:59 (/mnt/big/dot-dropbox.ext2) parsley:/mnt# losetup -d /dev/loop0 parsley:/mnt# losetup -d /dev/loop1 parsley:/mnt# losetup -a parsley:/mnt# umount big/ parsley:/mnt#
A Gentoo forum post also lists swapfiles as a potential culprit; although swapping to files is probably pretty rare these days, it can’t hurt to check the output of cat /proc/swaps . I’m not sure whether quotas could ever prevent an unmount — I was clutching at straws.
Не могу размонтировать раздел в Linux: umount — device is busy
При попытке размонтировать раздел в Linux с помощью команды umount может появится ошибка device is busy:
umount: /mnt/sda2: device is busy
umount: /dev/sda2: device is busy. (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1))
В данный момент это устройство используется каким-то запущенным процессом/программой и вы не можете от монтировать его.
Попробуйте найти процесс, который используется ваше устройство с помощью команды:
Вы получите список PID процессов, которые сейчас используют этот диск. Завершите эти процессы:
Попробуйте размонтировать устройство:
Если это не помогло, можно принудительно от монтировать такой раздел или устройство (может вызвать потерю данных в открытых файлах. Есть два варианта размонтирования устройства:
Lazy unmount: # umount -l /dev/sda2 в этом режиме Linux ждет прячет от системы точку монтирования и ждет когда будут закрыты все файловые дескрипторы на указанном устройстве.
Force: # umount -f /dev/sda2 – принудительное размонтирование (часто это единственный способ отключить NFS диск, который стал недоступным)
How to Fix umount target is busy in Linux
Sometimes when you unmount a filesystem or drive, the system shows «unmount target is busy» message. Unless you release the busy system, you won’t be able to unmount.
In this guide, we learn how to fix umount target is busy in Linux.
What is unmount target busy
A mounted filesystem can be accessed by any process running on the Linux operating system. When such a filesystem or a directory which is being accessed by some process is unmounted, the system may issue the target as busy (“device is busy”). One of the reasons the system doesn’t allow unmount is to prevent data loss.
This problem generally occurs in the following scenarios:
- The current working directory accessed by the terminal is on the path of the mount point
- A process is accessing the files on the filesystem hierarchy being unmounted
- A process is accessing a file which relies (reads/writes) on the file inside the filesystem which is being unmounted.
- Remote mount point unreachable
Force unmount
Force unmount is one solution to detach the busy device.
Usually, you see a busy device message when you try to unmount an NFS filesystem. This happens often when the NFS server has some issues (mainly unreachable) and you have a soft NFS mount.
Force unmount will detach the server mount point by disrupting some running processes.
CAUTION: This may cause data loss or corrupt files or programs accessing file throw errors.
unmount -f /path/to/busy-nfs-mount
You can verify if it is successfully unmounted using the df command.
Using lsof — Find and Kill the processes using the file
The lsof (list open files) command displays a list of all open files and the processes associated with them on a specific file system, directory, or device. By default, it lists all files, shared libraries, and directories that are currently open and provides as much information as possible about each of them.
We can use lsof command to find PID (process id) corresponding to our mount point and then kill that process.
Use the following lsof command to list processes using the mount point.
lsof /media/dsk
orlsof | grep '/media/dsk'
The output shows that the user linuxopsys has two bash processes with PIDs 4255 and 4335 using /media/dsk.
Once these two programs are stopped the device is no longer busy.
Once you make sure its safe to kill the process, run the following kill command:
If no more processes tide to the mount point, you initiate umount command.
Using fuser — Kill processes accessing the file
fuser command in Linux helps to identify the processes which are accessing sockets or files on filesystems.
Use fuser command with -m option which lists all the processes accessing the files or mount point on the file system. You can add -v option for verbose.
The following example displays all the processes accessing the file system /media/dsk along with their process ids arranged in a tabular format.
Now you found the processes which are using the file on the mounted filesystem. You can use kill command to terminate those processes.
You can add -k option to kill processes in a single command, so you can avoid one step.
Lazy unmount
Lazy unmounting is used to unmount the mount point from the Linux filesystem hierarchy. The command removes all references to the detached file system as soon as it is no longer busy. Once no processes are accessing the unmounted file system, the umount command executes and actually detaches the file system.
Lazy unmounting a mount point is beneficial when we don’t want to unexpectedly kill the process which are accessing the file systems as this may lead to loss of data or may corrupt the file systems.
For example, when you are copying a file from the mounted flash drive to linux machine and need to unmount the mounted device at the same time so that you don’t need to actively check the status of the file transfer, you can execute a lazy unmount on the flash drive so that once the operation to copy the file is complete, the system automatically detaches the mount point of the flash drive.
To lazy unmount use -l option followed by the mount path:
Conclusion
In this guide, we learned how to fix when you encounter umount target is busy in Linux. We have explained solutions using force unmount, detaching busy device by finding and kill the processes, and finally lazy mount.
Thanks for reading, please leave your feedback and suggestions in the comment section.
If this resource helped you, let us know your care by a Thanks Tweet. Tweet a thanks
Fixing ‘Umount Target is Busy’ Error in Linux
A not-so-uncommon error while using umount command is ‘target is busy’. Learn what you can do to get rid of this error.
Unmounting disks in the Linux command line is not complicated. All you have to do is to use the umount command:
But once in a while, you’ll come across an error that says ‘umount: target is busy’:
So how are you supposed to solve this issue?
Well, before solving this issue, let me share the reason behind this problem first.
The reason behind Umount target is busy
The reason is quite simple! The target device is still in use.
With enough permissions, any process might be utilizing that drive that you want to unmount, and to prevent data loss, the kernel won’t allow you to unmount.
How to solve Umount target is busy in Linux
If an ongoing data transfer occurs in the background, you may lose your data by forcefully unmounting your drive.
There are times when you want to unmount the drive at any cost. Perhaps the drive isn’t responding for some reason and you want to unmount it.
In this tutorial, I will share three ways to unmount the target:
Let’s start with the first method.
Method 1: Unmout target by killing the process itself (recommended)
This is the best way of unmounting the target in my opinion as you are eventually killing the process itself.
The first step is to find the PID of the process that causes the problems.
To do so, I will be using the lsof command in the following manner:
Once you get the PID, it’s quite simple to force kill the process:
And now, you should be able to unmount the drive easily:
Method 2: Using force unmount (for Network File Systems)
The force unmount option is mainly preferred by those who are dealing with network file systems.
So it may NOT give you the expected results with your local file system.
To use the force unmount, you will have to use the same old umount command but with the -f flag:
sudo umount -f /Path/to/target
Method 3: Using the lazy unmount (Schrödinger’s unmount)
This option does not actually unmount your target but just removes the target from the namespace. And will unmount the target when the drive is not being utilized anymore!
It is more of a Schrödinger’s mount when you can never be sure of whether the filesystem is unmounted or not!
So why am I even adding this to the solution’s list? Well, this is the least harmful way of unmounting your stubborn drive.
To use the lazy unmount, you will have to use the -l flag with the umount command as shown:
sudo umount -l /Path/to/target
Which one should you choose?
In times like you have to have your drive unmounted, I would prefer going with the 1st method which involves killing the process itself.
And there is a strong reason why. It gets my job done without any hiccups.
Sure, you may want to go with either of the last two options based on your use case.