You are not logged in.
Basically, I copy a file to the usb drive, either through a gui or with "cp". After it finishes I cannot immediately unmount the drive as it says "device busy". Only after several seconds have passed, I can remove it safely. If I unplug it before it stops being busy and check it on a different computer, I lose the copied file. There is simply no trace of it.
Why is this happening? Any ideas?
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
How do you know it finished? It probably still writes data to device.
Offline
Well, if I use "cp", I expect it to finish writing when the command terminates. If I use a gui app (say, thunar) I expect it to finish when it closes the copy dialog. Shouldn't this be the expected behaviour?
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
> Shouldn't this be the expected behaviour?
I'm not an expert but maybe the fs options modify this behavior - how often you flush data, the sync parameters etc. USB is slower than your hard drive so maybe the data is put in a buffer and then is written via USB to the device.
Offline
I agree, it is probably related to the fs mount options. So, how should I alter them so it actually works as expected?
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
> how should I alter them so it actually works as expected?
Sorry, but I don't know. As I said, I'm not an expert.
http://linux.die.net/man/8/mount
Offline
as far as I know modern file systems will guarantee that after cp reading it will give the right result but that doesn't mean it's physically written to disk already. This is expected behaviour as it's very important performance wise. If an application needs to really know it's on disk it's required to run fsync.
If you want you can run "sync" on the command line that will write everything to disk.
Offline
Thanks for the info. But how do I make it default behaviour? It's extremely annoying that whenever I unplug a USB drive right after "cp" finishes, I lose all my data. Other OSes don't have this "problem" (some might call this a feature) so I'm sure I can just force it to sync all the time.
It is better to keep your mouth shut and be thought a fool than to open it and remove all doubt. (Mark Twain)
Offline
have a look at "sync" as a mount option. This should be what you want. If you mount the stick via command line add "-o sync".
Edit: but iirc, if there are still some data in the cache, waiting to be written to the stick, umount doesn't say the device is busy rather than just take longer to finish. Because umount takes care of writing all pending data to the stick.
Last edited by knopwob (2010-04-26 22:58:40)
Offline
There are sometimes ways to shorten the time data spends in the cache before it is written to the disk, but it depends on the file system used. For vfat formatted USB flash drives, I use 'noatime' as a general speed-up and 'flush' to speed up writes to disk.
The complete vfat options I use are:
rw,noexec,nosuid,nodev,noatime,shortname=lower,flush,utf8,gid=100
I'd recommend 'noatime' for any drive. I don't have a need to record file access times on a single user machine.
'man 8 mount' is not filled with a lot of info about what the 'flush' option does (I copied my mount options from my wife's Opensuse machine):
If set, the filesystem will try to flush to disk more early than normal.
Not set by default.
Offline