14

I use Ubuntu 12.04 on a home server. There are 5 hard drives: one SSD with the OS and 4 HDDs (Samsung HD204UI) configured as a RAID5 using mdadm.

I don't need the RAID very often (say, about once per day in average); it contains multimedia data and some backups, so I decided to put the drives to standby most of the time.

I configured the drives to automatically spin-down after 20 minutes using hdparm, here /dev/sda as an example:

hdparm -S 240 /dev/sda

The output of the command confirmed this:

/dev/sdb:
 setting standby to 240 (20 minutes)

But the problem is that the drive spins down after about 5 seconds (instead 20 minutes) after the last access, and

hdparm -C /dev/sdb

displays:

/dev/sdb:
 drive state is:  standby

Why doesn't the drive wait the 20 minutes as configured? Does it have something to do with the RAID setup? (I don't think so...)

This very short timeout is problematic since it is a RAID5 and when I access a file, it is spread block-wise around the four drives. Since drive 1 isn't needed when drive 2 is read, it went asleep when it will be used the next time (after drive 3 has been read from). So the drives keep spinning up and down the whole time resulting in a throughput near zero.

For the people being concerned about the life of my drives: It will be no problem that the drives are spinned up and down once a day in average since I prefer saving energy and heat over health of the drives (I use RAID5 and the content isn't very important).

2
  • 4
    Glad you got your answer over here. Shame the ServerFault guys were so picky. I'd have thought that energy saving techniques would be pretty important in any forward-thinking enterprise scenario. Instead they'll miss out.
    – tomfanning
    May 16, 2012 at 12:02
  • 1
    @tomfanning Well, I assume that ServerFault is for large scale servers like in a datacenter only. But I didn't know, and I expected that a home server also counts as a server. Well, if not, I should put my server in my garden, so it's not in my home anymore. What I really don't understand, is why they just don't live me with what I want and only answer the question if they have constructive answers for my question but instead want me to let it be what I want to do. [for other people not knowing what we're talking about: serverfault.com/q/389222/116951]
    – leemes
    May 16, 2012 at 12:47

3 Answers 3

12

Is AHCI enabled in your BIOS? If not try turning it on and re-trying.

If that still doesn't work, then you may have to try something a bit more complicated, as hdparm doesn't always play nicely with SATA drives, which is what I presume you have.

Check out this page for the following relatively simple solution that uses crontab:

sudo apt-get install sg3-utils
crontab -e

Now, add this to the bottom of your crontab (replace sdx with the drive you wish to put in standby):

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="sdx "; if [ "$(diff /dev/shm/1 /dev/shm/2 | grep $HD )" =  "" ] ; then /usr/bin/sg_start --stop /dev/$HD; fi ) >/dev/null 2>&1

Of course, before attempting any of this, it's highly advisable to perform a full backup of the contents of your hard drives.

2
  • Worked like a charm. I enabled AHCI in BIOS. SATA mode was set to RAID (my motherboard has a RAID controller on board which I don't use). I didn't know that AHCI is needed for proper SMART control of SATA drives or whatever hdparm is doing here. Thanks!
    – leemes
    May 16, 2012 at 10:51
  • Sir @SirCharlo, what is the basic command to make hdd in standby mode (using that sg3-utils)? Is it /usr/bin/sg_start --stop /dev/sdx? Jan 6, 2017 at 1:51
1

Maybe a better way could be:

hdparm -B 1 -Y /dev/device
hdparm -B 255 /dev/device

The first hdparm put the device standby immediately. The second one turn off APM, so the disk stay in standby mode till the next disk access.

1
  • Good suggestion, though it should be stated that these commands should be used with a script that times the actions.
    – Rucent88
    Nov 23, 2016 at 11:12
0

I used a systemd unit file to set the spindown timeout to the lowest one 21m15s right after the boot. It's running only once at each boot, because it's just a temporary setting and the drive forgets it. Apart from that my RAID1 is configured as BTRFS filesystem devices and contains a 2TB Samsung 870EVO SSD and a Samsung HD204UI.

/etc/systemd/system/hdparm.service

[Unit]
Description=hdparm sleep

[Service]
Type=oneshot
ExecStart=/usr/bin/hdparm -S 255 /dev/sdb

[Install]
WantedBy=multi-user.target

https://wiki.archlinux.org/title/hdparm#Putting_a_drive_to_sleep_directly_after_boot

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .