CarmaBlog

Agility, Java programming, New technologies and more…
  • rss
  • Home
  • Management
  • Agile Programming
  • Technology
  • Linux
  • Event
  • Contact
  • About the author
  • English
  • Francais

How to properly eject an external hard drive with Ubuntu?

Fabian Piau | Tuesday June 23rd, 2009 - 03:02 PM
914 views
  • Twitter
  • Facebook
  • Google +1
  • LinkedIn

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.

Notification

Notification

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
Fdisk - before plug in

Fdisk - before plug in

Fdisk - after plug in

Fdisk - after plug in


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.

Launchers

Launchers

My Book icon             Passport icon

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.

Related posts

Laptop's batteryExtend your laptop’s battery life
Comments
No Comments »
Categories
Linux
Tags
bash, unmount, hard drive, eject, script, ubuntu
Comments rss Comments rss
Page 1 of 11

Language

  • Français
  • English

Most viewed posts

  • Changing the language in Firefox - 18,877 views
  • Java EE & CDI vs. Spring - 10,085 views
  • Customizing Gnome 3 (Shell) - 8,211 views
  • Firefox Nightly, Aurora, Beta, Desktop, Mobile, ESR & Co. - 6,006 views
  • WordPress plugins of CarmaBlog - 5,376 views
  • Open Street Map, better map than Google Maps? - 3,139 views
  • This file is currently used, you cannot do anything… Thanks you Windows ! - 2,911 views
  • Belbin – Team Role Theory - 2,394 views
  • Using Google Docs to create an online survey - 2,056 views
  • Changing the Eclipse splash screen in few seconds - 2,017 views

Tags

training windows 7 blog agile c# ebook firefox docjax extreme programming jug nosql wave eclipse tool unmount automation sharing itil jquery script cloud wordpress nantes continuous integration extension tdd build plugin ci windows seven hard drive chrome best practices mongodb fosdem unit test documents search engine agility java configuration management ubuntu eject bash shortcut hibernate test .net google mobile computing watin

Recent Posts

  • Get the opportunity to start a course about Gamification Tuesday April 2nd, 2013
  • Comparing NoSQL: Couchbase & MongoDB Friday March 8th, 2013
  • IconFinder, find efficiently your icons Friday March 1st, 2013
  • Fosdem 2013 Impressions Wednesday February 20th, 2013
  • Fosdem, a truly open conference Monday January 28th, 2013
  • Free online MongoDB training Tuesday January 1st, 2013
  • Discover Maxthon Tuesday December 11th, 2012
  • Shutdown, standby or hibernate your computer? Sunday December 9th, 2012
  • A mobile version of your WordPress Blog Sunday October 28th, 2012
  • Using Google Docs to create an online survey Monday September 24th, 2012
  • Open Street Map, better map than Google Maps? Wednesday July 25th, 2012
  • First steps with Apache Camel Friday May 11th, 2012
  • This file is currently used, you cannot do anything… Thanks you Windows ! Sunday April 22nd, 2012
  • Customizing Gnome 3 (Shell) Thursday March 15th, 2012
  • Give your application a facelift – CSS Wednesday February 15th, 2012

RSS feeds

RSS Feed RSS - Posts

RSS Feed RSS - Comments

Email Subscription

Enter your email address to receive notifications of new posts.

Links

  • Agile Nantes
  • Blog Ippon Technologies
  • Blog Netapsys
  • Blog Xebia France
  • Blog Zenika
  • Coursera
  • Developpef
  • Le Touilleur Express
  • Les Cast Codeurs Podcast
  • new Blog( perso );
  • OCTO talks !
  • The Coder's Breakfast

Follow me!

Follow me on TwitterFollow me on LinkedInFollow me on Google+Follow me on About.meFollow me on SlideShare

Categories

  • Event (9)
  • Linux (3)
  • Management (4)
  • Agile programming (11)
  • Technology (26)

Archives

  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (1)
  • January 2013 (2)
  • December 2012 (2)
  • October 2012 (1)
  • September 2012 (1)
  • July 2012 (1)
  • May 2012 (1)
  • April 2012 (1)
  • March 2012 (1)
  • February 2012 (1)
  • January 2012 (2)
  • December 2011 (1)
  • November 2011 (2)
  • October 2011 (2)
  • September 2011 (1)
  • July 2011 (1)
  • June 2011 (2)
  • April 2011 (1)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • November 2010 (2)
  • September 2010 (1)
  • August 2010 (1)
  • July 2010 (1)
  • June 2010 (1)
  • May 2010 (1)
  • April 2010 (1)
  • March 2010 (1)
  • February 2010 (1)
  • December 2009 (1)
  • November 2009 (1)
  • October 2009 (2)
  • September 2009 (2)
  • August 2009 (3)
  • July 2009 (1)
  • June 2009 (2)
rss Comments rss get firefox
Fabian Piau | Copyright © 2009 - 2013
All Rights Reserved | Top ↑