3 Ways to Force Unmount in Linux Showing “device is busy”

Updated August 8, 2019By Bobbin ZachariahLINUX HOWTOTROUBLESHOOTING

When you do an NFS mount, it sometimes shows "device is busy” status, in such case we need to perform force unmount in a graceful way. There are different ways and options we can try out if normal nfs unmount fails.

Scenario

In our scenario, we have created /var/linoxide directory for the mount. When we try to umount the remote partition, we have an error message. Good to read on NFS Mount Options in Linux.

You can all the mounted folders with the df command

  1. # df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/vda1 20G 1.3G 18G 7% /
  4. devtmpfs 236M 0 236M 0% /dev
  5. tmpfs 245M 0 245M 0% /dev/shm
  6. tmpfs 245M 8.4M 237M 4% /run
  7. tmpfs 245M 0 245M 0% /sys/fs/cgroup
  8. tmpfs 49M 0 49M 0% /run/user/0
  9. 10.128.20.241:/var/linoxide 20G 1.3G 18G 7% /mnt/nfs/linoxide_srv
  10. 10.128.20.241:/home 20G 1.3G 18G 7% /mnt/nfs/home_srv

In the last two lines, you can see mounted folders on the client. Below example shows the unmount fails because the device is busy

  1. # umount /mnt/nfs/linoxide_srv/
  2. umount.nfs4: /mnt/nfs/linoxide_srv: device is busy

1) With lsof

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. The output gives us some information such as the PID, USER so that we can use a pipe to filter its output.

  1. # lsof /mnt/nfs/linoxide_srv/
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. bash 24098 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv
  4. bash 24125 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv
  5. vim 24144 linoxide cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv

You can see that we have the PID of process which uses the mounted folder, we see the commands in execution, the user who executes the command. It is possible to kill the busy process but take care of the executed command. You can see vim command which means that a file is being edited by the linoxide user. So if we kill the process, his progress will be lost. Suppose that we have informed him, let's see the result

  1. # lsof /mnt/nfs/linoxide_srv/
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. bash 24098 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv
  4. bash 24125 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv

You can look that our user has stopped his modification but we still have bash command in execution but we don't know why. We can now kill the two processes with kill command. Be sure to don't miss the pid of the process to kill.

Now we will kill the first bash process

  1. # kill -9 24098

We can verify the result

  1. # lsof /mnt/nfs/linoxide_srv/
  2. COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  3. bash 24125 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv

We can see that one process is killed

  1. # kill -9 24125

Now let's verify for the second process

  1. # lsof /mnt/nfs/linoxide_srv/

Now let's try to unmount the folder

  1. # umount /mnt/nfs/linoxide_srv/
  2. umount: /mnt/nfs/linoxide_srv/: not mounted

It seems that kill the process has automatically unmounted the folder but let's check with df command

  1. # df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/vda1 20G 1.3G 18G 7% /
  4. devtmpfs 236M 0 236M 0% /dev
  5. tmpfs 245M 0 245M 0% /dev/shm
  6. tmpfs 245M 8.3M 237M 4% /run
  7. tmpfs 245M 0 245M 0% /sys/fs/cgroup
  8. tmpfs 49M 0 49M 0% /run/user/0
  9. 10.128.20.241:/home 20G 1.3G 18G 7% /mnt/nfs/home_srv

The folder /mnt/nfs/linoxide_srv has been unmounted as we want.

2) With fuser

The fuser (find user processes) command helps to identify processes that are preventing you from unmounting file systems. It finds user processes that are associated with whatever files, directories, or file system mount points that you supply as command-line arguments.

  1. # fuser /mnt/nfs/linoxide_srv/
  2. /mnt/nfs/linoxide_srv: 24191c

We can use fuser command with -m option which lists all the processes accessing the files or mount point on the file system and the -v option which shows a result like ps command with PID, user and the executed command.

  1. # fuser -mv /mnt/nfs/linoxide_srv/
  2. USER PID ACCESS COMMAND
  3. /mnt/nfs/linoxide_srv:
  4. root kernel mount /mnt/nfs/home_srv
  5. root 24191 ..c.. bash
  6. root 24275 ..c.. bash
  7. linoxide 24290 ..c.. vim

