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?

  • 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 0:09

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.

| improve this answer | |
  • 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 linux.die.net/man/8/sync – ott-- Mar 30 '13 at 21:11

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.

| improve this answer | |

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.