Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unmount a busy device

Tags:

linux

umount

I've got some samba drives that are being accessed by multiple users daily. I already have code to recognize shared drives (from a SQL table) and mount them in a special directory where all users can access them.

I want to know, if I remove a drive from my SQL table (effectively taking it offline) how, or even is, there a way to unmount a busy device? So far I've found that any form of umount does not work.

Ignoring the possibility of destroying data - is it possible to unmount a device that is currently being read?

like image 836
Max Avatar asked Oct 24 '11 16:10

Max


People also ask

How do I unmount a device?

Press the Windows / Super key and search for “disk.” Select the Disks utility. 3. Selecting the USB Flash drive correctly. Click the square stop button icon to unmount the disk.

Can't umount device or resource busy?

Answer. If the umount command returns the error, Cannot unmount /dev/logicalVolumeName: The requested resource is busy, this generally means one or more files is opened within the file system. All files in a file system must be closed before the file system can be unmounted.


2 Answers

YES!! There is a way to detach a busy device immediately - even if it is busy and cannot be unmounted forcefully. You may cleanup all later:

umount -l /PATH/OF/BUSY-DEVICE umount -f /PATH/OF/BUSY-NFS (NETWORK-FILE-SYSTEM) 

NOTE/CAUTION

  1. These commands can disrupt a running process, cause data loss OR corrupt open files. Programs accessing target DEVICE/NFS files may throw errors OR could not work properly after force unmount.
  2. Do not execute above umount commands when inside mounted path (Folder/Drive/Device) itself. First, you may use pwd command to validate your current directory path (which should not be the mounted path), then use cd command to get out of the mounted path - to unmount it later using above commands.
like image 79
Amit Verma Avatar answered Dec 10 '22 22:12

Amit Verma


If possible, let us locate/identify the busy process, kill that process and then unmount the samba share/ drive to minimize damage:

  • lsof | grep '<mountpoint of /dev/sda1>' (or whatever the mounted device is)

  • pkill target_process (kills busy proc. by name | kill PID | killall target_process)

  • umount /dev/sda1 (or whatever the mounted device is)

like image 29
Frank Tudor Avatar answered Dec 10 '22 22:12

Frank Tudor