Tuesday, January 6, 2009

External HDD spindown issue

This guide shows how to automatically spindown your external hard drives connected to your NSLU2. Isn't it great to stop your external hdd when you are not using it. This will also extend the lifetime of your external hdd. I have been using this with my NTFS formatted hdd for a couple of months and I am very satisfied.
We need a program to control the harddisk connected to your NSLU2. SG3-utils will do it for us. To install write
apt-get install sg3-utils

After the installation you can try to spindown your harddrive to test if it's working.
In my case I wrote
/usr/bin/sg_start --stop /dev/sdb

If it works you are almost done. Let us automatize it now.Spindown is a daemon that spins down idle disks and so saving energy and giving the disks a longer lifetime. You can check http://code.google.com/p/spindown/ for more information. Follow the steps below to install it into your Debian machine. You may change the "spindown-0.2.2.tar.gz" parts according to the latest version.

mkdir xxx
cd xxx
wget http://spindown.googlecode.com/files/spindown-0.2.2.tar.gz
tar xvzf spindown-0.2.2.tar.gz
cd spindown-0.2.2
make install

After compiling and installing the spindown you still need to configure it. I prepared a sample config file for you. Create spindown.conf by typing
nano /etc/spindown.conf

and copy and paste the lines below into this file.

cycle-time = 60 # Number of seconds between cycles.

idle-time = 3600 # The time in seconds a disk has to be idle before it is spundown.
# Do not use a value that is to small (less than 3600) unless you
# know what you are doing.

syslog = 0 # Turn this on if you want spindown to log messages using syslog.
# You will not want to turn this on if you are trying to spindown
# the disk with the root filesystem on.

[Disk 0]
name = sdb
spindown = 1
command = sg_start --stop

You will need to change name = sdb into something else depending which drive you want to stop or you can make it stop multiple drives. Check the website I gave before for more information.

Now you have your configuration file. It is time to start the daemon, write
/etc/init.d/spindown start

when you write the line below
/etc/init.d/spindown status

you should see something like

You can change the spindown time from the config file. 3600 is fine if you do not know what you are doing. Hope this helps. Write comments if I miss something.
Good luck...


  1. Hi, thanks for your post. Can you tell me which external HDD you use?

  2. Thanks,
    I use Philips 500GB USB2.0 External Hard Drive, SP3051CC/05

  3. Just a note, doesn't appear to work with an Icy-Box.

  4. when I try to type "make" I got the following:

    g++ -O1 -pthread -c src/main.cpp
    make: g++: Command not found
    make: *** [main.o] Error 127

  5. It looks like the problem is with your c++ compiler. "make: g++: Command not found". Try to install/reinstall g++ with apt-get and try again.

  6. apt-get install g++ helped. Thanks!

  7. Thanks for the nice guides for slug fans. sg_start and spindown can use vol_id which is better than labels (sda, sdb etc) since the ids do not change but the labels do if you remove or plug in additional drives. So I set this up using id = "whaterver the drive id is" in spindown.conf.
    You can find the vol_id using
    >ls -l /dev/disk/by-id

    Doing a similar process with fstab to use UUID and not labels also (hopefully) has solved by debian NSLU2 from going awry after a while......to restore it I remove the 2 gig flashdrive (attached to slug with debian lenny install), attach to my laptop and re-dump the (saved) image onto the 2gig flash. Whew! couple of minutes later and I have backtracked to the install where it worked!
    Have you managed to suspend or hibernate the NSLU2? I want to do this and then wake it up with etherwake as needed. Problem is I am running my slug using power from a USB hub that connects to USB port2 (the debian install is on 2 gig flash on USB port 1) so I cannot even poweroff the slug! I am also confused as to which to try and get to work - pm-utils, tuxonice, hibernate sleepd or ?

  8. For the suspend and hibernation, it is the first time I heard this though :). Slug is very low power consuming but it would be even nicer to suspend it. I guess it has to be defined in the kernel first so we will be able to suspend or hibernate. At least for gentoo I have to select it from the kernel first, so I think it is the same for debian. It would be great to hear from you if you achieve it :)

  9. BTW if sg_start does not work try a few differnt options (check man page) . I have two drives attached to NSLU2 by usb hub. One is 320gig multimedia other is 80gig docs backup. These worked for me where the simple sg_start did not!

    #dev/sdb at media/slugMUSIC
    id = usb-ST332062_0A_DEF10DBBD5A9-0:0
    spindown = 1
    command = /usr/bin/sg_start 0 --pc=2

    #dev/sdc at /home/backup
    id = usb-Myson_Century__Inc._USB_Mass_Storage_Device_100
    spindown = 1
    command = /usr/bin/sg_start 0 --pc=3

    PS try different pc=? options..

  10. Thanx for help. I had a new 1tb drive for backups. Unfortunately it has autospindown feature :). Unfortunately because I wrote a script for the old drive connected and it emails me when it spins up and spins down so I can see what happens and who reaches the drive. So, it is not possible to do the mail trick for the new drive. I can't monitor the spindown status. I should find a workaround for this problem soon ...

  11. I type
    make install
    and nothing happens, no answer, no prompt, just nothing.
    Maybe I need to setup something else. I've unslugged with the most recent debian version and my NLSU2 is a 133 Mhz.

  12. at least you should have an error to diagnose. It is really hard to say something at this point but try to install

    apt-get install build-essential

    let me know what happens

  13. Thamk you. You're so right my friend! Worked like a charm. I found a post and it recommended this before anything, to set it up nicely.

    aptitude install sg3-utils build-essential

    Nos it's going. Great app!

    My slug runs with a little 2 GB mem stick and a HD enclosure with a 640 GB laptop drive. AMazing savings on time, electricity and very discreet.