47

When you unplug an USB drive without unmounting, your OS warns you about how dreadful could be such operation for your devices (I'm on OSX).

I usually follow the advice, unmounting before unplugging, but it happened many times (thousands) that, at the end of my tasks, I just unplugged (Hd storage, Cell phones, etc..) and I never ever noticed corrupted data on my devices.
Am I lucky or can this annoying warning just be ignored?

13
  • 2
    Not 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
    Aug 25, 2010 at 22:30
  • @Nifle that's what i'm talking about :) (actually, i have specified "at the end of my tasks") Aug 25, 2010 at 22:46
  • 1
    I'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
    Aug 26, 2010 at 8:11
  • 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
    Aug 26, 2010 at 10:39
  • 2
    another prize?! who's muffin ya butterin? ;-) here, have another vote... Sep 6, 2010 at 11:33

12 Answers 12

45

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).

8
  • 3
    Go for sync mounting! :D
    – Pylsa
    Aug 25, 2010 at 21:26
  • Is this still an issue when using a journaled filesystem?
    – NReilingh
    Aug 25, 2010 at 23:36
  • 1
    @NRei Yes. Journaled filesystems just prevent corruption of data if something goes wrong in the middle of the writing process. It doesn't prevent corruption or missing data due to the writing not having taken place at all because the drive was unplugged before the OS got around to write the data.
    – deceze
    Aug 26, 2010 at 1:47
  • @BloodPhilia: sync sometimes hurts more than performance, see my edit. Aug 26, 2010 at 19:28
  • 2
    Agreed - systempuntoout has been lucky so far. I have lost quite a bit of work by not unmounting before removing a flash drive. You can save all you want in your application, but if the writes are buffered, it hasn't happened where it matters. You only get burned by this once.
    – brice
    Sep 21, 2010 at 9:01
5

The main risk you have is delayed writing. For various reasons the system doesn't always write the data to a disk when it is told to and keeps it instead in memory. When you unmount it, it makes sure all that is then written to the disk (and makes sure it isn't currently being used). You would probably know if you are currently writing to the disk, but you might not realize that your OS hasn't written everything you previously told it to write.

The frequency of this depends on your system and what your doing with the USB drive. If unmounts are usually slow and you can hear the writing noise coming from the drive, then you should probably continue to unmount. If unmounts are always instant though, then feel free to skip this step at your own risk.

5
  • 4
    I believe most OS'es disable this sort of delayed write for removable drives, though. Aug 25, 2010 at 23:33
  • @Jeff, that would certainly be the sensible way to treat USB drives. Is there a way to check that? In Windows 7? Aug 26, 2010 at 6:48
  • @torbengb: Actually, it's not always sensible — see my edited answer. Aug 26, 2010 at 19:29
  • My USB if I go into the policies options, it's defaulted to use Quick Removal which says in the description that Safety Remove is not needed. The other option is Best Performance which is not the default but would require you to safety remove. So for most the default would be quick remove meaning not needing to safety remove. Apr 25, 2012 at 1:47
  • @Fogest, that’s true, but it’s also specific to Windows; the OP is using OSX. Of course, I’m sure that OSX does something similar.
    – Synetech
    Dec 19, 2013 at 21:31
4

I don't think anyone has addressed the issue of read vs write access. If you haven't copied anything to the flash drive, or opened a file on it for writing, you are probably safe just removing it -- if I only copy a file from a flash drive to my computer, I generally do not take the time to unmount it. But if I am copying files to the flash drive, then I do take the eatra step -- and yes, I have had corrupted files as a result of removing a flash drive too soon after writing to it.

3

I work in a casino and a lot of slot machine manufacturers now use USB thumbdrives to install the bin files (games and OS) onto the slot machine.

A slot machine that has corrupt firmware may or may not award thousands if not tens of thousands of dollars is great incentive to make sure the integrity of the data on that USB drive is not corrupt. Compliance/Regulator checks it anyway but it still saves work to do it right the first time.

In a corporate environment data loss could cost millions and personally you may lose something irreplaceable.

I'd certainly would make sure to unmount, safely remove or whatever terminology is used to make sure that any USB device with data on it is safe to remove.

1
  • 1
    But, copying mp3s to listen to, not so much.
    – cgp
    Aug 26, 2010 at 3:15
3

Driving a car without wearing a seat belt can be safe for most of the time. But when something goes haywire, you thank you used it.

So yes. Even if most of the time just removing the USB drive without unmounting it can be safe, it definitely is not recommended.

3

When a drive is being written to I have seen corruption when it was dismounted too early. While the OS doesn't hold data unwritten normally XP at least will accept write requests that back up.

I have had someone copy a file onto a flash drive and immediately hand it to me once the copy finished on his screen--the file was corrupt.

I have seen the write light flicker for some seconds after something supposedly has finished copying to a flash drive also.

2

If the system is performing file operations on the disk, there's a chance it'll corrupt data. Since it never happened to you, you're lucky. Use common sense to decide whether or not there's a chance your OS is performing operations. (Are there programs/files from the drive open/in use? Do I have caching on the drive on? Is it being indexed? Does my OS store temporary files on it?)

2

Anecdotal evidence, not proof, but I have had data corruption due to USB disconnection, but it has only occurred to me with Blackberry phones.

0
2

Trust me, YES.

You may thing nothing is accessing the USB drive, but in truth something is. This way I've trashed 3 external Backup HDDs, and lost Data in the amount close to 2 terabyte.

ALWAYS, ALWAYS, unmount before unplugging.

2
  • Wow, 3 HDD is bad luck. Aug 26, 2010 at 10:17
  • 3
    @systempuntoout: "Once it's funny, twice it's silly, three times it's worth a spanking." After the first couple of incidents, you might want to look deeper than "bad luck". Apr 28, 2011 at 9:38
1

Unmount it to be safe (if you are totally paranoid), but as already mentioned data loss mainly occurs due to delayed writes.

There is one other thing though and thats to do with my WD essentials portable drive. If I just unplug it without a clean mount, next time I plug it in it'll make the drive read-only. I have to reboot the pc with the drive in to make it writable again.. most definatly annoying!

0

Another scenario on a Windows 10 system is when a (here, 64 Gb, no readyboost) flash drive is physically removed while the system is in hibernation. After the system soft boots from the hibernate, a move or copy of any changed files on the flash stick may incur a file or directory is corrupt and unreadable error.
To bypass the error (along with the requisite chkdsk action producing a chk fragment or two, and "recovering" the otherwise perfectly healthy drive), we try the right_click_on_drive_to_eject, or dismount the stick. Fine, but when the user then disables/enables it in Devices, the drive will not appear in any explorer windows, and still shows up as No Media in Disk Management. The only way then to fully re-attach the device is simply to physically disconnect and re-connect the unit.
Thus it's preferable to gracefully dismount the device before unplugging it.

0

I'd like to point out that on some operating systems, one may choose the removal policy for each drive: if you select "Quick Removal", which is the default option on Windows 7, then one "can disconnect the device safely without using Safely Remove Hardware notification icon" (i.e., one doesn't have to unmount the USB drive before unplugging it):

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .