summaryrefslogtreecommitdiff
path: root/pm/power.d/harddrive
blob: 4bad394e9e1307dba66bc254ed23913547c45368 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/sh

[ -x /sbin/hdparm ] || exit $NA

# Default values on AC
DRIVE_SPINDOWN_VALUE_AC="${DRIVE_SPINDOWN_VALUE_AC:-0}"
DRIVE_WRITE_CACHE_AC="${DRIVE_WRITE_CACHE_AC:-1}" 
DRIVE_POWER_MGMT_AC="${DRIVE_POWER_MGMT_AC:-254}"
DRIVE_ACOUSTIC_MGMT_AC="${DRIVE_ACOUSTIC_MGMT_AC:-0}"

# Default values on battery
DRIVE_SPINDOWN_VALUE_BAT="${DRIVE_SPINDOWN_VALUE_BAT:-6}"
DRIVE_WRITE_CACHE_BAT="${DRIVE_WRITE_CACHE_BAT:-0}" 
DRIVE_POWER_MGMT_BAT="${DRIVE_POWER_MGMT_BAT:-1}"
DRIVE_ACOUSTIC_MGMT_BAT="${DRIVE_ACOUSTIC_MGMT_BAT:-254}"

# Default devices to operate on
DRIVE_LIST="/dev/[hs]d[a-z]"

help() {
cat <<EOF
Hard drive Parameters we support tweaking:

Drive spindown:
DRIVE_SPINDOWN_VALUE_AC = time until a drive will spin down on AC
Defaults to 0, which disables drive spindown.

DRIVE_SPINDOWN_VALUE_BAT = time until a drive will spin down on battery
Defaults to 6, which will spin the drive down after 30 seconds of inactivity.

See the -S option on the hdparm manpage.

Drive write caching:
DRIVE_WRITE_CACHE_AC  = 0 disables write cache, 1 enables it.
Defaults to 1

DRIVE_WRITE_CACHE_BAT  = 0 disables write cache, 1 enables it.
Defaults to 0

See the -W option on the hdparm man page.

Drive power management:
DRIVE_POWER_MGMT_AC = Drive Advanced Power Management value on AC
Defaults to 254 for max performance.

DRIVE_POWER_MGMT_BAT = Drive Advanced Power Management value on battery
Defaults to 1 for max power savings.

See the -B option on the hdparm man page

Drive acoustic management:
DRIVE_ACOUSTIC_MGMT_AC = Drive Acoustic Management value on AC
Defaults to 254 for max head speed.

DRIVE_ACOUSTIC_MGMT_BAT = Drive Acoustic Management value on battery
Defaults to 128 for max quietness.

See the -M option on the hdparm man page. 

Drives to manage:
DRIVE_LIST = the list of hard drives to manage.
Defaults to "/dev/[hs]d[a-z]", which will manage up to the first 25 drives.

EOF
}

harddrive_ac () {
    for dev in $DRIVE_LIST; do
	# disable write caching, do not spin down the drive, disable APM 
	# and acoustic management, and sync everything to drive.
	hdparm -W $DRIVE_WRITE_CACHE_AC \
	    -S $DRIVE_SPINDOWN_VALUE_AC \
	    -B $DRIVE_POWER_MGMT_AC \
	    -M $DRIVE_ACOUSTIC_MGMT_AC $dev
    done
}

harddrive_battery() {
    for dev in $DRIVE_LIST; do
	# disable write caching, enable acoustic management
	hdparm -W $DRIVE_WRITE_CACHE_BAT \
	    -S $DRIVE_SPINDOWN_VALUE_BAT \
	    -B $DRIVE_POWER_MGMT_BAT \
	    -M $DRIVE_ACOUSTIC_MGMT_BAT -F $dev
    done
}

case $1 in
    true) harddrive_battery ;;
    false) harddrive_ac ;;
    help) help;;
    *) exit $NA ;;
esac

exit 0