5

In Windows, there's an option to "safely remove hardware".

Ignoring the fact that it almost always fails, and that most of the time I simply have to plug the device out, I get the initiative behind it (not completely though).

So, when using Debian, when is it "safe" (i.e. not damaging to any party) to remove my external HDD?

After it has been unmounted (Xfce seems to use the term "ejected" but I guess that's the same thing)? Or simply when there are no programs using the disk?

jcora
  • 3,884
  • 7
  • 36
  • 54
  • 3
    "Safely remove" on Windows has almost always worked for me; it may be worthwhile to figure out what the problem is on your computer. – Izkata Mar 31 '13 at 00:09

3 Answers3

6

It is 'safe' to remove an external drive when it is unmounted.

The reason it might not be safe simply if programs aren't using it is that the Linux kernel does write caching. Meaning that when a program has written to disk, that data might not physically be on the disk, it could still be in memory (unless the program uses fsync or fdatasync). Linux does this to perform the disk writes in large chunks which optimizes throughput.

When you unmount a filesystem, it makes sure that no further writes are able to be performed to the disk. It also performs a sync call which ensures that all cached data is flushed out to disk.

phemmer
  • 71,831
  • 1
    Might be worth mentioning that you can also manually issue sync to make sure the buffers are flushed before removing the drive... – jasonwryan Mar 30 '13 at 20:05
  • 3
    @jasonwryan When sync returns to the shell prompt, there's still no garantee that all data have been written. See http://linux.die.net/man/8/sync – ott-- Mar 30 '13 at 21:11
2

You have to unmount it before disconnecting it. Some interfaces will use the term "eject", which should do the same thing.

How much damage is done if you disconnect without unmouting/ejecting depends on the filesystem, hardware, and caches in use. The effect is basically the same as losing power, which means most file systems are designed to recover from such situations, but there are no guarantees, and filesystem check will usually be necessary for file systems native to unix-like OSes. So the only time removing is safe under Linux is after an unmount/eject is complete.

depquid
  • 3,891
2

I have two Seagate external 2TB "Expansion Desktop Drives" mounted via USB3. After backing up my system using rsync, even after a sync and umount.crypt, the drives continue moving the heads for quite some time after the umount - 30 seconds to a minute perhaps (based on what I can feel when I put my hand on the drive). I presume this may be due to some internal caching by the external drive. I don't feel safe unplugging them until I can no longer feel any head movement.

I suspect I need to turn off the drive's write cache. My drive is normally /dev/sdg, so when ever I use the drive I could issue the following command as root:

hdparm -W0 /dev/sdg

but I haven't verified that this solves the problem.