我有一些samba驱动器,每天都有多个用户访问。我已经有了识别共享驱动器(从SQL表)的代码,并将它们挂载到所有用户都可以访问它们的特殊目录中。
我想知道,如果我从我的SQL表中删除驱动器(有效地使其脱机)如何,甚至是,有一种方法来卸载繁忙的设备?到目前为止,我发现任何形式的umount都不起作用。
忽略破坏数据的可能性-是否有可能卸载当前正在读取的设备?
我有一些samba驱动器,每天都有多个用户访问。我已经有了识别共享驱动器(从SQL表)的代码,并将它们挂载到所有用户都可以访问它们的特殊目录中。
我想知道,如果我从我的SQL表中删除驱动器(有效地使其脱机)如何,甚至是,有一种方法来卸载繁忙的设备?到目前为止,我发现任何形式的umount都不起作用。
忽略破坏数据的可能性-是否有可能卸载当前正在读取的设备?
当前回答
以防有人和你一样。:
我无法卸载chroot监狱的挂载点(here /mnt)。
下面是我输入的命令:
$ umount /mnt
umount: /mnt: target is busy.
$ df -h | grep /mnt
/dev/mapper/VGTout-rootFS 4.8G 976M 3.6G 22% /mnt
$ fuser -vm /mnt/
USER PID ACCESS COMMAND
/mnt: root kernel mount /mnt
$ lsof +f -- /dev/mapper/VGTout-rootFS
$
您可以注意到,即使lsof也没有返回任何内容。
然后我有了这样的想法:
$ df -ah | grep /mnt
/dev/mapper/VGTout-rootFS 4.8G 976M 3.6G 22% /mnt
dev 2.9G 0 2.9G 0% /mnt/dev
$ umount /mnt/dev
$ umount /mnt
$ df -ah | grep /mnt
$
这里是一个/mnt/dev绑定到/dev,我创建它是为了能够从chroot监狱中修复我的系统。
在umounting之后,我的pb。现在解决了。
其他回答
sudo fusermount -u -z <mounted path>
注意:不要对路径使用补全,因为这也会冻结终端。
看看umount2:
Linux 2.1.116 added the umount2() system call, which, like umount(), unmounts a target, but allows additional flags controlling the behaviour of the operation: MNT_FORCE (since Linux 2.1.116) Force unmount even if busy. (Only for NFS mounts.) MNT_DETACH (since Linux 2.4.11) Perform a lazy unmount: make the mount point unavailable for new accesses, and actually perform the unmount when the mount point ceases to be busy. MNT_EXPIRE (since Linux 2.6.8) Mark the mount point as expired. If a mount point is not currently in use, then an initial call to umount2() with this flag fails with the error EAGAIN, but marks the mount point as expired. The mount point remains expired as long as it isn't accessed by any process. A second umount2() call specifying MNT_EXPIRE unmounts an expired mount point. This flag cannot be specified with either MNT_FORCE or MNT_DETACH. Return Value On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
如果可能的话,让我们定位/识别繁忙的进程,终止该进程,然后卸载samba共享/驱动器,以最大限度地减少损害:
Lsof | grep '< /dev/sda1的挂载点>'(或任何被挂载的设备) kill target_process(将busy proc.按名称| kill PID | killall target_process) Umount /dev/sda1(或任何已挂载的设备)
有人提到过,如果你正在使用终端,而你的当前目录在你想要卸载的路径中,你会得到错误。 作为补充,在这种情况下,你的lsof | grep path-to-be unmounted必须有以下输出:
bash ... path-to-be-unmounted
在卸载文件系统之前。我们需要检查是否有任何进程持有或使用文件系统。这就是为什么它显示设备繁忙或文件系统正在使用。 运行以下命令查看文件系统所使用的进程:
定影器 -cu /本地/mnt/
它将显示有多少进程持有/使用文件系统。
Local /mnt: 1725e(root) 5645c(shasankarora)
ps -ef | grep 1725 < - > ps -ef | grep < pid >
Kill -9 pid
杀死所有进程,然后您将能够卸载分区/繁忙设备。