Debian Codegraph @

debian/95hdparm-apm

raw
1 #! /bin/sh
2 #
3 # This script adjusts hard drive APM settings using hdparm. The hardware
4 # defaults (usually hdparm -B 127) cause excessive head load/unload cycles
5 # on many modern hard drives. We therefore set hdparm -B 254 while on AC
6 # power. On battery we set hdparm -B 128; this still does not guarantee
7 # disk parking, but is safer than causing lots of mechanical wear on disks
8 # as we seem to get currently with 127.
9 #
10 # Refactored from acpi-support's 90-hdparm.sh for pm-utils
11
12 if grep -wq "nohdparm" /proc/cmdline ; then
13 exit 0
14 fi
15
16 # Do nothing when called via /etc/init.d/acpi-support; udev rules take care
17 # of setting the initial hdparm policy for us.
18 if ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]; then
19 exit 0
20 fi
21
22 if [ -e /usr/sbin/laptop_mode ] ; then
23 LMT_CONTROL_HD_POWERMGMT=$(. /etc/laptop-mode/laptop-mode.conf && echo "$CONTROL_HD_POWERMGMT")
24 if [ "$LMT_CONTROL_HD_POWERMGMT" != 0 ] \
25 && [ -e /var/run/laptop-mode-tools/enabled ]
26 then
27 # Laptop mode controls hdparm -B settings, we don't.
28 exit 0
29 fi
30 fi
31
32 . /usr/lib/hdparm/hdparm-functions
33
34 resume_hdparm_apm()
35 {
36 for dev in /dev/sd? /dev/hd? ; do
37 apm_opt=
38 if [ -b $dev ] && hdparm_try_apm $dev ; then
39 for option in $(hdparm_options $dev); do
40 case $option in
41 -B*)
42 apm_opt=$option
43 ;;
44 *)
45 ;;
46 esac
47 done
48 if [ -n "$apm_opt" ]; then
49 hdparm $apm_opt $dev
50 fi
51 fi
52 done
53 }
54
55 resume_hdparm_spindown()
56 {
57 for dev in /dev/sd? /dev/hd? ; do
58 # Check for force_spindown_time option
59 # If defined apply hdaprm -S even if APM is not supported
60 # See also #758988
61 ignore_apm=
62 options=$(hdparm_options $dev)
63 case $options in
64 (*'force_spindown_time'*)
65 ignore_apm='true'
66 ;;
67 esac
68 apm_opt=
69 if [ -b $dev ]; then
70 if hdparm_try_apm $dev || [ "$ignore_apm" = true ] ; then
71 for option in $(hdparm_options $dev); do
72 # Convert manually introduced option "force_spindown_time"
73 # back to "-S" understandable by hdparm
74 option=$(echo $option| sed 's/force_spindown_time/-S/')
75 case $option in
76 -S*)
77 apm_opt=$option
78 ;;
79 *)
80 ;;
81 esac
82 done
83 if [ -n "$apm_opt" ]; then
84 hdparm $apm_opt $dev
85 fi
86 fi
87 fi
88 done
89 }
90
91 case "$1" in
92 true|false) # powersaving on/off
93 resume_hdparm_apm
94 ;;
95 thaw|resume)
96 resume_hdparm_apm
97 # only set the -S option on resuming, not necessary for power.d
98 resume_hdparm_spindown
99 ;;
100 *)
101 exit 254
102 ;;
103 esac