You can see the command in execution. We must prevent our linoxide user to save his work.

  1. # fuser -mv /mnt/nfs/linoxide_srv/
  2. USER PID ACCESS COMMAND
  3. /mnt/nfs/linoxide_srv:
  4. root kernel mount /mnt/nfs/home_srv
  5. root 24191 ..c.. bash
  6. root 24275 ..c.. bash

With fuser command, it is possible to directly kill the process in execution with -k option without kill command

  1. # fuser -kmv /mnt/nfs/linoxide_srv/
  2. USER PID ACCESS COMMAND
  3. /mnt/nfs/linoxide_srv:
  4. root kernel mount /mnt/nfs/home_srv
  5. root 24191 ..c.. bash
  6. root 24275 ..c.. bash

Check the result

  1. # fuser -mv /mnt/nfs/linoxide_srv/
  2. USER PID ACCESS COMMAND
  3. /mnt/nfs/linoxide_srv:
  4. root kernel mount /mnt/nfs/home_srv

It seems that only the mount is in execution. Let's try to unmount the folder

  1. # umount /mnt/nfs/linoxide_srv/

We don't have error message. Check the mount point

  1. # df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/vda1 20G 1.3G 18G 7% /
  4. devtmpfs 236M 0 236M 0% /dev
  5. tmpfs 245M 0 245M 0% /dev/shm
  6. tmpfs 245M 8.3M 237M 4% /run
  7. tmpfs 245M 0 245M 0% /sys/fs/cgroup
  8. tmpfs 49M 0 49M 0% /run/user/0
  9. 10.128.20.241:/home 20G 1.3G 18G 7% /mnt/nfs/home_srv

We can see that the /mnt/nfs/linoxide_srv folder has been unmounted as we want.

3) Lazy unmount

