Spinning down HDDs, troubleshooting and setting up drives

Got any great tips or tricks you're dying to share with the rest of the world? Then please post them here.
They don't have to be specifically related to building a media server but please do try to keep them suitably "geeky".
Beeblebear
Member
Member
Posts: 8
Joined: July 31st, 2012, 9:55 pm

Spinning down HDDs, troubleshooting and setting up drives

Postby Beeblebear » August 12th, 2012, 3:41 pm

Further to the Spin down idle drives in Ubuntu Server section of the main website http://www.havetheknowhow.com/Configure-the-server/Spin-down-idle-drives.html, there now follows an expanded how-to with some new information and techniques and several troubleshooting tips which have worked for others.
I have amassed quite a bit of experience in trying to get this to work on my system, so I'll share it with you here:

Note: If you have a Western Digital 'Green' HDD, you may not be able to spin this drive down, due to all of its power management features being automatically controlled by the drive itself and aggressive head-parking being used instead of Standby mode. This renders APM unavailable. I believe that has been done in order to make the drive more energy efficient in consumer electronics useage, where there is no advanced (or any) user-configurability available. This can cause problems and dramatically shorten the drive's lifespan when used in a linux box, if the user is not very careful, so I therefore chose a Hitachi drive for my server. I would definitely recommend reading up on this if you are considering using one of these popular drives in your system:
http://koitsu.wordpress.com/2012/05/30/ ... d-parking/

The first thing to do is to check if your drives will spin down:

Code: Select all

sudo hdparm -y /dev/sd[abc]

/dev/sda:
 issuing standby command

/dev/sdb:
 issuing standby command

/dev/sdc:
 issuing standby command

After 5-10 minutes, check to see if the drives are still in standby, by entering:

Code: Select all

sudo hdparm -C /dev/sd[abc]

/dev/sda:
 drive state is:  active/idle

/dev/sdb:
 drive state is:  standby

/dev/sdc:
 drive state is:  standby

If they are not in standby, then you may have a problem which will need solving before this process will work. To attempt remedy this, please check out the troubleshooting suggestions at the bottom of this section, though it is worth bearing in mind that, as in the example above, sda is very likely to be the system drive (and an SSD, in my case) and will likely not spin down anyway, no matter what you do, so it may benefit you to not even bother with this process for such drives.

Also, make sure that you check the APM settings of your drives in order to make sure that they are set up to support spinning down:

http://technomancer.me.uk/howto-hdparm- ... isk-tuning
http://www.linuxguide.it/command_line/l ... ile=hdparm
http://manpages.ubuntu.com/manpages/pre ... onf.5.html

Terminal:

Code: Select all

man hdparm

Code: Select all

[...]

-B     Get/set  Advanced  Power  Management feature, if the drive supports it. A low value
              means aggressive power management and a high value means better performance.   Posâ€�
              sible settings range from values 1 through 127 (which permit spin-down), and values
              128 through 254 (which do not permit spin-down).  The highest degree of power  manâ€�
              agement  is  attained  with  a setting of 1, and the highest I/O performance with a
              setting of 254.  A value of 255 tells hdparm to disable Advanced  Power  Management
              altogether on the drive (not all drives support disabling it, but most do).

[...]


To check if your drives support APM:

Code: Select all

sudo hdparm -B /dev/sd[abc]

/dev/sda:
 APM_level      = not supported

/dev/sdb:
 APM_level      = off

/dev/sdc:
 APM_level      = 254


Set APM mode with:

Code: Select all

sudo hdparm -B127 /dev/sd[bc]

/dev/sdb:
 setting Advanced Power Management level to 0x7f (127)
 APM_level      = 127

/dev/sdc:
 setting Advanced Power Management level to 0x7f (127)
 APM_level      = 127


It is incredibally worthwhile to have a good look at that hdparm Man Page mentioned above, as it can help you to set up your drives just as you want them.
For example, you might want to change the Acoustic Management setting for your drives, to make them as quiet as possible (this should not have a major impact on performance):

Code: Select all

sudo hdparm -M /dev/sd[abcd]

/dev/sda:
 acoustic      = not supported

/dev/sdb:
 acoustic      = not supported

/dev/sdc:
 acoustic      = not supported

/dev/sdd:
 acoustic      = 254 (128=quiet ... 254=fast)

Code: Select all

sudo hdparm -M128 /dev/sdd

/dev/sdd:
 setting acoustic management to 128
 acoustic      = 128 (128=quiet ... 254=fast)


In order to make these changes permanent (some changes are kept over reset and power-off, but not all), they need to be written to /etc/hdparm.conf. There are detailed notes commented in the file which explain the procedure and syntax, so have a good read of them before you start altering the file.

For example, the following is a direct cut and paste from hdparm.conf which lists the available options:

Code: Select all

