How do I forcefully unmount a Linux disk partition?

It happens many times you try to unmount a disk partition or mounted CD/DVD disk and if you try to unmount device, which is accessed by other users, then you will get error umount: /xxx: device is busy.

What happens basically, is that Linux / UNIX will not allow you to unmount a device that is busy. There are many reasons for this (such as program accessing partition or open file) ,but the most important one is to prevent data loss.

1 the first method

Try the following command to find out what processes have activities on the device/partition. If your device name is /dev/sdb1, enter the following command as root user:

# lsof | grep '/dev/sda1' 
Output: vi 4453 vivek 3u BLK 8,1 8167 /dev/sda1

Above output tells that user vivek has a vi process running that is using /dev/sda1. All you have to do is stop vi process and run umount again. As soon as that program terminates its task, the device will no longer be busy and you can unmount it with the following command:

# kill 4453
# umount /dev/sda1

 2 the second method

Linux fuser command to forcefully unmount a disk partition

Suppose you have /dev/sda1 mounted on /mnt directory then you can use fuser command as follows:Type the command to unmount /mnt forcefully:

# fuser -km /mnt 

Where, 
    -k : Kill processes accessing the file. 
    -m : Name specifies a file on a mounted file system or a block 
device that is mounted. In above example you are using /mnt

 3 the third method

# umount -l /mnt

Where,
    -l : Also known as Lazy unmount. Detach the filesystem from 
the filesystem hierarchy now, and cleanup all references to the 
filesystem as soon as it is not busy anymore. This option works 
with kernel version 2.4.11+ and above only.

4 the fourth method

# umount -f /mnt

Where,

    -f: Force unmount in case of an unreachable NFS system

Caution: Using these commands or option can cause data loss for open files;      programs which access files after the file system has been unmounted will get an error.

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据