umount command has an -l option to perform a lazy unmount. The mount will be removed from the filesystem namespace (so you won't see it under /mnt/nfs/linoxide anymore) but it stays mounted, so programs accessing it can continue to do so. When the last program accessing it exits, the unmount will actually occur.

  1. # fuser -mv /mnt/nfs/linoxide_srv/
  2. USER PID ACCESS COMMAND
  3. /mnt/nfs/linoxide_srv:
  4. root kernel mount /mnt/nfs/home_srv
  5. root 24366 ..c.. bash
  6. root 24381 ..c.. bash
  7. linoxide 24398 ..c.. vim

We can see that the folder is busy. Now let's try to do a lazy unmount

  1. # umount -l /mnt/nfs/linoxide_srv/

We don't have an error message. We will check if the command was being executed without error

  1. # echo $?
  2. 0

Now let's check the mount point

  1. # df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/vda1 20G 1.3G 18G 7% /
  4. devtmpfs 236M 0 236M 0% /dev
  5. tmpfs 245M 0 245M 0% /dev/shm
  6. tmpfs 245M 8.4M 237M 4% /run
  7. tmpfs 245M 0 245M 0% /sys/fs/cgroup
  8. tmpfs 49M 0 49M 0% /run/user/0
  9. 10.128.20.241:/home 20G 1.3G 18G 7% /mnt/nfs/home_srv

We can see that the mount point /mnt/nfs/linoxide_srv doesn't appear again but as we said earlier, for example, our linoxide user is still modifying his file, can create new files, etc. On the server, we can see the file that the user is modifying.

We can need to unmount a partition because of an emergency or simply to remove a device but a problem can occur because that device is busy. It is important to examine every process on the system before taking a decision for the method to resolve the problem. The lsof and fuser commands make it easy to identify the processes that are preventing you from unmounting a file system.

Read Also:

3 Ways to Force Unmount in Linux Showing “device is busy”的更多相关文章

  1. Linux在device is busy处理

    在Linux管理umount设备时,时常会遇到"device is busy", 假设umount一个文件系统碰到这样的情况.而且你并没有在所需卸载的文件夹下.那么非常可能实用户或 ...

  2. 5 Ways to Send Email From Linux Command Line

    https://tecadmin.net/ways-to-send-email-from-linux-command-line/ We all know the importance of email ...

  3. Linux umount设备时出现device is busy解决方法

    在Linux中,有时使用umount命令去卸载LV或文件时,可能出现umount: xxx: device is busy的情况,如下案例所示 [root@DB-Server u06]# vgdisp ...

  4. [platform]linux platform device/driver(三)--Platform Device和Platform_driver注册过程之代码对比

    转自:http://blog.csdn.net/thl789/article/details/6723350 Linux 2.6的设备驱动模型中,所有的device都是通过Bus相连.device_r ...

  5. linux umount 提示device is busy 的解决

    linux umount 提示"device is busy" 终极解决 为了干净地关闭或热交换 UNIX 或类 UNIX 系统上的存储硬件,必须能够卸载使用此设备上的存储的所有文件系统.但是,如果正 ...

  6. Linux 环境下umount, 报 device is busy 的问题分析与解决方法

    在Linux环境中,有时候需要挂载外部目录或硬盘等,但当想umount时,却提示类似“umount:/home/oracle-server/backup:device is busy”这种提示. 出现 ...

  7. Linux DTS(Device Tree Source)设备树详解之二(dts匹配及发挥作用的流程篇)【转】

    转自:https://blog.csdn.net/radianceblau/article/details/74722395 版权声明:本文为博主原创文章,未经博主允许不得转载.如本文对您有帮助,欢迎 ...

  8. I.MX6 Linux I2C device& driver hacking

    /******************************************************************************************* * I.MX6 ...

  9. Linux内核device结构体分析

    1.前言 Linux内核中的设备驱动模型,是建立在sysfs设备文件系统和kobject上的,由总线(bus).设备(device).驱动(driver)和类(class)所组成的关系结构,在底层,L ...

随机推荐

  1. Python-11-生成器

    一.定义 可以理解为一种数据类型,这种数据类型自动实现了迭代器协议(其他数据类型需要调用__iter__方法),所以生成器就是一种迭代器. 二.生成器的两种形式 1. 生成器函数 使用yield代替r ...

  2. Linux进程状态详解及状态转换

        学而不思则罔,思而不学则殆.    Linux下,进程状态有五种 : 运行态,可中断睡眠态,不可中断睡眠态,停止态和追踪态 运行态表示进程可执行或者正在执行, 可中断睡眠态表示进程被阻塞,等条 ...

  3. get merge --no-ff和git merge区别、git fetch和git pull的区别

    get merge --no-ff和git merge区别 git merge -–no-ff可以保存你之前的分支历史.能够更好的查看 merge历史,以及branch 状态. git merge则不 ...

  4. Centos7部署开源聊天软件rocket.chat

    一.部署rocket.chat 1.看官方文档部署,很简单,一步一步跟着部署即可 注意:需要部署节点需要联网主要是yum方式 https://rocket.chat/docs/installation ...

  5. UCOS内存管理

    STM32F10xxx内置64K字节的静态SRAM.它可以以字节.半字(16位)或全字(32位)访问 SRAM的起始地址是0x20000000 UCOSII //定义存储区 OS_MEM *DATA_ ...

  6. 获取项目中所有URL--获取swagger上展示的接口信息

    有时我们需要接口的一些基本信息,比如接口请求路径,接口请求方式等,我们用这些信息来做判断,或者入库. 我在开发接口权限的时候就遇到了这个问题,之前写的接口很多,现在需要将这些接口信息存到数据库中, 用 ...

  7. live555的使用(转载)

    Live555 是一个为流媒体提供解决方案的跨平台的C++开源项目,它实现了对标准流媒体传输协议如RTP/RTCP.RTSP.SIP等的支持.Live555实现 了对多种音视频编码格式的音视频数据的流 ...

  8. Python线性回归算法【解析解,sklearn机器学习库】

    一.概述 参考博客:https://www.cnblogs.com/yszd/p/8529704.html 二.代码实现[解析解] import numpy as np import matplotl ...

  9. 【JUC】3.ReentrantLock

    ReentrantLock实现Lock接口,所以先看下Lock接口: public interface Lock { // 获得锁 void lock(); // 获得锁 void unlock(); ...

  10. Mybatis,返回Map的时候,将Map内的Key转换为驼峰的命名

    每次使用mybatis的时候,简单的连表查询,用Map接收的时候,都是像DB定义的字段一样,类似以下 student_name,student_id,没有转换为驼峰,但是又不能因为这一个定义一个jav ...