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

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 1.3G 18G 7% /
devtmpfs 236M 0 236M 0% /dev
tmpfs 245M 0 245M 0% /dev/shm
tmpfs 245M 8.4M 237M 4% /run
tmpfs 245M 0 245M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
10.128.20.241:/var/linoxide 20G 1.3G 18G 7% /mnt/nfs/linoxide_srv
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

# umount /mnt/nfs/linoxide_srv/
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.

# lsof /mnt/nfs/linoxide_srv/
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 24098 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv
bash 24125 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv
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

# lsof /mnt/nfs/linoxide_srv/
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 24098 root cwd DIR 253,1 4096 519062 /mnt/nfs/linoxide_srv
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

# kill -9 24098

We can verify the result

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

We can see that one process is killed

# kill -9 24125

Now let's verify for the second process

# lsof /mnt/nfs/linoxide_srv/

Now let's try to unmount the folder

# umount /mnt/nfs/linoxide_srv/
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

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 1.3G 18G 7% /
devtmpfs 236M 0 236M 0% /dev
tmpfs 245M 0 245M 0% /dev/shm
tmpfs 245M 8.3M 237M 4% /run
tmpfs 245M 0 245M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
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.

# fuser /mnt/nfs/linoxide_srv/
/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.

# fuser -mv /mnt/nfs/linoxide_srv/
USER PID ACCESS COMMAND
/mnt/nfs/linoxide_srv:
root kernel mount /mnt/nfs/home_srv
root 24191 ..c.. bash
root 24275 ..c.. bash
linoxide 24290 ..c.. vim

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

# fuser -mv /mnt/nfs/linoxide_srv/
USER PID ACCESS COMMAND
/mnt/nfs/linoxide_srv:
root kernel mount /mnt/nfs/home_srv
root 24191 ..c.. bash
root 24275 ..c.. bash

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

# fuser -kmv /mnt/nfs/linoxide_srv/
USER PID ACCESS COMMAND
/mnt/nfs/linoxide_srv:
root kernel mount /mnt/nfs/home_srv
root 24191 ..c.. bash
root 24275 ..c.. bash

Check the result

# fuser -mv /mnt/nfs/linoxide_srv/
USER PID ACCESS COMMAND
/mnt/nfs/linoxide_srv:
root kernel mount /mnt/nfs/home_srv

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

# umount /mnt/nfs/linoxide_srv/

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

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 1.3G 18G 7% /
devtmpfs 236M 0 236M 0% /dev
tmpfs 245M 0 245M 0% /dev/shm
tmpfs 245M 8.3M 237M 4% /run
tmpfs 245M 0 245M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
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.

# fuser -mv /mnt/nfs/linoxide_srv/
USER PID ACCESS COMMAND
/mnt/nfs/linoxide_srv:
root kernel mount /mnt/nfs/home_srv
root 24366 ..c.. bash
root 24381 ..c.. bash
linoxide 24398 ..c.. vim

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

# umount -l /mnt/nfs/linoxide_srv/

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

# echo $?
0

Now let's check the mount point

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 1.3G 18G 7% /
devtmpfs 236M 0 236M 0% /dev
tmpfs 245M 0 245M 0% /dev/shm
tmpfs 245M 8.4M 237M 4% /run
tmpfs 245M 0 245M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0
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. UOJ343 清华集训2017 避难所 构造、打表

    传送门 玄学题 考虑构造三个数\(p_1p_2,p_1p_2,p_1p_2\)满足贪心分解会分解为\(p_1^3,p_2,p_2,p_2\),那么需要满足条件 1.\(p_1 , p_2 \in Pr ...

  2. Kubernetes1.11.1 使用Nvidia显卡配置方法

    一.安装 1.1.kubernetes硬件支持问题说明 Kubernetes目前主要在很小程度上支持CPU和内存的发现.Kubelet本身处理的设备非常少.Kubernetes对于硬件都使用都依赖于硬 ...

  3. 深度优先搜索(DFS)思路及算法分析

    1.算法用途: 用于遍历图中的节点,有些类似于树的深度优先遍历.这里唯一的问题是,与树不同,图形可能包含循环,因此我们可能会再次来到同一节点. 2.主要思想: 借用一个邻接表和布尔类型数组(判断一个点 ...

  4. js计算结果不精确问题解决--math.js的使用

    最近在做订单相关的一个功能,涉及到金额的计算,有人建议,将计算全部抛给后端来做吧,前端就不需要再维护一套算法了,话说的在理,但是呢,想想用户体验,单价*数量=金额,当用户改变一个数量时,用户都口算出来 ...

  5. ②将SVN迁移到GitLab-多分支多标签迁移

    之前我们介绍了<①将SVN迁移到GitLab-单分支迁移>,文中研究了svn迁移到git单分支的操作过程,本文针对实际开发过程中svn使用到的trunk.branches.tags情况进行 ...

  6. StatusStrip控件的使用(转:http://blog.sina.com.cn/s/blog_4f18c3ec0100fguf.html)

    c# winForm 将窗体状态栏StatusStrip 分成左中右三部分 右边显示当前时间 实现效果: 通过StatusStrip显示窗体状态栏 同时将状态栏分成三部分 居左边显示相关文字信息 中间 ...

  7. 命令行获取docker远程仓库镜像列表

    命令行获取docker远程仓库镜像列表 获取思路 通过curl获取镜像tag的json串,解析后得到${image}:${tag}的格式 curl获取示例 # curl [:-s] ${API}/${ ...

  8. JAVA - Windows下JDK默认安装的配置参数

    JDK版本1.8 JAVA_HOME C:\Program Files\Java\jdk1.8.0_60 CLASSPATH .;%%JAVA_HOME%%\lib;%%JAVA_HOME%%\lib ...

  9. python 操作excel实现替换特定内容

    本文介绍使用python语言,借助openyxl库来实现操作excel(xlsx)文件,实现替换特定内容的需求. 目前实现了3个小功能: 1. 全字匹配替换(mode1):(如:全字匹配 yocich ...

  10. obj + mtl 格式说明

    OBJ(或 .OBJ)是一种开放的几何定义文件格式,最初由Wavefront Technologies公司开发,用以描述其Advanced Visualizer动画包.该格式已被其他3D图形应用供应商 ...