You are not logged in.

#1 2010-04-26 21:34:33

dcc24
Member
Registered: 2009-10-31
Posts: 732

USB drive, "device busy" when trying to unmount

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)

My AUR packages

Offline

#2 2010-04-26 22:05:47

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: USB drive, "device busy" when trying to unmount

How do you know it finished? It probably still writes data to device.

Offline

#3 2010-04-26 22:07:29

dcc24
Member
Registered: 2009-10-31
Posts: 732

Re: USB drive, "device busy" when trying to unmount

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)

My AUR packages

Offline

#4 2010-04-26 22:13:04

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: USB drive, "device busy" when trying to unmount

> 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

#5 2010-04-26 22:15:03

dcc24
Member
Registered: 2009-10-31
Posts: 732

Re: USB drive, "device busy" when trying to unmount

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)

My AUR packages

Offline

#6 2010-04-26 22:18:03

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: USB drive, "device busy" when trying to unmount

> 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

#7 2010-04-26 22:26:13

Spacenick
Member
From: Germany
Registered: 2010-04-02
Posts: 168

Re: USB drive, "device busy" when trying to unmount

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

#8 2010-04-26 22:28:51

dcc24
Member
Registered: 2009-10-31
Posts: 732

Re: USB drive, "device busy" when trying to unmount

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)

My AUR packages

Offline

#9 2010-04-26 22:54:32

knopwob
Member
From: Hannover, Germany
Registered: 2010-01-30
Posts: 239
Website

Re: USB drive, "device busy" when trying to unmount

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

#10 2010-04-26 23:21:11

thisoldman
Member
From: Pittsburgh
Registered: 2009-04-25
Posts: 1,172

Re: USB drive, "device busy" when trying to unmount

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

Board footer

Powered by FluxBB