Linux:卸载时哪个进程导致“设备繁忙”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/624154/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux: Which process is causing "device busy" when doing umount?
提问by flybywire
Linux: Which process is causing "device busy" when doing umount?
Linux:卸载时哪个进程导致“设备繁忙”?
采纳答案by MarkusQ
Look at the lsofcommand (list open files) -- it can tell you which processes are holding what open. Sometimes it's tricky but often something as simple as sudo lsof | grep (your device name here)
could do it for you.
查看lsof命令(列出打开的文件)——它可以告诉您哪些进程保持打开状态。有时这很棘手,但通常sudo lsof | grep (your device name here)
可以为您做一些简单的事情。
回答by alvatar
Just in case... sometimes happens that you are calling umount from the terminal, and your current directory belongs to the mounted filesystem.
以防万一……有时会发生您从终端调用 umount 的情况,而您的当前目录属于已安装的文件系统。
回答by Ben
You should use the fusercommand.
您应该使用fuser命令。
Eg. fuser /dev/cdrom
will return the pid(s) of the process using /dev/cdrom
.
例如。fuser /dev/cdrom
将使用 返回进程的 pid(s) /dev/cdrom
。
If you are trying to unmount, you can kill theses process using the -k
switch (see man fuser
).
如果您正在尝试卸载,您可以使用-k
开关终止这些进程(请参阅参考资料man fuser
)。
回答by Anonymous
lsof and fuser are indeed two ways to find the process that keeps a certain file open. If you just want umount to succeed, you should investigate its -f and -l options.
lsof 和 fuser 确实是查找保持某个文件打开的进程的两种方法。如果你只是想让 umount 成功,你应该调查它的 -f 和 -l 选项。
回答by Anonymous
That's exactly why the "fuser -m /mount/point" exists.
这正是“fuser -m /mount/point”存在的原因。
BTW, I don't think "fuser" or "lsof" will indicate when a resource is held by kernel module, although I don't usually have that issue..
顺便说一句,我认为“fuser”或“lsof”不会指示内核模块何时持有资源,尽管我通常没有这个问题..
回答by mas
lsof +f -- /mountpoint
(as lists the processes using files on the mount mounted at /mountpoint. Particularly useful for finding which process(es) are using a mounted USB stick or CD/DVD.
(列出了使用挂载在 /mountpoint 上的挂载文件的进程。对于查找哪些进程正在使用挂载的 USB 记忆棒或 CD/DVD 特别有用。
回答by Jay
Check for open loop devices mapped to a file on the filesystem with "losetup -a". They wont show up with either lsof or fuser.
使用“losetup -a”检查映射到文件系统上文件的开环设备。他们不会与 lsof 或 fuser 一起出现。
回答by Malvineous
Also check /etc/exports
. If you are exporting paths within the mountpoint via NFS, it will give this error when trying to unmount and nothing will show up in fuser
or lsof
.
还要检查/etc/exports
。如果您通过 NFS 导出挂载点内的路径,则在尝试卸载时会出现此错误,并且fuser
或 中不会显示任何内容lsof
。
回答by captcha
lsof and fuser didn't give me anything either.
lsof 和 fuser 也没有给我任何东西。
After a process of renaming all possible directories to .old and rebooting the system every time after I made changes I found one particular directory (relating to postfix) that was responsible.
在将所有可能的目录重命名为 .old 并在每次进行更改后重新启动系统的过程之后,我发现一个特定的目录(与 postfix 相关)负责。
It turned out that I had once made a symlink from /var/spool/postfix to /disk2/pers/mail/postfix/varspool in order to minimise disk writes on an SDCARD-based root filesystem (Sheeva Plug).
事实证明,我曾经创建了一个从 /var/spool/postfix 到 /disk2/pers/mail/postfix/varspool 的符号链接,以尽量减少对基于 SDCARD 的根文件系统(Sheeva Plug)的磁盘写入。
With this symlink, even after stopping the postfix and dovecot services (both ps aux as well as netstat -tuanp didn't show anything related) I was not able to unmount /disk2/pers.
使用此符号链接,即使在停止 postfix 和 dovecot 服务(ps aux 和 netstat -tuanp 都没有显示任何相关内容)之后,我也无法卸载 /disk2/pers。
When I removed the symlink and updated the postfix and dovecot config files to point directly to the new dirs on /disk2/pers/ I was able to successfully stop the services and unmount the directory.
当我删除符号链接并更新后缀和 dovecot 配置文件以直接指向 /disk2/pers/ 上的新目录时,我能够成功停止服务并卸载目录。
Next time I will look more closely at the output of:
下次我将更仔细地查看以下输出:
ls -lR /var | grep ^l | grep disk2
The above command will recursively list all symbolic links in a directory tree (here starting at /var) and filter out those names that point to a specific target mount point (here disk2).
上面的命令将递归列出目录树中的所有符号链接(这里从 /var 开始)并过滤掉那些指向特定目标挂载点(这里是 disk2)的名称。
回答by Slobodan Pejic
Filesystems mounted on the filesystem you're trying to unmount can cause the target is busy
error in addition to any files that are in use. (For example when you mount -o bind /dev /mnt/yourmount/dev
in order to use chroot
there.)
target is busy
除了正在使用的任何文件之外,挂载在您尝试卸载的文件系统上的文件系统也可能导致错误。(例如当你mount -o bind /dev /mnt/yourmount/dev
为了使用chroot
那里。)
To find which file systems are mounted on the filesystem run the following:
要查找文件系统上挂载了哪些文件系统,请运行以下命令:
mount | grep '/mnt/yourmount'
mount | grep '/mnt/yourmount'
To find which files are in use the advice already suggested by others here:
要查找正在使用的文件,请参考其他人在此处提出的建议:
lsof | grep '/mnt/yourmount'
lsof | grep '/mnt/yourmount'