How do you limit root partition disk access to allow drive to go into standby mode?

When there are no users on my system, I would like the hard disk to spindown to low-power state. I realize that this might not be 100% achievable for a straight 24 hours, but it seems reasonable that the system could remain idle for a few hours at a time when it is not in use.

My system is headless and running a limited number of services. The primary services are: exim4, mythtv-backend, nfs, samba, cups, apt-cacher-ng

Assume that drives are already enabled to go into standby mode. Also, its not acceptable to increase the write-back timeout, since my system is not on a UPS.


Solution 1:

hdparm lets you set the spindown time for a drive (how long period of inactivity before the disk goes to standby mode) or put it in standby or to sleep.

# set spindown time for sda drive to 1 min
sudo hdparm -S 12 /dev/sda 
# set sdb drive to standby mode
sudo hdparm -y /dev/sdb
# put sdc drive to sleep
sudo hdparm -Y /dev/sdc
# check drive state (active/standby/sleeping)
sudo hdpam -C /dev/sdc

/etc/hdparm.conf contains hdparm commands to run automatically at bootup. Here's a snippet from mine:

/dev/sda {
  # apm 127: Highest performance that allows spindown
  apm = 127
  # spindown 120 = 10 min 
  spindown_time = 120
}

Not all commands work on all hard drive models, you need to experiment.

laptop-mode works for non-laptops too, it is meant to let the disk(s) sleep as much as possible.

PowerTOP is a utility for tracking down unnecessary background activity.

lesswatts.org has a number of tips on harddrive spindown.

write-back timeout: To the best of my knowledge it is not possible to have the primary disk go idle without a) increasing the write-back timeout and b) disabling syslog sync.

A workaround could perhaps be to have an SSD as the root disk, as they are fairly low on power anyway?

tracking activity: It is possible to debug where disk access is coming from according to the laptop-mode FAQ - see 5 Spinup Debugging.

Quote:

My disk spins up all the time and I have no clue what causes this. Can I debug this?

Yes, you can. But first, check that you have modified your syslog.conf to not sync, as described in the last question of the previous section. To debug disk activity, you can do:

echo 1 > /proc/sys/vm/block_dump

(Warning: you must disable syslogd before you do this, or you must make sure that kernel output is not logged. If you forget this, your system may get into a feedback loop, where syslogd causes disk activity, this causes kernel output, and this causes syslogd to do more disk activity, etcetera!)

This enables file/disk activity debugging in the kernel. You can read the output using dmesg. When you're done, disable block dump using

echo 0 > /proc/sys/vm/block_dump

disabling syslogd sync: The laptop-mode FAQ and lesswatts.org refer to /etc/syslog.conf.

In recent Ubuntu this file does not exist, instead look for /etc/rsyslog.d/*.conf.

The syntax is the same - prepend every log file with a dash, like this:

kern.*              -/var/log/kern.log

This turns off syncing for the syslog deamon, meaning that the logs will be written to disk at dirty_writeback_centisecs intervals (every 5 sec by default) instead of every time there is new log entry.

Solution 2:

If you have sufficient RAM you can move temporary filesystems to memory, using tmpfs. Edit /etc/fstab and add:

tmpfs       /tmp        tmpfs   defaults    0   0
tmpfs       /var/run        tmpfs   defaults    0   0
tmpfs       /var/lock       tmpfs   defaults    0   0