How to properly eject an external hard drive with Ubuntu?
Fabian Piau | Tuesday June 23rd, 2009 - 03:02 PMLatest versions of Ubuntu now properly eject hard drives by stopping the disk rotation. So you should not have to follow the steps described in this article.
I have two Western Digital external hard drives: a Passport and a My Book model. I don’t want to do any advertisement here, but the following tip has been adapted to these models.
Thus, you will need to slightly modify the scripts for your own hard drive.
Hard drives are fully recognized by Ubuntu (mounting & unmounting). But, when I unmount one of them, disk is still in activity (spinning). And, when I disconnect my drive, I heard a clicking sound related to an aggressive head parking.
On the long run, these hard shutdowns will ultimately reduce the longevity of the hard disk.
This issue does not appear with Windows XP. In Windows, when using the “safely remove hardware”, the disk stops spinning, even though the drive keeps getting electricity from the USB cable, as a light on the drive stays on.
To remedy this problem with Ubuntu, here is the script to unmount and spin-down the hard drive. Please take note that scripts are differents depending on the kind of power supply.
If your device is powered by an external power adapter
(WD My Book model)
#!/bin/bash WD=/dev/sdc1 # unmount gksudo "umount $WD" # spin down gksudo "hdparm -Y $WD" # message echo message:Your WD My Book hard drive can be safely removed now. | zenity --notification --listen --window-icon="info" | zenity --notification --window-icon="info" --text="Your WD My Book hard drive can be safely removed now."
“/dev/sdc1” is the mount point of your drive.
Line 9 is not necessary. It uses the notification system to notify the user he can safely unplug the device.
To help you, the following is the command showing all the assigned mount points. Watch before and after plugging your hard drive. Thus, you will see easily which mount point is used by your device.
sudo fdisk -l
If your device is powered by the USB port itself
(WD Passport model)
#!/bin/bash cd /sys/bus/usb/devices good_usb=$(grep -H Western usb?/?-?/manufacturer | cut -d"/" -f1,2) cd ${good_usb}/power gksudo "sh -c 'echo "suspend" > level'" echo message:Your WD Passport hard drive can be safely removed now. | zenity --notification --listen --window-icon="info" | zenity --notification --window-icon="info" --text="Your WD Passport hard drive can be safely removed now."
I have created one launcher (shortcut) for each script in the gnome panel. That’s very user-friendly with these icons.
As a precaution, during the execution, you will be asked for your root password (sudo).
Last resort Tip
One last thing, in case the device still seems to be spinning even after the script tells you it’s safe to unplug. It is really a “system D” tip. Sometimes, I continue to use this solution when Windows stubbornly refuses to eject my WD Passport (50% time…)
Trick is to gradually unplug the hard drive very slowly. You can feel there are two steps: a first one where spinning stops (like at the end of the script), and a second one where hard drive is shutting down.
Recent Comments