This page is about configuring the hard disk power management on a Raspberry Pi, to be used as NAS and mediacenter. The hard disk is connected via a SupTronics X835 shield. See the main index at Home Mediacenter and NAS with the Raspberry Pi.
There are two tools to manage SATA disks in GNU/Linux. smartctl is designed to interact with the S.M.A.R.T. capabilities of a disk. hdparm is a command line interface to the Linux kernel SATA subsystem, including Advanced Power Management.
The smartctl tool from the smartmontools package requires the -d sat option to access the hard disk through the USB bridge with the right protocol.
See all the S.M.A.R.T. data of the drive:
smartctl -d sat -a /dev/sda
To enable the smartd service I had to configure the /etc/smartd.conf:
# Disable DEVICESCAN, which does not work in our environment. #DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner # Use the suggedested subset of checks, instead of the '-a'. # NOTICE: We are running smartd with option --interval=3600 instead of the # 1800 default, i.e. device polling occurs every 1 our instead of 30 minutes. # The number of skipped checks (option -n) must be multipled by that value # to obtain the maximum time that checks will be skipped: # 336 * 3600 seconds = 14 days. /dev/sda -d sat \ -H \ # Check the health with the SMART RETURN STATUS command -l selftest \ # Report increasing number of failed Self-Test -l error \ # Report increasing errors number in the Summary SMART error log -f \ # Check for 'failure' of any Usage Attributes -n standby,336 \ # Skip smartd checks during standby (max 336 times, add ',q' for quiet) -W 0,50,60 \ # Temperature (SMART att. 194): WARN=50 (log), CRIT=60 (mail) -s S/../../1/23 \ # Schedule a short Self-Test at 23:00 of every monday. -s O/../.././21 \ # Schedule an Offline Immediate Test every day at 21:00. -m root@localhost \ # Send a warning email on failures and errors -M daily \ # Repeat email warnings daily -M test # Send an email test on daemon start
The smartd daemon has a default device polling cycle of 30 minutes, we want to increase this interval otherwise the disk will never reach an inactivity period longer than that. Edit the /etc/default/smartmontools file and set:
smartd_opts="--interval=3600"
Restart the smartd.service and verify that the smartd program is running with that paramter (3600 seconds, i.e. one hour, instead of 30 minutes).
At each cycle, all the -s options are check for a match, the first match will be executed and the remaining are ignored.
The syntax for the -s option (test scheduling) is as follow:
-s T/MM/DD/d/HH | | | | | | | | | | | | | | \-- Hour of day, 2 digits | | | \----- Day of week, 1 is Monday | | \------- Day of the month, 2 digits | \---------- Month, 2 digits \------------- (L)ong Self-Test, (S)hort Self-Test, (C)onveyance Self-Test, (O)ffline Immediate Test
We should use the background test mode, which does not interrupt normal disk activity.
-A
and -l error
options respectively.If you want to display the log e.g. of self-test executed, run:
smartctl -d sat -l selftest /dev/sda
The output is something like this:
=== START OF READ SMART DATA SECTION === SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error # 1 Short offline Completed without error 00% 525 - # 2 Short offline Completed without error 00% 377 - # 3 Short offline Completed without error 00% 252 - # 4 Conveyance offline Completed without error 00% 252 -
To set the Advanced Power Management level use the -B option, the maximum performance level which permits spin-down of the drive is 127:
hdparm -B 127 /dev/sda
Regardless of the APM level, we can set the hard disk Standby timer (spindown) after 30 minutes of inactivity. See man hdparm for explanation of the number following the -S option (the granularity of the timer up to 20 minutes is 5 seconds, above that threshold it is 30 minutes). It seems that there is not way to know the timeout once you have set it.
hdparm -S 241 /dev/sda
WARNING: If both APM and the Standby timer are set, then the device shall go to the Standby state when the timer expires or the device’s APM algorithm indicates that the Standby state should be entered. If you want a time exact spin-down, use the -S Standby timer, because APM algorithm (including its spin-down timeout) is device dependant and you cannot control it. See p.19 of ATA/ATAPI Command Set - 2 (ACS-2).
Enable the most quiet acoustic management (it is not supported in my case: 4 Tb Seagate IronWolf):
hdparm -M 128 /dev/sda
Debian provides the file /etc/hdparm.conf which is handled by the udev on system start to set the required parameters. You can set something like this:
# Enable hard disk standby (spin-down) timeout at 30 minutes. # It is advisable to disable write cache in this case. # See man hdparm(8), -S and -W options. # The granularity of the spindown_time up to 20 minutes is 5 # seconds, above that threshold it is 30 minutes. /dev/sda { write_cache = off spindown_time = 241 }
To enforce the setting immediately, you can execute:
DEVNAME=/dev/sda /lib/udev/hdparm
Check whether the drive is in standby mode, without waking it up:
smartctl -d sat --nocheck=standby,3 /dev/sda
The meaning of standby,3 is: do not check the disk if it is in SLEEP or STANDBY mode (not spinning), return exit code 3 in this case (you can choose your custom exit code). Beside the exit code, these are the output messages:
Device is in ACTIVE or IDLE mode
Device is in STANDBY mode, exit(3)
WARNING: Reading SMART attributes using the smartctl command will reset the Standby timer, even if using the --nocheck=standby option; i.e. that option will prevent exiting from the standby mode, but if smartctl
is executed when standby is not yet active, it will reset the timer and this may prevent entering the standby mode, regardless of that option.
WARNING: When smartctl report the device being in ACTIVE or IDLE mode, the disk may be actually not spinning.
Beware that there are several activities which may awake the driver from its stanby status, among that there are: