I have always just unplugged my USB drives from my computer for years and nothing bad has happened; but I heard that you are supposed to use "Safely Remove Hardware
" before removing a drive. What does the "Safely Remove Hardware
" program do (besides flush the output buffer)?
Is this recommended just to ensure that all data transmission to the device has stopped, or is there another reason?
-
I also checks to be sure the drive is not in use or being written to.– MoabNov 15, 2011 at 21:08
-
It does NOT affect the drive itself. It can however affect the files on the drive. This is because as stated before, files are in cache at the time, so when you eject the drive it will write the files to the drive, otherwise you may get corrupted files.– MattNov 17, 2011 at 8:44
-
@Matt: Drives have caches too.– Billy ONealNov 17, 2011 at 22:38
-
@BillyONeal i never said it didnt :), when i say drive i mean the actual platters, from volatile memory to nonvolatile memory.– MattNov 18, 2011 at 7:32
-
@Matt: How on earth is that not affecting the platters? The eject operation flushes buffers onto the platters.– Billy ONealNov 18, 2011 at 14:54
3 Answers
This depends on what settings you have set for the drive. For instance, if you look in the device manager for the disk drive itself, you'll see something like this:
If you have the first option (quick removal) selected, then ejecting the drive merely unmounts the partition, and no longer allows programs to access the drive.
If you choose the second option (better performance), then ejecting the drive flushes any caches the OS has in memory, unmounts the filesystem (which may also flush a few buffers), and flushes on-device buffers.
-
7+1 for noting that "it depends" on the config, and including a screenshot Nov 15, 2011 at 21:32
-
Nice answer! Would you be interested in writing about this briefly for the Super User Blog? If so, let me know in chat or by responding to this comment.– nhinkleNov 16, 2011 at 5:49
-
This assumes you're using Windows of course... Mac and Linux machines don't have that option AFAIK, but will still complain if you pull out the USB stick before unmounting the drive.– calum_bNov 16, 2011 at 11:19
-
@scottishwildcat - Mac and Linux machines defer the handling of cache to the filesystem code. FAT(32, exFAT etc) filesystems by default sync writes every 5s, NTFS(rw - fuse implementation) is always tricky and beyond my knowledge, ext2,3 behaves similar to FAT.. XFS, btrfs, ext4 by default is way more fun, I have no idea about UFS/UFS+ in MacOSX.– qdotNov 16, 2011 at 12:52
-
1@qdot: Most consumer level drives don't do much in the way of write back caching. More enterprisey drives almost always have some form of write-back caching either on the drive or controller. Both types are available as external versions. It's not the USB Mass Storage spec we're talking about here; that same dialog is used for any type of device that can be disconnected; e.g. eSATA, FireWire, IBIS/HSDL, LightPeak, etc. Nov 17, 2011 at 17:14
The new data is not instantly saved to USB drive, it's stored in RAM for some time. The primary motivation of that appoarch is to gain some performance on pages repeatedly rewritten in place.
So, by unplugging unsafely you have some risk that recently written pages temporarily kept in RAM will never reach the disk.
This may affect not only data, but metadata too - entire directories may disappear, show garbage etc. It's less likely to happen on NTFS, as NTFS has transaction log for the metadata. So on NTFS you just corrupt user data in files and have metadata changes rolled back if you're unlucky on unsafe unplug.
-
4NTFS' transaction log ensures consistency of the filesystem. It does not ensure that everything you write to the volume actually gets written. Nov 15, 2011 at 21:18
-
1It works the other way too. If data if being copied to the computer form an HDD, then it may have been scheduled for delayed transfer. In that case, the data will appear on the destination drive but if the host is unplugged, the destination data will disappear. Nov 15, 2011 at 21:24
-
Also, the delay in writing to the drive tries to minimise total writes - lengthening drive lifetime. Nov 16, 2011 at 4:18
-
@CapsicumDreams: Perhaps for solid state drives that's true. Conventional magnetic storage doesn't have a write count limit. (Well at least not in the "reasonably small enough that someone might hit the limit" territory) Nov 17, 2011 at 21:17
Exactly, this is all this does. It flushes all buffers and ensures nothing can access the USB drive anymore by disconnecting it from the system.