Re: Remove USB storage like a caveman
Reply #1 –
On the command line or in a shell script afaik you can just:
# 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:
# 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?