我有一些samba驱动器,每天都有多个用户访问。我已经有了识别共享驱动器(从SQL表)的代码,并将它们挂载到所有用户都可以访问它们的特殊目录中。
我想知道,如果我从我的SQL表中删除驱动器(有效地使其脱机)如何,甚至是,有一种方法来卸载繁忙的设备?到目前为止,我发现任何形式的umount都不起作用。
忽略破坏数据的可能性-是否有可能卸载当前正在读取的设备?
我有一些samba驱动器,每天都有多个用户访问。我已经有了识别共享驱动器(从SQL表)的代码,并将它们挂载到所有用户都可以访问它们的特殊目录中。
我想知道,如果我从我的SQL表中删除驱动器(有效地使其脱机)如何,甚至是,有一种方法来卸载繁忙的设备?到目前为止,我发现任何形式的umount都不起作用。
忽略破坏数据的可能性-是否有可能卸载当前正在读取的设备?
当前回答
看看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.
其他回答
使用exportfs -v检查导出的NFS文件系统。如果发现,使用exportfs -d share:/directory删除。这些不会在fuser/lsof列表中显示,并且会阻止umount成功。
是的! !有一种方法可以立即分离繁忙的设备-即使它繁忙且不能强制卸载。你可以稍后清理:
umount -l /PATH/OF/BUSY-DEVICE
umount -f /PATH/OF/BUSY-NFS (NETWORK-FILE-SYSTEM)
注意/警告
这些命令可能会中断正在运行的进程,导致数据丢失或损坏打开的文件。在强制卸载后,访问目标DEVICE/NFS文件的程序可能会抛出错误或无法正常工作。 不要在挂载路径(文件夹/驱动器/设备)内部执行以上umount命令。首先,您可以使用pwd命令验证您的当前目录路径(不应该是挂载路径),然后使用cd命令退出挂载路径-稍后使用上述命令卸载它。
当一切正常时,另一个选择是编辑/etc/fstab,添加noauto标志并重新启动机器。设备将不会被安装,当你完成任何操作时,移除标志并重新启动。
文件夹内的多个挂载
另一个原因可能是在你的主挂载文件夹中有一个副挂载,例如,在你为嵌入式设备使用SD卡后:
# mount /dev/sdb2 /mnt # root partition which contains /boot
# mount /dev/sdb1 /mnt/boot # boot partition
卸载/mnt将失败:
# umount /mnt
umount: /mnt: target is busy.
首先我们必须卸载引导文件夹,然后卸载根目录:
# umount /mnt/boot
# umount /mnt
众答:
如果该设备上有一个zfs池,至少当它是一个基于文件的池时,lsof将不会显示使用情况。但你可以简单地跑步
sudo zpool export mypool
然后卸载。