Either you're lucky to never have had corrupted data, or you're unlucky to never had noticed your data was corrupted.
When you perform an action that should write on a disk, most operating systems put the write operation into a queue. From time to time, they flush the queue. (I'm calling it a queue here, but actually operations can be performed out of order, operating systems do this when it's faster and gives the same final result.) This can make the write operations a lot faster, both because the system tries to perform them when it doesn't have anything better to do and because it can group them intelligently.
If you happen to unplug your device before everything has been written, you may miss the latest data. Worse, if the OS has been performing operations out of order, you may put your device into an inconsistent state and lose more than the latest data.
Some operating systems go into a more conservative (but slower) mode for removable devices, to reduce the risks associated with unplugging the device before it has been unmounted.
ADDED:
Doing operations out of order is sometimes not just a matter of speed. Cheap flash media (that doesn't to sector reallocation at the hardware level) has a limitation on the number of times you can write over any given sector. If you naively write all changes as they happen, this can kill the sectors that contain the file allocation table on a (V)FAT filesystem (the most common case for removable drives) or the journal on a typical modern filesystem. (See e.g. this discussion of sync
on the Linux Kernel mailing list.) Here, not updating the FAT or journal every time a file is written to is not just a big performance gain, it's also good for the lifetime of the hardware.
Until recently, Linux only gave a choice between sync
(write all changes as they happen) and async
(write whenever it's convenient). Recent versions introduce the flush
option for FAT filesystems, which is somewhere in between (flush all delayed writes as soon as the disk becomes inactive); it's on by default in Ubuntu 10.04.
On a different note, unmounting a removable drive ensures that no application has a file open. If you don't unmount before unplugging, you won't notice if you have unsaved data until it's too late. Unmounting while a file is open also increases the chance of corruption, both at the filesystem level (the OS may have queued some operations until the file is closed) and at the application level (e.g. if the application puts a lock file, it won't be removed).
2Not posting an answer since my data is totally anecdotal. I have been a sysadmin and then a software developer for about 15 years and many of my friends is in the same trade and I can't remember one person complaining about data-loss from unplugging a USB device without unmounting. Just use some common sense. Don't pull it out while you are copying/moving stuff. – Nifle – 2010-08-25T22:30:56.247
@Nifle that's what i'm talking about :) (actually, i have specified "at the end of my tasks") – systempuntoout – 2010-08-25T22:46:43.697
1I'd like to offer an additional anecdotal story - in the lab's at Uni people would (obviously) plug USB sticks in for transporting work about. We didn't have the relevant permissions to unmount (don't ask..) and after the first term several large important looking signs appeared telling people not to use the USB ports in the keyboards, this was because they kept corrupting sticks (I knew personally of at least four incidents). But, the ones in the base units used in the same way (without unmount permissions) seemed to work fine! – DMA57361 – 2010-08-26T08:11:33.930
1@DMA57361, If you don't have permissions to unmount (I wonder how you mounted then in first place then... bad bad admin), you can anyways run
sync
, wait for a few seconds and then unplug. – user39559 – 2010-08-26T10:39:26.860@user39559 - the machines are WinXP, so I don't think
sync
is available to me? – DMA57361 – 2010-08-26T11:21:16.690@DMA57361: I believe he is referring to the Sync utility by Sysinternals. http://technet.microsoft.com/en-us/sysinternals/bb897438.aspx
– Hello71 – 2010-08-31T00:45:28.880@systempuntoout: I believe you may have a typo in your name: "systempunt o out". – Hello71 – 2010-08-31T00:53:34.943
@Hello, thanks for that. Looks handy, but the blurb says it needs administrative privileges to run - which I don't have on the Uni machines. – DMA57361 – 2010-08-31T06:56:57.567
@Hello71 nope but thanks :), punto means dot in italian. If you are familiar with Java, you probably already know System.Out . – systempuntoout – 2010-08-31T12:19:51.443
2another prize?! who's muffin ya butterin? ;-) here, have another vote... – Sky Sanders – 2010-09-06T11:33:28.620
I can't remember one person complaining about data-loss from unplugging a USB device without unmounting.
@Nifle, what OS(es) are you referring to? What you describe is likely due to two factors: (1) removable drives default to a quick-removal policy in Windwos (and likely in other OSes as well), which forgoes write-caching so that it doesn’t have to be ejected, and (2) most people probably won’t notice when there’s corruption right away, and even if they do, they probably won’t associate it with a lack of ejection. – Synetech – 2013-12-19T21:34:04.323@DMA57361, were the keyboards brand-names? I have experienced a lot of problems with cheap Chinese SD card readers from eBay corrupting memory-cards, while better card-readers never had problems with the same cards. It is probably the quality of the readers in my case, and USB ports/hubs in the keyboards in your case. – Synetech – 2013-12-19T21:36:05.097
@Synetech Haven't a clue now I'm afriad, it was a long time ago now (relatively speaking) and IIRC they'd refurbished the Uni labs (inc computer replacement) in the year before I left, so the last machines I used there wouldn't be those mentioned in my comment. – DMA57361 – 2013-12-20T08:40:28.177