umount.nfs4: /mnt/nfs/code404: device is busy

Posted by music_man on Mon, 03 Jan 2022 07:47:19 +0100

introduce

When performing an NFS mount, you may see the device busy. In this case, you must force the uninstall in an appropriate way.

View mounted partitions

Using df -h to view partitions

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1  20G 3G 18G 7% /
devtmpfs  236M 0 236M 0% /dev
tmpfs     245M 0 245M 0% /dev/shm
tmpfs     245M 4M 237M 4% /run
tmpfs     245M 0 245M 0% /sys/fs/cgroup
tmpfs      49M 0 49M 0% /run/user/0
192.168.55.101:/var/code404 20G 3G 18G 7% /mnt/nfs/code404

Uninstall nfs mount

Prompt device is busy

umount /mnt/nfs/code404
umount.nfs4: /mnt/nfs/code404: device is busy

Use lsof to view occupied processes

The lsof (list open files) command displays a list of all open files and their associated processes on a specific file system, directory or device. By default, it lists all currently open files, shared libraries and directories, and provides as much information as possible about each file. You can use pipes to filter the output to provide information such as PID, USER, etc.

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

The PID of the process using the installed folder exists and displays the command being executed and the user executing the command
It can kill the process in use, but it can process the executed commands
You can see the vim command above. This means that the code404 user is editing the file
Therefore, if you kill the process, its progress will be lost. Let's look at the results, assuming you have informed him

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

It seems that the user has stopped making changes, but is still running the bash command, but I don't know why. You can kill two processes with the kill command. Don't miss the PID of the killed process.

Kill bash process

kill -9 24098 24125
lsof /mnt/nfs/code404/

umount uninstall folder

umount /mnt/nfs/code404/
umount: /mnt/nfs/code404/: not mounted

When killing the process, it seems that the folder is automatically uninstalled. Check it with the df command

df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 20G 3G 18G 7% /
devtmpfs  236M 0 236M 0% /dev
tmpfs     245M 0 245M 0% /dev/shm
tmpfs     245M 3M 237M 4% /run
tmpfs     245M 0 245M 0% /sys/fs/cgroup
tmpfs     49M 0 49M 0% /run/user/0

fuser lookup process

The fuser command helps identify the processes that prevent the file system from unmounting. Finds the user processes associated with the files, directories, or file system mount points specified as command line parameters.

fuser /mnt/nfs/code404/
/mnt/nfs/code404: 24191c

You can use the fuser command - m to list the options for all processes accessing files or mount points on the file system - v to display the results of PID commands, users, executed commands, etc.

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

You can use the fuser command to stop the running process directly- k no option - kill Command

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

Inspection results

fuser -mv /mnt/nfs/code404/
 USER PID ACCESS COMMAND
 /mnt/nfs/code404:
 root kernel mount /mnt/nfs/code404

Only mount appears to be running. Let's uninstall the folder

umount /mnt/nfs/code404/

No error message, uninstall normally

summary

You need to urgently uninstall the partition or just delete the device, but this may cause problems because the device is busy. Before deciding how to solve the problem, you must check all processes on the system. The lsof and fuser commands make it easy to identify processes that are preventing the file system from unmounting.

CSDN_ Code 404: umount nfs4: /mnt/nfs/code404: device is busy
https://www.code404.icu/1544.html

Topics: Linux bash server