Skip to main content
Topic: Remove USB storage like a caveman (Read 2202 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: Remove USB storage like a caveman

Reply #1
On the command line or in a shell script afaik you can just:
Code: [Select]
# mount /dev/sd? /some/dir
# umount /dev/sd? /some/dir

umount will call sync internally, and sync will block until it completes. The only caveat is that with some older spinning disk drives they might say they have synced when data is in some internal buffer in the drive circuits, but not yet actually written to the magnetic disk, so you might want to add an arbitrary pause to be safe and give time for the hardware to react before you pull out the cable:
Code: [Select]
# mount /dev/sd? /some/dir
# sync
# sleep 10
# umount /dev/sd? /some/dir

I guess you could look at the source code for mount, umount and sync if you want to know more about the low level details of how they work?

Re: Remove USB storage like a caveman

Reply #2
I second #######'s suggestion. This is how I've always done it, and still do. Count to 5 or so before yanking out the stick/cable. For superstitious reasons.

I would also like to voice my opinion that "cavemen" chose to live in caves because that was simple, convenient, and the least-surprise solution in their environment.

Re: Remove USB storage like a caveman

Reply #3
I must be a caveman because I just 'sync' and when completed(back to prompt) I pull the USB stick out.
Or am I missing the point ?

Re: Remove USB storage like a caveman

Reply #4
I must be a caveman because I just 'sync' and when completed(back to prompt) I pull the USB stick out.
Or am I missing the point ?

I think theoretically that is correct, because sometimes when writing large files to disk, the prompt does not appear instantaneously, suggesting that it is waiting for the writing (or reading) to finish. I always wait a few seconds after that before unplugging the disk, but hey what do I know?!  ;D

Re: Remove USB storage like a caveman

Reply #5
If you don't umount then some file systems will record this as an unclean unmount, which can cause problems on some os'es or devices which will then declare the drive to be faulty or claim the contents are corrupt, and you might need to re-format the drive to get rid of the warnings and errors. If you can't be bothered to umount, you can leave the drive in place until you power off because the shut down procedure unmounts all drives automatically.

Re: Remove USB storage like a caveman

Reply #6
The only thing you do, aside from potentially damaging the drive, is confuse the proc information that feeds mount.  Eventually it will clear out the dead device from its table.  The new fangled run/media mechanism should sense the removal but if you mount by hand, like I do, it might be less happy.

sync is your friend, BTW

Re: Remove USB storage like a caveman

Reply #7
Edit: See OP

Re: Remove USB storage like a caveman

Reply #8
Microsoft filesystems (NTFS and FAT) and even some Linux ones like XFS have a dirty bit which records an unclean umount, although this can be cleared it can take a while to find a method that actually works for the case in question. I couldn't really find any single link to explain this in detail and give a list of affected file systems, but anyway, it's been my experience dirty bits can be annoying and I prefer to habitually do an actual umount, while there might be some FS's where it can be potentially skipped.
https://www.partitionwizard.com/clone-disk/dirty-bit.html

If you want to know more about the low level drive operations, this site might be helpful if you have not already found it:
https://wiki.osdev.org/Expanded_Main_Page