You are on page 1of 3

blog.mymediasystem.

net

http://blog.mymediasystem.net/uncategorized/simple-way-to-spindown-a-sata-harddisk-drive-after-being-idle-linux/

How to spindown(sleep) a SATA hard disk drive after being idle (Linux) at Acmelabs' Blog
How to spindown(sleep) a SATA hard disk drive after being idle (Linux)
November 18th, 2008 by acmelab68 [UPDATE] If your BIOS supports the AHCI standard, you may try to turn it on, and try to use the hdparm -S1 /dev/sdn command again, or all the variants your distro suggests for powering down your hard disk. BUT! Read here carefully about possible complications: http://en.wikipedia.org/wiki/Advanced_Host_Controller_Interface. If you dont have such an BIOS switch or it doesnt work for you for other reasons, you may read ahead.[/UPDATE] It was easy to set an IDE(PATA) hard disk drive into standby mode. You just invoked the hdparm command with the -S switch.

hdparm -S180 /dev/hdb

e.g. sets your IDE hard disk drive into the standby mode after 15 minutes idle time, where almost no energy was consumed anymore, and for some of us more important than that, no noise was generated as well. If you wanted to make these setting persistent, youve simply wrote these rules into the The day I bought my first SATA disk, Ive almost instantly tried the /etc/hdparm.conf .

sdparm command with the same switch

-S180 . Haha, that doesnt work of course you might say now, because youve tried the same nonsense also. Then you probably also started your journey for the right command to set your drive after a certain amount of time into standby. Well I found nothing. Laptop_mode tools didnt work for me. After setting these values in the /etc/laptop-mode/laptop-mode.conf

ENABLE_LAPTOP_MODE_ON_AC=1 HD="/dev/[hs]d[bcdefgh]" CONTROL_HD_IDLE_TIMEOUT=1 NOLM_HD_IDLE_TIMEOUT_SECONDS=20

and running

"/etc/init.d/laptop-mode restart" or invoking it from the console laptop_mode I

only got a bunch of these ones:

HDIO_DRIVE_CMD failed: Input/output error

This all may of course due to the fact, that this machine is not a notebook at all, but my media server. S.M.A.R.T doesnt work for me (dont know why, and I dont intend to become a rocket scientist to understand that), and there are tons of other commands and scripts out there, which let your SATA drive sleep after being idle for some time. This e.g. is an excellent site, where likely all possible methods are described how you can let your SATA disk go into standby, but theres no hdparm -S180 . Crap, isnt it? Ive studied the

site a bit, and decided to do it completely different. Here we go (I assume youre know what youre doing and youre not new to Linux either ): This is a simple Two Steps HOWTO for Linux. This example is running on an Ubuntu 8.10 / Intrepid Ibex 1. Install sg3-utils:

apitude install sg3-utils

2. enter these 3 (blue) lines as root user into your

crontab by entering

crontab -e ... #==Acmelabs 2008 ===== Spin down SATA disks after a given idle time == 0-59/15 * * * * ( if [ ! -f /dev/shm/1 ] ; then touch /dev/shm/1 /dev/shm/2; fi ; mv /dev/shm/1 /dev/shm/2; cat /proc/diskstats > /dev/shm/1 ) >/dev/null 2>&1 0-59/15 * * * * ( export HD="sda "; if [ "$(diff /dev/shm/1 /dev/shm/2 | grep $HD )" = "" ] ; then /usr/bin/sg_start --stop /dev/$HD; fi ) >/dev/null 2>&1 save and exit the crontab editor. Thats it. Watch out, on cut and paste the lines above, they are one-liner, and there are, inlcuding the comment line, three of them. Be careful with the quotes also. Its better you type instead of cut&pasting -> learning by doing

Im personally using

export EDITOR=vi

because

nano makes me go mad as the standard editor for

crontab , but this is only a matter of taste. sda , e.g. with sdb . The

And if you like more hard drives go to sleep, just copy the last line, and replace

15 is the idle time in minutes, after which your drives should go to sleep. If you dont know the name of your drives, just perform a df command. Note: The sais /usr/share/doc/sg3-utils/README.sg_start

Be aware that the Linux SCSI subsystem at this time does not autmatically starts stopped devices, so stopping a device which is in use may have fatal results for you

I personally dont know, whether the author just wants to sound a bit dramatic, or its the plain truth, because countless hamsters have been grilled or other natural disaster hit the earth after this command has been used. Its working for me actually. But please, I wont be upset if you enlighten me bye saying: Hey, why dont you use?

You might also like