系统相关
首页 > 系统相关> > 如何在Linux中临时提取闪存驱动器或HDD?

如何在Linux中临时提取闪存驱动器或HDD?

作者:互联网

假设我以这种方式安装了磁盘:

mount /dev/sdb /mnt/tmp

我在这个文件系统上打开了一些文件,并且不想卸载它.但是我想暂时提取设备,然后再重新安装.我希望对此文件系统的所有读取和写入仅在缓存中执行,或者挂起,直到我重新连接设备.

如果我考虑提前暂时分离,我会使用设备映射器:

# ls -lh /dev/sdb
brw-rw---- 1 root floppy 8, 16 Sep 12 17:38 /dev/sdb
# blockdev --getsize /dev/sdb
2211840
# dmsetup create sdb_detachable --table '0 2211840 linear 8:16 0'
# mount /dev/mapper/sdb_detachable /mnt/tmp
(start working with the filesystem)
(suddenly need to detach the device)
# dmsetup suspend sdb_detachable
# dmsetup load sdb_detachable --table '0 2211840 error'
# blockdev --flushbufs /dev/sdb
(eject the device)
(maybe even use the cached part of the filesystem)
(reattach the device, now it appears as /dev/sdc)
# ls -lh /dev/sdc && blockdev --getsize /dev/sdc
brw-rw---- 1 root floppy 8, 32 Sep 12 17:51 /dev/sdc
2211840
# dmsetup load sdb_detachable --table '0 2211840 linear 8:32 0'
# dmsetup resume sdb_detachable
(filesystem is usable again)
(finished using it, now need to clean up)
# umount /mnt/tmp/
# dmsetup remove sdb_detachable
# eject /dev/sdc

如果直接安装设备,如何实现这一目标?我可以将其“窃取”到设备映射器中吗?

解决方法:

嗯,这很酷.我不知道dmsetup可以做到这一点.

标签:vfs,usb-drive,linux,external-hdd,device-mapper
来源: https://codeday.me/bug/20190812/1642885.html