# -q be quiet
quiet
# -a sector count for filesystem read-ahead
#read_ahead_sect = 12
# -A disable/enable the IDE drive's read-lookahead feature
#lookahead = on
# -b bus state
#bus = on
# -B apm setting
#apm = 255
# -c enable (E)IDE 32-bit I/O support - can be any of 0,1,3
#io32_support = 1
# -d disable/enable the "using_dma" flag for this drive
#dma = off
# -D enable/disable the on-drive defect management
#defect_mana = off
# -E cdrom speed
#cd_speed = 16
# -k disable/enable the "keep_settings_over_reset" flag for this drive
#keep_settings_over_reset = off
# -K disable/enable the drive's "keep_features_over_reset" flag
#keep_features_over_reset = on
# -m sector count for multiple sector I/O
#mult_sect_io = 32
# -P maximum sector count for the drive's internal prefetch mechanism
#prefetch_sect = 12
# -r read-only flag for device
#read_only = off
# -s Turn on/off power on in standby mode
# poweron_standby = off
# -S standby (spindown) timeout for the drive
#spindown_time = 24
# -u interrupt-unmask flag for the drive
#interrupt_unmask = on
# -W Disable/enable the IDE drive's write-caching feature
#write_cache = off
# -X IDE transfer mode for newer (E)IDE/ATA2 drives
#transfer_mode = 34
# -y force to immediately enter the standby mode
#standby
# -Y force to immediately enter the sleep mode
#sleep
# -Z Disable the power-saving function of certain Seagate drives
#disable_seagate
# -M Set the acoustic management properties of a drive
#acoustic_management
# -p Set the chipset PIO mode
# chipset_pio_mode
# --security-freeze Freeze the drive's security status
# security_freeze
# --security-unlock Unlock the drive's security
# security_unlock = PWD
# --security-set-pass Set security password
# security_pass = password
# --security-disable Disable drive locking
# security_disable
# --user-master Select password to use
# user-master = u
# --security-mode Set the security mode
# security_mode = h

I would recommend identifying your drives by their unique ID rather than simply using /dev/hd*# or /dev/sd*#, as device assignments can change between system boots. I had this happen to me when I left my bootable USB rescue drive plugged in. It took the sdb label and pushed the rest of my storage drives on up the alphabet. This caused me some concern before I realised what had happened.

https://help.ubuntu.com/community/UsingUUID

Code: Select all

ls -l /dev/disk/by-id

Code: Select all

total 0
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-Hitachi_HDS724040ALE640_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-MATSHITABD-MLT_UJ240AS_WJ42_003694 -> ../../sr0
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 ata-SAMSUNG_SSD_830_Series_S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-name-Server-root -> ../../dm-0
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-name-Server-swap_1 -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-name-Server-System -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdb9h3Rs23fJ2io8zxPjbpedP4eUrC3OVw -> ../../dm-2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdG5s3dBd4rFdt34hdJoyhJxB5oCw7l6RI -> ../../dm-1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 dm-uuid-LVM-Z8LZg70hTKbj7AoTEU12IP81IeP5fgLdVJQezcxe7NQVplQeVfQFMlqY4dAwq73D -> ../../dm-0
lrwxrwxrwx 1 root root  9 Aug  1 14:09 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_OCZ-NOCTI_OCZ-F412PBYMZ7MZ4E6W-part1 -> ../../sdc1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 scsi-SATA_SAMSUNG_SSD_830S0XZNEAC711934-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 14:09 wwn-0x5000cca22bc063f2 -> ../../sdb
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5000cca22bc063f2-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  9 Aug  1 14:09 wwn-0x5002538043584d30 -> ../../sda
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5002538043584d30-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5002538043584d30-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5002538043584d30-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 Aug  1 14:09 wwn-0x5e83a97edd3455aa -> ../../sdc
lrwxrwxrwx 1 root root 10 Aug  1 14:09 wwn-0x5e83a97edd3455aa-part1 -> ../../sdc1

So for the device sdb, I would choose:

/dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ

Code: Select all

sudo vim /etc/hdparm.conf


Add your devices and their hdparm options to the bottom of the file:

Code: Select all

/dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ {
        apm = 127
        keep_features_over_reset = on
        spindown_time = 242
}

AS you can see, I've opted to set Advanced Power Management to 127 as this is the setting with the highest performance which still allows spin-down, I've told the drive to keep features over reset, in order to preserve the settings on a soft restart, and spin-down delay has been set to 242 (1 hour).

I have also enabled Power On In Standby to limit instant power drain on system power-up (DO NOT use this unless your mother board supports it!), by entering in a terminal:

Code: Select all

sudo hdparm -s --yes-i-know-what-i-am-doing  /dev/disk/by-id/scsi-SATA_Hitachi_HDS7240_PK1310PAG0VMBJ

As stated above; don't do this unless you really know what you are doing! Your drive will not power up and you will therefore be unable to change this setting again unless you can connect it to a motherboard and OS which supports this feature and has it enabled in BIOS (in my BIOS, this feature is listed as 'Enable Staggered Spin-up'). Unless your system meets these criteria, your drive will, to all intents and purposes be 'bricked' upon the next restart!

Patch "/lib/hdparm/hdparm-functions" File:

For some unknown reason, the ability to set HDD parameters in /etc/hdparm.conf using ID symlinks been broken for years and although a fix has been around for almost as long (in one form or another), it has never been implemented.

https://bugs.launchpad.net/ubuntu/+sour ... bug/799312
https://launchpadlibrarian.net/73763550 ... ions.patch

