7

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.

5
  • Most drives can be set to spin down automatically using hdparm.
    – karthick87
    Dec 28, 2010 at 8:42
  • 2
    Whatever you do, just make sure to keep an eye on the (un)load cycle count (eg. via sudo smartctl -a /dev/sda, S.M.A.R.T. value "Load Cycle Count"). Spinning the disk up and down will increase this value - a typical lifetime limit is 600,000.
    – htorque
    Dec 28, 2010 at 12:37
  • Parts of it is well described at lesswatts.org/tips/disks.php , see under headings "Use the '-' option in /etc/syslog.conf" and "hal cdrom polling" Dec 30, 2010 at 13:46
  • Please don't put answers in the comments. @j-g-faustus, I've tried all of these methods, plus some. Still seeing disk access, not sure where from.
    – cmcginty
    Jan 5, 2011 at 1:39
  • See my updated reply - you can find out where disk access is coming from, but I know of no way to make the primary disk to idle without increasing the write-back timeout. Jan 5, 2011 at 2:20

4 Answers 4

6

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.

6
  • powertop was very helpfull! It tells you what process are writing to the disk.
    – cmcginty
    Dec 28, 2010 at 21:02
  • hdparm -S and -B/apm does not work on the popular WD Green drives. I assume a lot of people have those now.
    – cmcginty
    Jan 5, 2011 at 1:34
  • if syslog is disabled or written to tmpfs volume, why can't the drive go idle?
    – cmcginty
    Jan 5, 2011 at 2:22
  • the samwell.tk link is bad, change to samwel.tk
    – cmcginty
    Jan 5, 2011 at 2:24
  • @Casey: Don't know :) but spent some time researching this for my own system about a year ago, and the consensus seems to be that many things in Linux, from kernel to drivers to standard services and programs, were never written with power or disk saving in mind. I went the increase-writeback-timeout route myself as it seemed the simplest, and my system is almost all static data - 5 sec vs several min writeback makes little to no difference. Jan 5, 2011 at 2:44
3

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
0

On my laptop I mounted /var/log to a tmpfs ram drive. That gives you far less disk writes but of course any log messages are discarded upon reboot. Something you might not want when you are running services like exim.

tmpfs /var/log tmpfs defaults,noatime,mode=1777 0 0

and in /etc/rc.local

mkdir /var/log/apt

0

mount it with noatime

more RAM also helps (bigger buffers and caches)

1
  • noatime is valid, but there are still other processes constantly accessing the disk
    – cmcginty
    Dec 29, 2010 at 0:10

You must log in to answer this question.

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