Suppose I mounted a disk in this way:
mount /dev/sdb /mnt/tmp
I have some files opened on this filesystem and don't want to unmount it. However I want to temporarily extract the device, then reattach it later. I want all reads and writes to this filesystem to be performed in cache only or be hung until I reattach the device.
If I thought about temporarily detaching in advance, I would have used the device mapper:
# 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
How can this be accomplished if the device is mounted directly? Can I "steal" it into the device mapper?