Debian hdd spindown

From NAS-Central Buffalo - The Linkstation Wiki
Revision as of 15:18, 22 June 2007 by Rosco pc (Talk)

Jump to: navigation, search

If you're not using your Kurobox 24 hours a day, it could be good to allow the hard drive to spin down and reduce noise and power usage. For this you'll need to install hdparm to tune the sleep delay, and configure syslog to prevent it from writing to the disk, causing it to wake up every 20 minutes!

Contents

Install, Test & Configure 'hdparm'

Installation

Use apt-get to install hdparm as well as any dependencies automatically:

apt-get install hdparm

Testing

You can find out what your drive's settings are by running this command:

hdparm -i /dev/hda

Typical output would be something like this:

kurobox:~# hdparm -i /dev/hda
/dev/hda:
Model=ST3320620A, FwRev=3.AAC, SerialNo=5QF06WD4
Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
BuffType=unknown, BuffSize=16384kB, MaxMultSect=16, MultSect=16
CurCHS=65535/1/63, CurSects=4128705, LBA=yes, LBAsects=268435455
IORDY=on/off, tPIO={min:240,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes:  pio0 pio1 pio2 pio3 pio4
DMA modes:  mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
AdvancedPM=no WriteCache=disabled
Drive conforms to: device does not report version:
* signifies the current active mode

You can give options to the hdparm command to either view or change specific characteristics. Look through the man page or /etc/hdparm.conf to find out what each option does. For example, changing the spindown time to 5 minutes from the command-line would be:

hdparm -S60 /dev/hda

Read through this Gentoo wiki page to find out some good options to play with in order to possibly increase your drive performance. Make sure to run this drive test both before and after in order find out whether you changes made things better or worse:

hdparm -tT /dev/hda

Configuration

Once you have found the best possible settings for your drive, edit the hdparm configuration file:

vi /etc/hdparm.conf

You can either uncomment the lines about /dev/hda at the end of the file, which would make the section look like this:

/dev/hda {
       mult_sect_io = 16
       write_cache = off
       dma = on
       spindown_time = 120
}

Add any additional options within the curly brackets for those changes to be permanent. You can also edit the options individually throughout the file (information on each option is provided as comments within the file).

One last step is to make sure hdparm runs for at least your chosen runlevel. For some reason hdparm is not set to run on runlevel 2 by default, so use this command to first remove it's rc.d entries:

update-rc.d -f hdparm remove

Then use this command to add it back to runlevel 2 (with shutdown running at reboot, shutdown, and single-user mode):

update-rc.d hdparm start 19 2 . stop 19 0 1 6 .

In the above example I've set hdparm's priority to 19 so it is before such things as NFS, Webmin, etc. You can change this to some other reasonable setting (check your /etc/rc2.d folder to find a good number).

syslogd Configuration

If you do not do that, your HDD will be turned on every 20 minutes because syslog will log a "MARK" in /var/log/messages every 20 minutes. So we need to remove that marking : edit /etc/init.d/sysklogd and set SYSLOGD to

SYSLOGD="-m 0"

exim Configuration

Exim is what the kurobox could be using as a replacement for sendmail. The problem is that it has no exim.conf file by default (which makes it write to one log file) and it wants to write to the drive every 15 minutes or so. Run this command to configure exim (which creates its configuration file):

eximconfig

I chose option(4) for local delivery only, and gave my non-root username for the recipient when asked during the questions. This process will create a file called /etc/exim/exim.conf with all the chosen configuration settings inside.

The next step is to make it so that exim doesn't try and write to logs every 15 minutes... otherwise setting up hdparm won't do us much good (depending on your setup). Edit the /etc/cron.d/exim, and change this line:

08,23,38,53 *     * * *     mail   if [ -x /usr/lib/exim/exim3 -a -f /etc/exim/exim.conf ]; then /usr/lib/exim/exim3 -q ; fi

To this:

0 * * * *     mail   if [ -x /usr/lib/exim/exim3 -a -f /etc/exim/exim.conf ]; then /usr/lib/exim/exim3 -q ; fi

This will tell cron to start the exim process only on every hour (rather than every 15 minutes or so).

Alternatively, if you don't need exim, you can disable it by putting a # at the beginning of the line in /etc/cron.d/exim :

#08,23,38,53 *     * * *     mail   if [ -x /usr/lib/exim/exim3 -a -f /etc/exim/exim.conf ]; then /usr/lib/exim/exim3 -q ; fi

If you do so, there is no need to run eximconfig.

sync Configuration

There's one thing that might prevent a spindown, `sync` and atime. Sync runs to flush the file buffer, sync is itself a file so it's atime (last access time) gets updated, which then needs to be written out to disk, repeat. This will either stop your drive from ever spinning down, or will cause it to keep spinning back up when it's otherwise idle.

This is where the mount option noatime comes in. If someone is having trouble getting their drive to spin down, try mounting your filesystem(s) with the noatime (possibly nodiratime as well) to solve this catch.

crontab Configuration

Check into /var/log/syslogd file for entries of this kind :

Apr 24 20:17:09 KURO-BOX /USR/SBIN/CRON[1133]: (root) CMD (   run-parts --report /etc/cron.hourly)

If you have some, it means that cron wakes hourly, writing to syslogd and waking up your drive. To prevent that, provided that you don't need it (check into/etc/cron.hourly for scripts to be launched hourly) , edit /etc/crontab and put a # in from of the hourly entry :

#17 *   * * *   root    run-parts --report /etc/cron.hourly

troubleshouting

Launch the KURO BOX and leave it unused for a long time (e.g. several hours). Then issue the following command (replace YYYY-MM-DD by the current date) to check which log (or other files) have been written during this time (last modified files first) :

ls -ltR /var | egrep 'var|YYYY-MM-DD'

Then look into the least recently modified files to see the last entries and try to locate what is responsible for them.