While mucking with three new Seagate FreeAgent GoFlex one terabyte external 2.5" drives, I noticed that Gnome has up to three options for what to do with a drive when you want to disconnect it. They are:
There's a brief summary of the three options in The "Unmount", "Eject" and "Safely Remove Drive" dilemma. "Unmount" I can figure out. "Eject" is obvious. OK, but what's this last one? It suggests that there is an unsafe way to remove a drive. And there is: just pull the plug on it without first unmounting any mounted partitions. That's a good way to leave the file system a mess. Don't do it.
What the last one actually does is tell the external device to spin down the drive, which implies flushing its internal buffers. In short, it does a graceful shutdown. Then it is safe to unplug and remove the drive. This becomes important with drives that get their power from the USB port, not from a separate power supply.
That sounds very nice. Except that my backup server (where I'll be using these things for offsite backups) doesn't run a GUI. In fact I run it headless and do everything by command line over SSH. So I wondered what the command line equivalent was.
Of course this is Linux: there are multiple answers. On Ubuntu 9.10 Komic Koala, the answer is devkit-disks --detach /dev/sdX, which indeed spins down and shuts off the device. Unfortunately devkit isn't available for Ubuntu 8.04.4 LTS Hardy Heron. The closest equivalent is sdparm --command=stop /dev/sdX. This will spin down but not power down the drive. But it will spin it down, and that will do for now.
One caveat for the "Safely Remove Drive" power down: this removes the device files from /dev. You have to power up the device to make them reappear.
Addendum, 2010-07-04: It appears that devkit is also not available for Ubuntu 10.4 Ludicrous Lemming, either. Use man 1 udisk instead. Great. E.g.:
udisks --detach /dev/sdb
Addendum, 2010-06-16: There is another sdparm command that is useful here, to tell the drive to flush its cache out to the platter(s). So to shut down an external drive on Hungry Hippo, use:
# flush the caches and spin down. Once DeviceKit is available, use # "devkit-disks --detach $device" sdparm --command=sync $device > /dev/null sdparm --command=stop $device > /dev/null