-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data can be written on an unmounted filesystem #493
Comments
On Friday 11 August 2017, Tom Hale wrote:
Your described behavior is exactly what lazy umount is made for.
Lazy umount only hides the filesystem from new processes. Already opened
files and directories will still behave like mounted.
You could remount read-only to avoid any further writes:
sudo mount -o remount,ro /tmp/mountpoint/
sudo umount -l /tmp/mountpoint
### Conundrums
1. How do I know when a filesystem unmounted with `umount -l` has
actually been unmounted?
Yes, this would be interesting to know.
2. How can I force the unmount of the device
after an `umount -l`?
You should avoid using `umount -l` at all. Just kill all processes which
are using /tmp/mountpoint and then umount without option -l.
To find all the processes using mountpoint you can use
sudo lsof | grep mountpoint
|
I want to be able to use Why do you say The
It seems to quite dangerous that there is: (I hope I'm wrong!)
So the user is left in limbo-land. I wonder, is |
The filesystem is invisible for another processes after after umount --lazy, it does not makes sense to use tools like lsof. I don't think standard "umount" produces file corruption. The umount(2) return -EBUSY in this case and filesystem is not mounted. You have to remove all processes (and so on) to umount filesystem. The --force is designed for NFS, I have doubts any another filesystem uses this. This is really how --lazy is designed, I don't see any bug here. Sorry. |
So is there a kernel mechanism to know when the device has eventually been unounted and is safe to remove? A running |
The answer to my question immediately above is that it's not easy. @karelzak Thanks for the grace with which you handled communication on this non-issue :) |
On my system:
I have been observing some strange behaviour:
/dev/sdb
to/dev/sdc
and sometimessdd
/dev/sdb
when only/dev/sdc
exists in the filesystemI've tracked down what I believe to be the cause: I have a script to unmount everything under
/media
withumount -l
so I can then disconnect my removable media.Here is an example of:
umount -l <filesystem>
umount --force --all-targets /dev/<device>
Below,
/dev/sdb
is a USB HDD with two partitions combined via btrfs magic into a single filesystem. (There is an ext4 example of writing to an unmounted device after this one)Write data on an unmounted filesystem
Mount the 'svelte-backup' filesystem:
Keep a "lock" on the filesystem and device via current directory:
File SURPRISE doesn't exist:
Unmount the filesystem
--lazy
:Then really unmount it:
Write SURPRISE to an unmounted filesystem and device:
Physically disconnect and reconnect USB HDD
Now
/dev/sdb
is somehow "locked" by the working directory.The reinserted device lists as
/dev/sdc
:Remove current directory "lock":
Mount the newly named device:
SURPRISE
file was written to an unmounted filesytem.Reproducible example, using loopback mounted ext4 filesystems
Create a new mountpoint, filesystem and mount it:
Now change to the directory to get the weird behaviour:
Unmount the filesystem while inside its mountpoint:
So now, I am told that the device is unmounted.
Write a new file to where the filesystem was previously mounted. I would expect that this would either error (as the reference to the current directory is invalid), or write the file to the directory which the filesystem was hiding while it was mounted.
Hmm, no error... so where is our surprise hiding?
And it wasn't written to the underlying mountpoint directory.
Could it have been written to the device which I was told was unmounted?
Prove no caching is at play: Remove the loopback device, copy the filesystem file:
Mount the copied filesystem (which should be empty):
SURPRISE
the file was written to an umounted filesystem.Conundrums
umount -l
has actually been unmounted?umount -l
?The text was updated successfully, but these errors were encountered: