- You cannot know if the the device is actually unmounted or not
- The "unmounted" filesystem remains accessible in some circumstances
- The "unmounted" filesystem is not accessible in some circumstances
There is a false sense of security: it appears that the filesystem has been unmounted, but in reality it has only been hidden from the file namespace / heirarchy.
- Processes can still write via open file descriptors
- New or existing files can be opened for writing by processes with a working directory inside the mountpoint via relative pathnames
This means that if you umount -l /media/hdd
you will no longer be able to access /media/hdd/dir/file
(absolute pathname) but if you have a process with working directory /media/hdd
it will still be able to create new processes which can read/write ./dir/file
(relative pathname).
If you try to unmount the device, you will a confusing message:
# umount --force --all-targets /dev/sdb2
umount: /dev/sdb2: not mounted
This makes it look like the device has unounted, but there still can be processes writing to the disk.
Since there are various non-obvious situations that can cause umount to block, the filesystem may still not be unmounted even though lsof +f -- /dev/device
shows nothing.
You'll never know if the filesystem actually unmounts. There's no way to find out.
Removable devices
If you do umount -l
a removable disk, you're in limbo-land: you can't be sure that all pending data has been written to disk.
The best you can do after a umount -l
is to ensure all writing completes and prevent future writing, but you still can't guarantee that it has been unmounted.
With removable devices, if the device isn't properly unmounted, strange behaviour can result the next time it is plugged in:
The device will get an incremented device name, ie /dev/sdb
becomes /dev/sdc
. The kernel log messages may still refer to /dev/sdb
even though that device no longer exists as a file under /dev
. (The only way I know to resolve this is to reboot.)
btrfs corruption can result. btrfs expects that only one filesystem with a given UUID is present at one time. The kernel still sees the same UUID available on the phantom device and the new device. (I had to rebuild my btrfs backup HDD).
systemd
gotchas
umount(2)
several times recently. It says only "Perform a lazy unmount: make the mount point unavailable for new accesses, immediately disconnect the filesystem and all filesystems mounted below it from each other and from the mount table, and actually perform the unmount when the mount point ceases to be busy." But unfortunately this is less detail even than what you have provided. – Jonathon Reinhart Jan 10 '19 at 02:18umount(8)
says that a file system is busy "for example, when there are open files on it, or when some process has its working directory there, or when a swap file on it is in use." That doesn't sound like a definitive list, but is probably as good as I'll be able to find. – Jonathon Reinhart Jan 10 '19 at 02:23/proc/<PID>/cwd
,/proc/<PID>/root
and/proc/<PID>/fd/<FD>
respectively. Those are absolute paths, and the files are accessible by name, so the list of "things you can't do" from the linked answer is pretty pointless and misleading. – Jan 26 '21 at 18:58cd
to/proc/<PID>/cwd
=>/
(where PID is a process whose cwd is on an unmounted fs) will not change to your root directory, but to the actual cwd of that process, within the unmounted fs. And yes, you can also use that directly e.g. as/proc/<PID>/fd/<DIRFD>/subdir/file
. Even though it's the "culture" here and I should've get used to it, this total disregard for the facts still pisses me off. Mightily. – Jan 27 '21 at 08:23/
. I think I stumbled on this behavior and remembered being surprised when working ongitlab-pages
. But if you look at this thread, I clearly didn't 100% understand it. And re-reading that thread led me to post my (again) inaccurate comment above. – Jonathon Reinhart Jan 27 '21 at 18:11unlink
for the FS from its original mountpoint. Other than that disconnect, the mountpoint is still completely viable and usable. Again, sorry for the stubbornness and thanks for setting me straight. – Jonathon Reinhart Jan 27 '21 at 18:18mountpointmounted filesystem, except open new files/directories by absolute path from the original mountpoint**. Do you concur? Feel free to leave any feedback at that answer, as this conversation has become a little detached. – Jonathon Reinhart Jan 27 '21 at 18:20