Raspberry Pi hard drive spin down, sleep with hd-idle and hdparm

By | January 25, 2016
  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

I’ve been meaning to write this tutorial, if you could call it that, for quite some time now. I don’t actually have any hard drives connected to my Raspberry Pi at the moment, but I did have hard drives connected to it a few months ago, 2 different drives, one in a USB 2.0 enclosure, and another in a USB 3.0 enclosure. I fiddled around for quite a bit trying to get them to go to sleep, to spin down, when not in use and I think that I managed to find 2 methods that will be able to put every portable hard drive to sleep regardless of the SATA to USB chip used in the enclosure.

Raspberry Pi hard drive spin down – ultimate guide

What exactly it is that you need in order to spin down and put to sleep a hard drive connected to a Raspberry Pi are two programs. I’m mentioning two of them because if one doesn’t work, odds are good that the other one will. The two programs that I’m using are called hd-idle and hdparm. With my USB 3.0 hard drive enclosure I needed to use hd-idle in order to get the drive to go to sleep. A USB 2.0 hard drive enclosure needed hdparm. Let’s see how exactly it is that these two work.

Raspberry Pi hard drive spin down with hd-idle

First up is hd-idle, which like I said I used to spin down a SATA hard drive in my USB 3.0 enclosure. hd-idle does not come installed by default in Raspbian, in fact it’s not even available in the repositories. You will need to install it yourself by opening up the hd-idle homepage over here and following the install instructions. They’re pretty straightforward, so there’s no need for me to repeat them over here.

raspberry pi hard drive hdd spin down sleep hd idle

After installation is complete, you will need to add a launch command to /etc/rc.local for hd-idle. This command will launch hd-idle every time that Raspberry starts. Trick is to tweak settings for when you want the hard drive to go to sleep, after how many minutes, well actually seconds.

1
hd-idle -i 0 -a sda -i 300 -l /var/log/hd-idle.log

This is the command that I used in my setup. There are modifiers after the command that you need to set. -i modifier sets a global sleep timer for all drives in seconds. Value 0 turns off global idle. I’ve set this so that I can set hard drive specific sleep timers only. -a modifier is for declaring specific hard drive idle time. That’s why it’s followed right away by the -i modifier with the value of 300 which means that sda will go to sleep after 5 minutes of inactivity and it did. -l modifier activates logging, obviously. Read more about all the modifiers on the hd-idle website.

Rapsberry Pi hard drive spin down with hdparm

I’m not entirely sure if Raspberry comes with hdparm pre-installed, but it’s definitly available in the repositories, so if its not available out of the box you can install it easily with this command:

1
sudo apt-get install hdparm

Once that hdparm is installed, you’re gonna have to find out which command modifier works for your hard drive, similarly to what we did with hd-idle.

raspberry pi hard drive hdd spin down sleep hdparm

This was now with my USB 2.0 enclosure. Hd-idle didn’t work with it, so I tried with hdparm and voila, it did work. Command for putting a hard drive to sleep is shorter here. It uses -B modifier which sets a different Power Management behavior for the declared hard drive.

1
hdparm -B127 /dev/sda

It’s a bit more complicated to explain, but you can read more about it over here. Now there are other hdparm modifiers that you can use. -S for example is the one that’s supposed to be used for setting a hard drive to sleep, but it didn’t work with my USB 2.0 enclosure. You’ll have to experiment here a bit in order to see what exactly will work for you.

Final thoughts

This text is a bit rough around the edges. Okay, it’s rough around the edges a lot, but its aim is not to serve you everything on a silver platter. A lot of it boils down to do a trial/error type of approach when it comes to getting your hard drive to sleep on Raspberry Pi. If you encounter problems, explain yourself in the comment section and I’ll try to help out if I can.

3 thoughts on “Raspberry Pi hard drive spin down, sleep with hd-idle and hdparm

  1. Ediddy Wii

    Thanks, Zoran, for writing this article. In working with armbian’s debian desktop release of jessie v3.4 kernel on a Banana Pi (original, not pro or plus or M2/3), I had to install debhelper and cvs to compile.

    In attempting the ?packaging? process, “dpkg-buildpackage -rfakeroot” I had success after removing the -rfakeroot option.

    Hope these details help someone.

    Reply

Leave a Reply