I want to use the functionality of umount -l, then remove the underlying device as safely as possible afterward.
- I can't use
umount --forceto unmount the filesystem as it has become invisible to new processes. - I can't use
lsoffor an accurate list of the open files as the filesystem has become invisible to new processes. - If I use
lsofbeforeumount -l, there is a race contition of a new file being opened in between the two invocations.
I'm testing a work-around: sync && blockdev --setro /dev/<device>
The manual for blockdev --setro only says:
Set read-only.
Is the man page missing something? This seems to create a file on a --setro device:
# mount /dev/loop0 mountpoint/
# blockdev --setro /dev/loop0
# echo test > mountpoint/f
# sync
# umount mountpoint
# mount /dev/loop0 mountpoint/
mount: /tmp/mountpoint: WARNING: device write-protected, mounted read-only.
# cat mountpoint/f
test
#
Environment:
$ uname -a
Linux svelte 4.9.39-1-MANJARO #1 SMP PREEMPT Fri Jul 21 08:25:24 UTC 2017 x86_64 GNU/Linux
$ blockdev --version
blockdev from util-linux 2.30
blockdev: Document that--setroonly applies to new access #498 to have the full behaviour documented. – Tom Hale Aug 14 '17 at 05:10