In Terminal:

Code: Select all

wget https://launchpadlibrarian.net/73763550/hdparm-functions.patch
sudo patch /lib/hdparm/hdparm-functions /home/server/hdparm-functions.patch
rm /home/server/hdparm-functions.patch
sudo reboot now


Troubleshooting:
Drive still won't spin down?

After setting this all up, I found to my dismay that I still couldn't get this to work on my 4TB Hitachi drive: It simply refused to spin down unless told to do so with the hdparm -y command. To troubleshoot this issue, I set spindown_time = 24 (2 minutes) and checking APM showed that my settings in hdparm.conf were definitely being applied;

Code: Select all

sudo hdparm -B /dev/sd[abc]

/dev/sda:
 APM_level      = not supported

/dev/sdb:
 APM_level      = 127

/dev/sdc:
 APM_level      = 254

but for some reason the spindown setting was not taking. The same problem seemed to be happening to others in the following thread; viewtopic.php?f=5&t=150&start=10, but the proposed solution; viewtopic.php?p=825#p825, wouldn't work for me as Gnome-Core doesn't seem to have the "Spin down hard disks when possible" tick-box in it's power settings. The Settings dialogue is now called "Power", not "Power Management" and has only the option to set standby time. Even installing XFCE instaed of Gnome-Core as my graphical desktop environment and installing power manager with;

Code: Select all

sudo apt-get install xfce4-power-manager

lead to a dead-end, as the "Spin down hard disks when possible" tick-box was greyed out and inaccessible. Launching power manager with;

Code: Select all

sudo xfce4-power-manager
sudo xfce4-power-manager-settings

gave me the tick-box back, but this still didn't help.

The following page gives a lot of advice and excellent suggestions for solving spin-down problems:
http://info4admins.com/tips-to-spindown ... or-ubuntu/

First, I tried a solution from the comments section of that page:
http://sourceforge.net/tracker/?func=de ... tid=117457

In Webmin:

Webmin -> Webmin Configuration -> Background Status Collection

Collect system status in background? Never
Collect available package updates? Yes
Collect drive temperatures? No


I next tried stopping Samba from Webmin with: Servers -> Samba Windows File Sharing -> Stop Samba Servers

No joy.

http://ubuntuforums.org/showthread.php?t=1488614&page=2
http://smartmontools.sourceforge.net/ma ... onf.5.html
http://ubuntuforums.org/archive/index.p ... 25263.html
https://wiki.archlinux.org/index.php/S.M.A.R.T.

Next up, I tried configuring smartmontools in case the SMART daemon was preventing spin-down:

Code: Select all

sudo vim /etc/default/smartmontools

adding the line

Code: Select all

smartd_opts=”-q never -i 7200"

to the end. I then altered the settings in /etc/smartd.conf, changing the configuration line from;

Code: Select all

DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner

to;

Code: Select all

DEVICESCAN -d removable ata -n standby,q -m root -M exec /usr/share/smartmontools/smartd-runner

(Key: -d removable = treat missing drives as if they might be plugged in later,
[-d] ata = treat drives as ATA rather than SCSI etc,
-n standby = don't wake up drives in standby or sleep - just 'skip',
,q = don't log the 'skip',
-m root = email SMART error messages to root,
-M exec /.../... = send email via smartd-runner.)

Still no luck, so I tried commenting out the whole line:

Code: Select all

#DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner


The result:

Code: Select all

sudo hdparm -C /dev/sd[abc]

/dev/sda:
 drive state is:  active/idle

/dev/sdb:
 drive state is:  active/idle

/dev/sdc:
 drive state is:  active/idle


This is driving me to distraction! :x :crazy: :wtf:

Is there something I've overlooked here?
If anyone can help me to solve this problem and get this blasted drive to spin down, I'd be extremely grateful as this is the only thing left to do to get my base operating system working as I want.

EDIT:

After a lot of head-scratching, I decided to open up another computer, remove a similar drive to the Hitachi 7K4000 which is causing me problems here and try it out on this system.
The substitute drive is a Hitachi 5K3000; so I thought that it should close enough to the 4TB for comparison. The result?

Code: Select all

sudo hdparm -S24 /dev/sd[abcd]

/dev/sda:
 setting standby to 24 (2 minutes)

/dev/sdb:
 setting standby to 24 (2 minutes)

/dev/sdc:
 setting standby to 24 (2 minutes)

/dev/sdd:
 setting standby to 24 (2 minutes)

...after two minutes...

Code: Select all

sudo hdparm -C /dev/sd[abcd]

/dev/sda:
 drive state is:  standby

/dev/sdb:
 drive state is:  active/idle

/dev/sdc:
 drive state is:  standby

/dev/sdd:
 drive state is:  standby

sdb is the 7K4000;
sdd is the 5K3000;
sda and sdc are SSDs - Even they are saying that they've gone to sleep!

I've submitted a support request to Hitachi GST to see if they have got any idea about this. If I get a reply I will let you know, but I will I will re-edit this post later in order to make it a proper how-to, anyway.

Return to “Tips 'n' Tricks”