23
# ... and many others that I've stopped
20
# Based on a script for Linux 2.4 written by Jens Axboe
26
# Based on a script for Linux 2.4 written by Jens Axboe.
22
28
#############################################################################
26
if [ "$1" == "defaults" -o "$1" == "readconfig" ] ; then
27
# This special option is used from multiple scripts to set the config defaults
28
# and to read the configuration on top of those.
30
ENABLE_LAPTOP_MODE_ON_BATTERY=1
31
ENABLE_LAPTOP_MODE_ON_AC=0
32
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=0
34
LM_BATT_MAX_LOST_WORK_SECONDS=600
35
LM_AC_MAX_LOST_WORK_SECONDS=360
41
CONTROL_HD_IDLE_TIMEOUT=1
42
LM_AC_HD_IDLE_TIMEOUT=1 # 5 seconds
43
LM_BATT_HD_IDLE_TIMEOUT=1 # 5 seconds
44
NOLM_HD_IDLE_TIMEOUT=244 # 2 hours
47
DEF_XFS_SYNC_INTERVAL=30
48
DEF_XFS_BUFD_INTERVAL=1
50
MINIMUM_BATTERY_MINUTES=7
51
CONTROL_MOUNT_OPTIONS=1
53
LM_AC_HD_POWERMGMT=255
54
NOLM_AC_HD_POWERMGMT=255
55
CONTROL_HD_POWERMGMT=0
56
CONTROL_HD_WRITECACHE=1
57
NOLM_AC_HD_WRITECACHE=1
58
NOLM_BATT_HD_WRITECACHE=0
60
ACPI_WITHOUT_AC_EVENTS=0
62
LM_DIRTY_BACKGROUND_RATIO=1
63
NOLM_DIRTY_BACKGROUND_RATIO=10
65
LM_SECONDS_BEFORE_SYNC=2
66
BATT_CPU_MAXFREQ=fastest
67
BATT_CPU_MINFREQ=slowest
68
BATT_CPU_GOVENOR=conservative
69
LM_AC_CPU_MAXFREQ=fastest
70
LM_AC_CPU_MINFREQ=slowest
71
LM_AC_CPU_GOVERNOR=ondemand
72
NOLM_AC_CPU_MAXFREQ=fastest
73
NOLM_AC_CPU_MINFREQ=slowest
74
NOLM_AC_CPU_GOVERNOR=performance
75
CONTROL_CPU_FREQUENCY=0
76
HD="/dev/[hs]d[abcdefgh]"
78
LM_AC_SYSLOG_CONF=/etc/syslog-on-ac-with-lm.conf
79
NOLM_AC_SYSLOG_CONF=/etc/syslog-on-ac-without-lm.conf
80
BATT_SYSLOG_CONF=/etc/syslog-on-battery.conf
81
SYSLOG_CONF_SIGNAL_PROGRAM=syslogd
82
SYSLOG_CONF=/etc/syslog.conf
83
CONTROL_DPMS_STANDBY=0
85
LM_AC_DPMS_STANDBY=1200
86
NOLM_DPMS_STANDBY=1200
87
CONTROL_CPU_THROTTLING=0
88
BATT_CPU_THROTTLING=medium
89
LM_AC_CPU_THROTTLING=minimum
90
NOLM_AC_CPU_THROTTLING=minimum
93
# Backward compatibility variable that is sometimes
94
# set externally (Debian init system)
98
if [ -r /etc/laptop-mode/laptop-mode.conf ] ; then
99
. /etc/laptop-mode/laptop-mode.conf
101
echo $0: Configuration file /etc/laptop-mode/laptop-mode.conf not present or not readable.
105
# Support for old config settings
106
if [ "$AC_HD" != "" ] ; then
107
AC_HD_WITHOUT_LM="$AC_HD"
108
AC_HD_WITH_LM="$AC_HD"
110
if [ "$VERBOSE" != "" ] ; then
111
VERBOSE_OUTPUT="$VERBOSE"
113
if [ "$CPU_MAXFREQ" != "" ] ; then
114
BATT_CPU_MAXFREQ="$CPU_MAXFREQ"
116
if [ "$MAX_AGE" != "" ] ; then
117
LM_BATT_MAX_LOST_WORK_SECONDS="$MAX_AGE"
118
LM_AC_MAX_LOST_WORK_SECONDS="$MAX_AGE"
120
if [ "$DEF_AGE" != "" ] ; then
121
DEF_MAX_AGE="$DEF_AGE"
123
if [ "$LAPTOP_MODE_ALWAYS_ON" != "" ] ; then
124
ENABLE_LAPTOP_MODE_ALWAYS="$LAPTOP_MODE_ALWAYS_ON"
126
if [ "$LM_WHEN_LID_CLOSED" != "" ] ; then
127
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED="$LM_WHEN_LID_CLOSED"
129
if [ "$REMOUNT_PARTITIONS" != "" ] ; then
130
PARTITIONS="$REMOUNT_PARTITIONS"
132
if [ "$READAHEAD" != "" ] ; then
133
LM_READAHEAD="$READAHEAD"
135
if [ "$DO_REMOUNT_NOATIME" != "" ] ; then
136
CONTROL_NOATIME="$DO_REMOUNT_NOATIME"
138
if [ "$DO_HD" != "" ] ; then
139
CONTROL_HD_IDLE_TIMEOUT="$DO_HD"
141
if [ "$AC_HD_WITH_LM" != "" ] ; then
142
LM_AC_HD_IDLE_TIMEOUT="$AC_HD_WITH_LM"
144
if [ "$AC_HD_WITHOUT_LM" != "" ] ; then
145
NOLM_HD_IDLE_TIMEOUT="$AC_HD_WITHOUT_LM"
147
if [ "$BATT_HD" != "" ] ; then
148
LM_BATT_HD_IDLE_TIMEOUT="$BATT_HD"
150
if [ "$DO_REMOUNTS" != "" ] ; then
151
CONTROL_MOUNT_OPTIONS="$DO_REMOUNTS"
153
if [ "$DO_HD_POWERMGMT" != "" ] ; then
154
CONTROL_HD_POWERMGMT="$DO_HD_POWERMGMT"
156
if [ "$AC_HDPARM_POWERMGMT_WITH_LM" != "" ] ; then
157
LM_AC_HD_POWERMGMT="$AC_HDPARM_POWERMGMT_WITH_LM"
159
if [ "$AC_HDPARM_POWERMGMT_WITHOUT_LM" != "" ] ; then
160
NOLM_AC_HD_POWERMGMT="$AC_HDPARM_POWERMGMT_WITHOUT_LM"
162
if [ "$BATT_HDPARM_POWERMGMT" != "" ] ; then
163
BATT_HD_POWERMGMT="$BATT_HDPARM_POWERMGMT"
165
if [ "$DO_WRITECACHE" != "" ] ; then
166
CONTROL_HD_WRITECACHE="$DO_WRITECACHE"
168
if [ "$AC_WRITECACHE_WITHOUT_LM" != "" ] ; then
169
NOLM_AC_HD_WRITECACHE="$AC_WRITECACHE_WITHOUT_LM"
171
if [ "$BATT_WRITECACHE" != "" ] ; then
172
LM_HD_WRITECACHE="$BATT_WRITECACHE"
174
if [ "$DIRTY_RATIO" != "" ]; then
175
LM_DIRTY_RATIO="$DIRTY_RATIO"
177
if [ "$DIRTY_BACKGROUND_RATIO" != "" ] ; then
178
LM_DIRTY_BACKGROUND_RATIO="$DIRTY_BACKGROUND_RATIO"
180
if [ "$DEF_DIRTY_RATIO" != "" ]; then
181
NOLM_DIRTY_RATIO="$DEF_DIRTY_RATIO"
183
if [ "$DEF_DIRTY_BACKGROUND_RATIO" != "" ] ; then
184
NOLM_DIRTY_BACKGROUND_RATIO="$DEF_DIRTY_BACKGROUND_RATIO"
186
if [ "$DO_CPU" != "" ] ; then
187
CONTROL_CPU_FREQUENCY="$DO_CPU"
189
if [ "$CONTROL_CPU_MAXFREQ" != "" ] ; then
190
CONTROL_CPU_FREQUENCY="$CONTROL_CPU_MAXFREQ"
192
if [ "$AC_CPU_MAXFREQ_WITH_LM" != "" ] ; then
193
LM_AC_CPU_MAXFREQ="$AC_CPU_MAXFREQ_WITH_LM"
195
if [ "$AC_CPU_MAXFREQ_WITHOUT_LM" != "" ] ; then
196
NOLM_AC_CPU_MAXFREQ="$AC_CPU_MAXFREQ_WITHOUT_LM"
198
if [ "$DO_SYSLOG" != "" ] ; then
199
CONTROL_SYSLOG_CONF="$DO_SYSLOG"
201
if [ "$SYSLOG_SIGNAL_PROGRAM" != "" ] ;then
202
SYSLOG_CONF_SIGNAL_PROGRAM="$SYSLOG_SIGNAL_PROGRAM"
204
if [ "$AC_SYSLOG_WITH_LM" != "" ] ; then
205
LM_AC_SYSLOG_CONF="$AC_SYSLOG_WITH_LM"
207
if [ "$AC_SYSLOG_WITHOUT_LM" != "" ] ; then
208
NOLM_AC_SYSLOG_CONF="$AC_SYSLOG_WITHOUT_LM"
210
if [ "$BATT_SYSLOG" != "" ] ; then
211
BATT_SYSLOG_CONF="$BATT_SYSLOG"
213
if [ "$ENABLE_LAPTOP_MODE_ALWAYS" != "" ] ; then
214
ENABLE_LAPTOP_MODE_ON_AC="$ENABLE_LAPTOP_MODE_ALWAYS"
218
if [ "$VERBOSE_OUTPUT" -ne 0 ] ; then
224
if [ "$PARTITIONS" == "" ] ; then
228
# Convert seconds to hdparm -S format
229
# Everything over 20 minutes is interpreted as 2 hours.
230
seconds_to_hdparm_S() {
231
if [ "$1" -eq 0 ] ; then
234
elif [ "$1" -gt 0 -a "$1" -lt 5 ] ; then
237
elif [ "$1" -le $((240*5)) ] ; then
238
# Values between 1 and 240 signify increments of 5 seconds
240
elif [ "$1" -lt $((30*60)) ] ; then
241
# Values between 20 and 30 minutes are rounded up to 30 minutes.
243
elif [ "$1" -lt $((12*30*60)) ] ; then
244
# Values between 30 minutes and 6 hours (exclusive) yield values between
245
# 241 and 251, in 30-minute increments.
246
echo $(( 240 + ($1 / (30*60)) ))
248
# Larger values effectively indicate no timeout at all.
253
# Convert configured idle timeouts to hdparm -S format.
254
if [ "$LM_AC_HD_IDLE_TIMEOUT_SECONDS" != "" ] ; then
255
LM_AC_HD_IDLE_TIMEOUT=$(seconds_to_hdparm_S $LM_AC_HD_IDLE_TIMEOUT_SECONDS)
257
if [ "$LM_BATT_HD_IDLE_TIMEOUT_SECONDS" != "" ] ; then
258
LM_BATT_HD_IDLE_TIMEOUT=$(seconds_to_hdparm_S $LM_BATT_HD_IDLE_TIMEOUT_SECONDS)
260
if [ "$NOLM_HD_IDLE_TIMEOUT_SECONDS" != "" ] ; then
261
NOLM_HD_IDLE_TIMEOUT=$(seconds_to_hdparm_S $NOLM_HD_IDLE_TIMEOUT_SECONDS)
264
elif [ "$1" == "status" ] ; then
30
# The laptop mode tools version number. Extracted by the installer makefile
31
# as well, so don't change the format!
34
# This script is loaded from multiple scripts to set the config defaults
35
# and to read the configuration on top of those. Only when the command is
36
# recognized does this script do anything else.
38
ENABLE_LAPTOP_MODE_ON_BATTERY=1
39
ENABLE_LAPTOP_MODE_ON_AC=0
40
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED=0
41
PARTITIONS="auto /dev/mapper/*"
42
LM_BATT_MAX_LOST_WORK_SECONDS=600
43
LM_AC_MAX_LOST_WORK_SECONDS=360
49
CONTROL_HD_IDLE_TIMEOUT=1
50
LM_AC_HD_IDLE_TIMEOUT=1 # 5 seconds
51
LM_BATT_HD_IDLE_TIMEOUT=1 # 5 seconds
52
NOLM_HD_IDLE_TIMEOUT=244 # 2 hours
55
DEF_XFS_SYNC_INTERVAL=30
56
DEF_XFS_BUFD_INTERVAL=1
58
CONTROL_MOUNT_OPTIONS=1
60
LM_AC_HD_POWERMGMT=255
61
NOLM_AC_HD_POWERMGMT=255
62
CONTROL_HD_POWERMGMT=0
63
CONTROL_HD_WRITECACHE=0
64
NOLM_AC_HD_WRITECACHE=1
65
NOLM_BATT_HD_WRITECACHE=0
68
LM_DIRTY_BACKGROUND_RATIO=1
69
NOLM_DIRTY_BACKGROUND_RATIO=10
71
LM_SECONDS_BEFORE_SYNC=2
72
BATT_CPU_MAXFREQ=medium
73
BATT_CPU_MINFREQ=slowest
74
BATT_CPU_GOVERNOR=ondemand
75
LM_AC_CPU_MAXFREQ=fastest
76
LM_AC_CPU_MINFREQ=slowest
77
LM_AC_CPU_GOVERNOR=ondemand
78
NOLM_AC_CPU_MAXFREQ=fastest
79
NOLM_AC_CPU_MINFREQ=slowest
80
NOLM_AC_CPU_GOVERNOR=performance
81
CONTROL_CPU_FREQUENCY=0
82
HD="/dev/[hs]d[abcdefgh]"
84
LM_AC_SYSLOG_CONF=/etc/syslog-on-ac-with-lm.conf
85
NOLM_AC_SYSLOG_CONF=/etc/syslog-on-ac-without-lm.conf
86
BATT_SYSLOG_CONF=/etc/syslog-on-battery.conf
87
SYSLOG_CONF_SIGNAL_PROGRAM=syslogd
88
SYSLOG_CONF=/etc/syslog.conf
89
CONTROL_DPMS_STANDBY=0
91
LM_AC_DPMS_STANDBY=1200
92
NOLM_AC_DPMS_STANDBY=1200
93
CONTROL_CPU_THROTTLING=0
94
BATT_CPU_THROTTLING=medium
95
LM_AC_CPU_THROTTLING=minimum
96
NOLM_AC_CPU_THROTTLING=minimum
99
BATT_TERMINAL_BLANK_MINUTES=2
100
BATT_TERMINAL_POWERDOWN_MINUTES=1
101
LM_AC_TERMINAL_BLANK_MINUTES=10
102
LM_AC_TERMINAL_BLANK_MINUTES=10
103
NOLM_AC_TERMINAL_POWERDOWN_MINUTES=10
104
NOLM_AC_TERMINAL_POWERDOWN_MINUTES=50
105
ENABLE_AUTO_HIBERNATION=0
106
HIBERNATE_COMMAND=/usr/sbin/hibernate
107
AUTO_HIBERNATION_ON_CRITICAL_BATTERY_LEVEL=1
108
DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL=1
109
AUTO_HIBERNATION_BATTERY_CHARGE_MAH=0
110
AUTO_HIBERNATION_BATTERY_CHARGE_MWH=0
111
MINIMUM_BATTERY_CHARGE_MAH=0
112
MINIMUM_BATTERY_CHARGE_MWH=0
113
ASSUME_SCSI_IS_SATA=1
115
# No default on these ones -- we need to detect if they have been set, for
116
# backward compatibility with MINIMUM_BATTERY_MINUTES etc.
117
AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT=
118
MINIMUM_BATTERY_CHARGE_PERCENT=
120
# Backward compatibility variable that is sometimes
121
# set externally (Debian init system)
125
if [ -r /etc/laptop-mode/laptop-mode.conf ] ; then
126
. /etc/laptop-mode/laptop-mode.conf
128
echo $0: Configuration file /etc/laptop-mode/laptop-mode.conf not present or not readable.
132
# Support for old config settings
133
if [ "$AC_HD" != "" ] ; then
134
AC_HD_WITHOUT_LM="$AC_HD"
135
AC_HD_WITH_LM="$AC_HD"
137
if [ "$VERBOSE" != "" ] ; then
138
VERBOSE_OUTPUT="$VERBOSE"
140
if [ "$CPU_MAXFREQ" != "" ] ; then
141
BATT_CPU_MAXFREQ="$CPU_MAXFREQ"
143
if [ "$MAX_AGE" != "" ] ; then
144
LM_BATT_MAX_LOST_WORK_SECONDS="$MAX_AGE"
145
LM_AC_MAX_LOST_WORK_SECONDS="$MAX_AGE"
147
if [ "$DEF_AGE" != "" ] ; then
148
DEF_MAX_AGE="$DEF_AGE"
150
if [ "$LAPTOP_MODE_ALWAYS_ON" != "" ] ; then
151
ENABLE_LAPTOP_MODE_ALWAYS="$LAPTOP_MODE_ALWAYS_ON"
153
if [ "$LM_WHEN_LID_CLOSED" != "" ] ; then
154
ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED="$LM_WHEN_LID_CLOSED"
156
if [ "$REMOUNT_PARTITIONS" != "" ] ; then
157
PARTITIONS="$REMOUNT_PARTITIONS"
159
if [ "$READAHEAD" != "" ] ; then
160
LM_READAHEAD="$READAHEAD"
162
if [ "$DO_REMOUNT_NOATIME" != "" ] ; then
163
CONTROL_NOATIME="$DO_REMOUNT_NOATIME"
165
if [ "$DO_HD" != "" ] ; then
166
CONTROL_HD_IDLE_TIMEOUT="$DO_HD"
168
if [ "$AC_HD_WITH_LM" != "" ] ; then
169
LM_AC_HD_IDLE_TIMEOUT="$AC_HD_WITH_LM"
171
if [ "$AC_HD_WITHOUT_LM" != "" ] ; then
172
NOLM_HD_IDLE_TIMEOUT="$AC_HD_WITHOUT_LM"
174
if [ "$BATT_HD" != "" ] ; then
175
LM_BATT_HD_IDLE_TIMEOUT="$BATT_HD"
177
if [ "$DO_REMOUNTS" != "" ] ; then
178
CONTROL_MOUNT_OPTIONS="$DO_REMOUNTS"
180
if [ "$DO_HD_POWERMGMT" != "" ] ; then
181
CONTROL_HD_POWERMGMT="$DO_HD_POWERMGMT"
183
if [ "$AC_HDPARM_POWERMGMT_WITH_LM" != "" ] ; then
184
LM_AC_HD_POWERMGMT="$AC_HDPARM_POWERMGMT_WITH_LM"
186
if [ "$AC_HDPARM_POWERMGMT_WITHOUT_LM" != "" ] ; then
187
NOLM_AC_HD_POWERMGMT="$AC_HDPARM_POWERMGMT_WITHOUT_LM"
189
if [ "$BATT_HDPARM_POWERMGMT" != "" ] ; then
190
BATT_HD_POWERMGMT="$BATT_HDPARM_POWERMGMT"
192
if [ "$DO_WRITECACHE" != "" ] ; then
193
CONTROL_HD_WRITECACHE="$DO_WRITECACHE"
195
if [ "$AC_WRITECACHE_WITHOUT_LM" != "" ] ; then
196
NOLM_AC_HD_WRITECACHE="$AC_WRITECACHE_WITHOUT_LM"
198
if [ "$BATT_WRITECACHE" != "" ] ; then
199
LM_HD_WRITECACHE="$BATT_WRITECACHE"
201
if [ "$DIRTY_RATIO" != "" ]; then
202
LM_DIRTY_RATIO="$DIRTY_RATIO"
204
if [ "$DIRTY_BACKGROUND_RATIO" != "" ] ; then
205
LM_DIRTY_BACKGROUND_RATIO="$DIRTY_BACKGROUND_RATIO"
207
if [ "$DEF_DIRTY_RATIO" != "" ]; then
208
NOLM_DIRTY_RATIO="$DEF_DIRTY_RATIO"
210
if [ "$DEF_DIRTY_BACKGROUND_RATIO" != "" ] ; then
211
NOLM_DIRTY_BACKGROUND_RATIO="$DEF_DIRTY_BACKGROUND_RATIO"
213
if [ "$DO_CPU" != "" ] ; then
214
CONTROL_CPU_FREQUENCY="$DO_CPU"
216
if [ "$CONTROL_CPU_MAXFREQ" != "" ] ; then
217
CONTROL_CPU_FREQUENCY="$CONTROL_CPU_MAXFREQ"
219
if [ "$AC_CPU_MAXFREQ_WITH_LM" != "" ] ; then
220
LM_AC_CPU_MAXFREQ="$AC_CPU_MAXFREQ_WITH_LM"
222
if [ "$AC_CPU_MAXFREQ_WITHOUT_LM" != "" ] ; then
223
NOLM_AC_CPU_MAXFREQ="$AC_CPU_MAXFREQ_WITHOUT_LM"
225
if [ "$DO_SYSLOG" != "" ] ; then
226
CONTROL_SYSLOG_CONF="$DO_SYSLOG"
228
if [ "$SYSLOG_SIGNAL_PROGRAM" != "" ] ;then
229
SYSLOG_CONF_SIGNAL_PROGRAM="$SYSLOG_SIGNAL_PROGRAM"
231
if [ "$AC_SYSLOG_WITH_LM" != "" ] ; then
232
LM_AC_SYSLOG_CONF="$AC_SYSLOG_WITH_LM"
234
if [ "$AC_SYSLOG_WITHOUT_LM" != "" ] ; then
235
NOLM_AC_SYSLOG_CONF="$AC_SYSLOG_WITHOUT_LM"
237
if [ "$BATT_SYSLOG" != "" ] ; then
238
BATT_SYSLOG_CONF="$BATT_SYSLOG"
240
if [ "$ENABLE_LAPTOP_MODE_ALWAYS" != "" ] ; then
241
ENABLE_LAPTOP_MODE_ON_AC="$ENABLE_LAPTOP_MODE_ALWAYS"
243
if [ "$MINIMUM_BATTERY_MINUTES" != "" -a "$MINIMUM_BATTERY_CHARGE_PERCENT" == "" ] ; then
244
# Use a very conservative estimate (1% = 1 battery minute, 100 minutes in a battery)
245
# for backward compatibility.
246
MINIMUM_BATTERY_CHARGE_PERCENT="$MINIMUM_BATTERY_MINUTES"
248
if [ -z "$MINIMUM_BATTERY_CHARGE_PERCENT" ] ; then
249
# Apply the default, now that we've determined that this is the minimum.
250
MINIMUM_BATTERY_CHARGE_PERCENT=3
252
if [ "$AUTO_HIBERNATION_BATTERY_MINUTES" != "" -a "$AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT" == "" ] ; then
253
# Use a very conservative estimate (1% = 1 battery minute, 100 minutes in a battery)
254
# for backward compatibility.
255
AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT="$AUTO_HIBERNATION_BATTERY_MINUTES"
257
if [ -z "$AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT" ] ; then
258
# Apply the default, now that we've determined that this is the minimum.
259
AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT=2
264
if [ "$VERBOSE_OUTPUT" -ne 0 ] ; then
270
if [ "$PARTITIONS" == "" ] ; then
271
PARTITIONS="auto /dev/mapper/*"
274
# Convert seconds to hdparm -S format
275
# Everything over 20 minutes is interpreted as 2 hours.
276
seconds_to_hdparm_S() {
277
if [ "$1" -eq 0 ] ; then
280
elif [ "$1" -gt 0 -a "$1" -lt 5 ] ; then
283
elif [ "$1" -le $((240*5)) ] ; then
284
# Values between 1 and 240 signify increments of 5 seconds
286
elif [ "$1" -lt $((30*60)) ] ; then
287
# Values between 20 and 30 minutes are rounded up to 30 minutes.
289
elif [ "$1" -lt $((12*30*60)) ] ; then
290
# Values between 30 minutes and 6 hours (exclusive) yield values between
291
# 241 and 251, in 30-minute increments.
292
echo $(( 240 + ($1 / (30*60)) ))
294
# Larger values effectively indicate no timeout at all.
299
# Convert configured idle timeouts to hdparm -S format.
300
if [ "$LM_AC_HD_IDLE_TIMEOUT_SECONDS" != "" ] ; then
301
LM_AC_HD_IDLE_TIMEOUT=$(seconds_to_hdparm_S $LM_AC_HD_IDLE_TIMEOUT_SECONDS)
303
if [ "$LM_BATT_HD_IDLE_TIMEOUT_SECONDS" != "" ] ; then
304
LM_BATT_HD_IDLE_TIMEOUT=$(seconds_to_hdparm_S $LM_BATT_HD_IDLE_TIMEOUT_SECONDS)
306
if [ "$NOLM_HD_IDLE_TIMEOUT_SECONDS" != "" ] ; then
307
NOLM_HD_IDLE_TIMEOUT=$(seconds_to_hdparm_S $NOLM_HD_IDLE_TIMEOUT_SECONDS)
310
if [ "$1" == "status" ] ; then
268
311
# Display a status report.
270
313
mount | sed "s/^/ /"
475
536
elif [ -f /proc/pmu/info ] ; then
476
537
if ( grep "^AC Power.*0$" /proc/pmu/info ) ; then
477
echo "/proc/pmu/info indicates absence of AC power." > $OUTPUT
538
echo "/proc/pmu/info indicates absence of AC power." >> $OUTPUT
480
541
# It is possible that there is no AC Power = 1 in the file,
481
542
# but we always assume AC power when we're not sure.
483
echo "/proc/pmu/info indicates presence of AC power." > $OUTPUT
486
echo "No ACPI, APM or PMU power management information found -- assuming AC power is present." > $OUTPUT
490
if [ "$ACTION" == "auto" ] ; then
491
if [ "$ON_AC" -eq 1 ] ; then
492
if [ "$ENABLE_LAPTOP_MODE_ON_AC" -ne 0 ] ; then
493
echo "On AC power: Setting action to \"start\" because ENABLE_LAPTOP_MODE_ON_AC is set." > $OUTPUT
496
echo "On AC power: Setting action to \"stop\" because ENABLE_LAPTOP_MODE_ON_AC is not set." > $OUTPUT
500
if [ "$ENABLE_LAPTOP_MODE_ON_BATTERY" -ne 0 ] ; then
501
echo "On battery power: Setting action to \"start\" because ENABLE_LAPTOP_MODE_ON_BATTERY is set." > $OUTPUT
504
echo "On battery power: Setting action to \"stop\" because ENABLE_LAPTOP_MODE_ON_BATTERY is not set." > $OUTPUT
509
if [ "$ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED" -ne 0 ] ; then
510
if [ -f /proc/acpi/button/lid/*/state ] ; then
511
if ( cat /proc/acpi/button/lid/*/state | grep "closed" ) ; then
512
echo "Setting action to \"start\" because the lid is closed." > $OUTPUT
516
echo "Warning: ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED is set, but there is no /proc/acpi/button/lid!"
544
echo "/proc/pmu/info indicates presence of AC power." >> $OUTPUT
547
echo "No ACPI, APM or PMU power management information found -- assuming AC power is present." >> $OUTPUT
552
# Determine whether to activate or deactivate laptop mode.
555
if [ "$ON_AC" -eq 1 ] ; then
556
if [ "$ENABLE_LAPTOP_MODE_ON_AC" -ne 0 ] ; then
557
echo "On AC power: Activating, because ENABLE_LAPTOP_MODE_ON_AC is set." >> $OUTPUT
560
echo "On AC power: Deactivating, because ENABLE_LAPTOP_MODE_ON_AC is not set." >> $OUTPUT
564
if [ "$ENABLE_LAPTOP_MODE_ON_BATTERY" -ne 0 ] ; then
565
echo "On battery power: Activating, because ENABLE_LAPTOP_MODE_ON_BATTERY is set." >> $OUTPUT
568
echo "On battery power: Deactivating, because ENABLE_LAPTOP_MODE_ON_BATTERY is not set." >> $OUTPUT
573
if [ "$ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED" -ne 0 ] ; then
574
if [ -f /proc/acpi/button/lid/*/state ] ; then
575
if ( cat /proc/acpi/button/lid/*/state | grep "closed" ) ; then
576
echo "Setting action to \"start\" because the lid is closed." >> $OUTPUT
580
echo "Warning: ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED is set, but there is no file"
581
echo "/proc/acpi/button/lid/.../state!"
521
585
# If the init script has not been run or has been run with the "stop"
522
586
# argument, then we should never start laptop mode.
523
587
if [ ! -f /var/run/laptop-mode-enabled ] ; then
524
echo "Laptop mode disabled because /var/run/laptop-mode-enabled is missing." > $OUTPUT
588
echo "Laptop mode disabled because /var/run/laptop-mode-enabled is missing." >> $OUTPUT
529
if [ "$ACTION" = start -a -f /etc/default/laptop-mode ] ; then
592
if [ "$ACTIVATE" -eq 1 -a -f /etc/default/laptop-mode ] ; then
530
593
. /etc/default/laptop-mode
531
594
if ! ( echo "$ENABLE_LAPTOP_MODE" |grep y ) ; then
532
echo "Not starting laptop mode because it is disabled in /etc/default/laptop-mode." > $OUTPUT
595
echo "Not starting laptop mode because it is disabled in /etc/default/laptop-mode." >> $OUTPUT
538
FULLSTATE=$ACTION,$ON_AC
600
if [ "$STATE" == "disabled" ] ; then
604
# Check whether we are allowed to activate the data-loss-sensitive stuff.
605
# If the battery charge is too low, we want to disable this, but not the
606
# other power-saving stuff.
608
if [ "$ACTIVATE" -eq 0 ] ; then
609
ACTIVATE_WITH_POSSIBLE_DATA_LOSS=0
611
ACTIVATE_WITH_POSSIBLE_DATA_LOSS=1
612
if [ ! -d /proc/acpi ] ; then
613
echo "Not ACPI -> no support for minimum battery charge checking." >> $OUTPUT
614
elif [ "$ON_AC" -eq 0 ] ; then
615
echo "On ACPI and not on AC -- checking minimum battery charge." >> $OUTPUT
617
ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=0
618
for BATT in /proc/acpi/battery/* ; do
619
PREV_ENOUGH_CHARGE=$ENOUGH_CHARGE
620
PREV_ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=$ENOUGH_CHARGE_TO_PREVENT_HIBERNATION
622
BATT_STATE=$BATT/state
624
echo "Checking info and state for $BATT." >> $OUTPUT
626
# Only do if the battery is present
627
if ( cat $BATT_INFO | grep "present:.*yes" > /dev/null ) ; then
628
FOUND_AN_ENABLED_CHECK=0
629
FOUND_AN_ENABLED_HIBERNATION_CHECK=0
631
# Get the remaining capacity.
632
REMAINING=`cat $BATT_STATE | grep "remaining capacity:" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
633
if [ -z "$REMAINING" ] ; then
634
echo "Battery does not report remaining capacity. Perhaps it is not present?" >> $OUTPUT
637
echo "Remaining charge: $REMAINING" >> $OUTPUT
639
CAPACITY=`cat $BATT_INFO | grep "design capacity:" | sed "s/.* \([0-9][0-9]* \).*/\1/" `
640
if [ -z "$CAPACITY" ] ; then
643
echo "Design capacity: $CAPACITY" >> $OUTPUT
645
# Check the charge percentage
646
if [ "$MINIMUM_BATTERY_CHARGE_PERCENT" -ne 0 ] ; then
647
FOUND_AN_ENABLED_CHECK=1
648
if [ "$CAPACITY" -eq 0 ] ; then
649
echo "WARNING: Battery does not report a design capacity. Minimum battery"
650
echo "charge checking does not work without a design capacity."
651
elif [ "$(($REMAINING * 100 / $CAPACITY))" -ge "$MINIMUM_BATTERY_CHARGE_PERCENT" ] ; then
655
if [ "$AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT" -ne 0 ] ; then
656
FOUND_AN_ENABLED_HIBERNATION_CHECK=1
657
if [ "$CAPACITY" -eq 0 ] ; then
658
echo "WARNING: Battery does not report a design capacity. Auto hibernation"
659
echo "does not work without a design capacity."
660
elif [ "$(($REMAINING * 100 / $CAPACITY))" -ge "$AUTO_HIBERNATION_BATTERY_CHARGE_PERCENT" ] ; then
661
ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=1
666
# Fallback: hard values.
668
# Determine the reporting unit.
671
if ( cat $BATT_INFO | grep mWh > /dev/null ) ; then
673
elif ( cat $BATT_INFO | grep mAh > /dev/null ) ; then
677
if [ "$IN_MAH" -ne 0 ] ; then
678
if [ "$MINIMUM_BATTERY_CHARGE_MAH" -ne 0 ] ; then
679
FOUND_AN_ENABLED_CHECK=1
680
if [ "$REMAINING" -ge "$MINIMUM_BATTERY_CHARGE_MAH" ] ; then
684
if [ "$AUTO_HIBERNATION_BATTERY_CHARGE_MAH" -ne 0 ] ; then
685
FOUND_AN_ENABLED_HIBERNATION_CHECK=1
686
if [ "$REMAINING" -ge "$AUTO_HIBERNATION_BATTERY_CHARGE_MAH" ] ; then
687
ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=1
690
elif [ "$IN_MWH" -ne 0 ] ; then
691
if [ "$MINIMUM_BATTERY_CHARGE_MWH" -ne 0 ] ; then
692
FOUND_AN_ENABLED_CHECK=1
693
if [ "$REMAINING" -ge "$MINIMUM_BATTERY_CHARGE_MWH" ] ; then
697
if [ "$AUTO_HIBERNATION_BATTERY_CHARGE_MWH" -ne 0 ] ; then
698
FOUND_AN_ENABLED_HIBERNATION_CHECK=1
699
if [ "$REMAINING" -ge "$AUTO_HIBERNATION_BATTERY_CHARGE_MWH" ] ; then
700
ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=1
704
echo "Failed to determine battery charge. Battery charge units are not in"
708
CAP_STATE=`cat "$BATT_STATE" | sed -r 's/^capacity state:\s*(.*)\s*$/\1/;t;d'`
709
if [ "$DISABLE_LAPTOP_MODE_ON_CRITICAL_BATTERY_LEVEL" -ne 0 ] ; then
710
if [ "$CAP_STATE" == "critical" ] ; then
711
# Restore the state we had before checking this battery, so that
712
# this battery does not count as having enough charge.
713
ENOUGH_CHARGE=$PREV_ENOUGH_CHARGE
714
elif [ "$FOUND_AN_ENABLED_CHECK" -eq 0 ] ; then
715
# This is the only check that is enabled. In that case a non-critical
716
# battery level counts as "enough". (If we would count non-critical
717
# battery levels as enough *always*, then the other settings would
718
# have no effect; this is only a final fallback.)
722
if [ "$AUTO_HIBERNATION_ON_CRITICAL_BATTERY_LEVEL" -ne 0 ] ; then
723
if [ "$CAP_STATE" == "critical" ] ; then
724
ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=$PREV_ENOUGH_CHARGE_TO_PREVENT_HIBERNATION
725
elif [ "$FOUND_AN_ENABLED_HIBERNATION_CHECK" -eq 0 ] ; then
726
ENOUGH_CHARGE_TO_PREVENT_HIBERNATION=1
730
echo "Battery is not present." >> $OUTPUT
733
if [ "$ENABLE_AUTO_HIBERNATION" -ne 0 -a "$ENOUGH_CHARGE_TO_PREVENT_HIBERNATION" -eq 0 ] ; then
734
echo "None of the batteries have a charge above the auto-hibernation level." >> $OUTPUT
735
echo "Starting hibernation." >> $OUTPUT
737
# Don't continue -- if things are configured correctly, then we
738
# will be called on resume.
741
if [ "$ENOUGH_CHARGE" -eq 0 ] ; then
742
echo "None of the batteries have a charge above the minimum level." >> $OUTPUT
743
echo "Deactivating data loss sensitive features." >> $OUTPUT
744
ACTIVATE_WITH_POSSIBLE_DATA_LOSS=0
749
if [ "$INIT" -eq 0 ] ; then
750
echo -n "Laptop mode "
753
# WAS_ACTIVE is used later on. If there is no /var/run/laptop-mode-state, then
754
# we know that laptop mode wasn't active before.
540
echo Checking if desired state is different from current state. > $OUTPUT
756
echo Checking if desired state is different from current state. >> $OUTPUT
541
757
if [ -f /var/run/laptop-mode-state ] ; then
542
read PREVFULLSTATE < /var/run/laptop-mode-state
543
if [ "$PREVFULLSTATE" == "start,0" -o "$PREVFULLSTATE" == "start,1" ] ; then
546
if [ "$PREVFULLSTATE" == "$FULLSTATE" ] ; then
548
if [ "$WAS_ACTIVE" -eq 1 ] ; then
549
echo "active [unchanged]."
551
echo "not active [unchanged]."
758
read WAS_ACTIVE WAS_ON_AC WAS_ACTIVATE_WITH_POSSIBLE_DATA_LOSS < /var/run/laptop-mode-state
759
if [ "$WAS_ON_AC" != "" ] ; then
760
if [ "$WAS_ACTIVE" -eq "$ACTIVATE" -a "$WAS_ON_AC" -eq "$ON_AC" -a "$WAS_ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -eq "$ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -a "$FORCE" -eq 0 ] ; then
762
if [ "$WAS_ACTIVE" -eq 1 ] ; then
763
echo -n "active [unchanged]."
764
if [ "$ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -eq 0 ] ; then
765
echo -n ' (Data-loss sensitive features disabled.)'
769
echo "not active [unchanged]."
556
echo "/var/run/laptop-mode-state does not exist, no previous state." > $OUTPUT
558
echo $FULLSTATE > /var/run/laptop-mode-state
560
if [ "$INIT" -eq 0 ] ; then
561
echo -n "Laptop mode "
774
echo "/var/run/laptop-mode-state in pre-1.20 format, ignoring previous state." >> $OUTPUT
778
echo "/var/run/laptop-mode-state does not exist, no previous state." >> $OUTPUT
780
echo $ACTIVATE $ON_AC $ACTIVATE_WITH_POSSIBLE_DATA_LOSS > /var/run/laptop-mode-state
782
if [ "$ACTIVATE" -eq 1 ] ; then
783
echo -n "$STATE, active."
784
if [ "$ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -eq 0 ] ; then
785
echo -n ' (Data-loss sensitive features disabled.)'
789
echo "$STATE, not active."
565
794
# Adjust CPU speed first -- that way, response to a switch to AC power will be faster,
566
795
# while switching to battery will take place while we're taking less power on the whole.
800
# Get the medium value from a list of numerical values.
801
# $1 = file containing the list of values
804
cat "$1" | sed 's/ /\n/g' | sort -n | awk -v RS="" '{n=split($0,a); print a[int((n+1)/2)]}'
807
# Set kernel setting, showing an error if this fails.
808
# Parameter 1: sysctl/proc path
809
# Parameter 2: the value
811
echo "Executing: echo $2 > $1" >> $OUTPUT
812
if ! echo "$2" > "$1" ; then
813
echo "SETTING OF KERNEL PARAMETER FAILED: echo $2 \> $1"
568
817
if [ $CONTROL_CPU_FREQUENCY -eq 1 ] ; then
569
818
if [ $ON_AC -eq 1 ] ; then
570
if [ "$ACTION" = "start" ] ; then
819
if [ "$ACTIVATE" -eq 1 ] ; then
571
820
CPU_MAXFREQ="$LM_AC_CPU_MAXFREQ"
572
821
CPU_MINFREQ="$LM_AC_CPU_MINFREQ"
573
822
CPU_GOVERNOR="$LM_AC_CPU_GOVERNOR"
652
# Take MAX_LOST_WORK_SECONDS from LM_BATT_MAX_LOST_WORK_SECONDS or LM_AC_MAX_LOST_WORK_SECONDS_WITH_LM, depending on power state.
653
MAX_LOST_WORK_SECONDS=$LM_BATT_MAX_LOST_WORK_SECONDS
654
if [ $ON_AC -eq 1 -a "$ACTION" = "start" ] ; then
655
MAX_LOST_WORK_SECONDS=$LM_AC_MAX_LOST_WORK_SECONDS
658
AGE=$((100*$MAX_LOST_WORK_SECONDS))
659
XFS_AGE=$(($XFS_HZ*$MAX_LOST_WORK_SECONDS))
660
echo -n "$STATE, active"
662
if [ -d /proc/sys/vm/pagebuf ] ; then
663
# (For 2.4 and early 2.6.)
664
# This only needs to be set, not reset -- it is only used when
665
# laptop mode is enabled.
666
echo "Adjusting XFS kernel parameters for 2.4 and early 2.6 kernels." > $OUTPUT
667
echo $XFS_AGE > /proc/sys/vm/pagebuf/lm_flush_age
668
echo $XFS_AGE > /proc/sys/fs/xfs/lm_sync_interval
669
elif [ -f /proc/sys/fs/xfs/lm_age_buffer ] ; then
670
# (A couple of early 2.6 laptop mode patches had these.)
671
# This only needs to be set, not reset -- it is only used when
672
# laptop mode is enabled.
673
echo "Adjusting XFS kernel parameters for early patched 2.6 kernels." > $OUTPUT
674
echo $XFS_AGE > /proc/sys/fs/xfs/lm_age_buffer
675
echo $XFS_AGE > /proc/sys/fs/xfs/lm_sync_interval
676
elif [ -f /proc/sys/fs/xfs/age_buffer ] ; then
678
# But not for these -- they are also used in normal
680
echo "Adjusting XFS kernel parameters for 2.6.6 kernel." > $OUTPUT
681
echo $XFS_AGE > /proc/sys/fs/xfs/age_buffer
682
echo $XFS_AGE > /proc/sys/fs/xfs/sync_interval
683
elif [ -f /proc/sys/fs/xfs/age_buffer_centisecs ] ; then
685
# And not for these either. These are in centisecs,
686
# not USER_HZ, so we have to use $AGE, not $XFS_AGE.
687
echo "Adjusting XFS kernel parameters for >2.6.7 kernel." > $OUTPUT
688
echo $AGE > /proc/sys/fs/xfs/age_buffer_centisecs
689
echo $AGE > /proc/sys/fs/xfs/xfssyncd_centisecs
690
echo 3000 > /proc/sys/fs/xfs/xfsbufd_centisecs
695
echo "Adjusting 2.4 kernel parameters to enable laptop mode." > $OUTPUT
696
echo 1 > /proc/sys/vm/laptop_mode
697
echo "30 500 0 0 $AGE $AGE 60 20 0" > /proc/sys/vm/bdflush
700
echo "Adjusting 2.6 kernel parameters to enable laptop mode." > $OUTPUT
701
echo "$LM_SECONDS_BEFORE_SYNC" > /proc/sys/vm/laptop_mode
702
echo "$AGE" > /proc/sys/vm/dirty_writeback_centisecs
703
echo "$AGE" > /proc/sys/vm/dirty_expire_centisecs
704
echo "$LM_DIRTY_RATIO" > /proc/sys/vm/dirty_ratio
705
echo "$LM_DIRTY_BACKGROUND_RATIO" > /proc/sys/vm/dirty_background_ratio
708
if [ $CONTROL_MOUNT_OPTIONS -eq 1 ]; then
709
echo "Remounting filesystems." > $OUTPUT
710
cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
712
if ( echo " $PARTITIONS " | grep " $DEV " > /dev/null ) ; then
714
echo "$DEV found in PARTITIONS." > $OUTPUT
716
echo "$DEV not found in PARTITIONS." > $OUTPUT
718
if ( echo " $PARTITIONS " | grep " $MP " > /dev/null ) ; then
720
echo "$MP found in PARTITIONS." > $OUTPUT
722
echo "$MP not found in PARTITIONS." > $OUTPUT
724
if ( echo " $PARTITIONS " | grep " auto " > /dev/null ) ; then
725
echo "Checking $DEV against HD because PARTITIONS contains \"auto\"." > $OUTPUT
726
for THISHD in $HD ; do
727
echo " Considering $THISHD." > $OUTPUT
728
if ( echo " $DEV" | grep "$THISHD" > /dev/null ) ; then
730
echo " $DEV contains $THISHD, which is in HD, so we will remount it." > $OUTPUT
734
if [ "$DO" -ne 0 ] ; then
735
echo "Original options: $OPTS" > $OUTPUT
736
if [ "$WAS_ACTIVE" -eq 0 ] ; then
737
# Coming from inactive state: save last known mount options for the device.
738
echo Updating /var/run/laptop-mode-nolm-mountopts. > $OUTPUT
739
if [ -f /var/run/laptop-mode-nolm-mountopts ] ; then
740
sed -i "s|^$DEV .*$||" /var/run/laptop-mode-nolm-mountopts
742
echo $DEV $OPTS >> /var/run/laptop-mode-nolm-mountopts
744
echo Not updating /var/run/laptop-mode-nolm-mountopts because laptop mode was already active. > $OUTPUT
746
if [ "$FST" = 'unknown' ]; then
747
echo "Deducing fstype for $MP." > $OUTPUT
748
FST=$(deduce_fstype $MP)
749
echo "Deduced fstype for $MP as $FST." > $OUTPUT
751
# Strip stuff like ext3,ext2 into just ext3.
752
echo Reducing file system type. > $OUTPUT
753
FST=`echo $FST | sed s/,.*//`
906
# Adjust kernel settings and mount options (but only if data loss
907
# sensitive features are active)
908
if [ "$ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -eq 1 ] ; then
909
# Take MAX_LOST_WORK_SECONDS from LM_BATT_MAX_LOST_WORK_SECONDS or LM_AC_MAX_LOST_WORK_SECONDS_WITH_LM, depending on power state.
910
MAX_LOST_WORK_SECONDS=$LM_BATT_MAX_LOST_WORK_SECONDS
911
if [ $ON_AC -eq 1 ] ; then
912
MAX_LOST_WORK_SECONDS=$LM_AC_MAX_LOST_WORK_SECONDS
915
AGE=$((100*$MAX_LOST_WORK_SECONDS))
916
XFS_AGE=$(($XFS_HZ*$MAX_LOST_WORK_SECONDS))
918
if [ -d /proc/sys/vm/pagebuf ] ; then
919
# (For 2.4 and early 2.6.)
920
# This only needs to be set, not reset -- it is only used when
921
# laptop mode is enabled.
922
echo "Adjusting XFS kernel parameters for 2.4 and early 2.6 kernels." >> $OUTPUT
923
set_sysctl /proc/sys/vm/pagebuf/lm_flush_age $XFS_AGE
924
set_sysctl /proc/sys/fs/xfs/lm_sync_interval $XFS_AGE
925
elif [ -f /proc/sys/fs/xfs/lm_age_buffer ] ; then
926
# (A couple of early 2.6 laptop mode patches had these.)
927
# This only needs to be set, not reset -- it is only used when
928
# laptop mode is enabled.
929
echo "Adjusting XFS kernel parameters for early patched 2.6 kernels." >> $OUTPUT
930
set_sysctl /proc/sys/fs/xfs/lm_age_buffer $XFS_AGE
931
set_sysctl /proc/sys/fs/xfs/lm_sync_interval $XFS_AGE
932
elif [ -f /proc/sys/fs/xfs/age_buffer ] ; then
934
# But not for these -- they are also used in normal
936
echo "Adjusting XFS kernel parameters for 2.6.6 kernel." >> $OUTPUT
937
set_sysctl /proc/sys/fs/xfs/age_buffer $XFS_AGE
938
set_sysctl /proc/sys/fs/xfs/sync_interval $XFS_AGE
939
elif [ -f /proc/sys/fs/xfs/age_buffer_centisecs ] ; then
941
# And not for these either. These are in centisecs,
942
# not USER_HZ, so we have to use $AGE, not $XFS_AGE.
943
echo "Adjusting XFS kernel parameters for >2.6.7 kernel." >> $OUTPUT
944
set_sysctl /proc/sys/fs/xfs/age_buffer_centisecs $AGE
945
set_sysctl /proc/sys/fs/xfs/xfssyncd_centisecs $AGE
946
set_sysctl /proc/sys/fs/xfs/xfsbufd_centisecs 3000
951
echo "Adjusting 2.4 kernel parameters to enable laptop mode." >> $OUTPUT
952
set_sysctl /proc/sys/vm/laptop_mode 1
953
set_sysctl /proc/sys/vm/bdflush "30 500 0 0 $AGE $AGE 60 20 0"
956
echo "Adjusting 2.6 kernel parameters to enable laptop mode." >> $OUTPUT
957
set_sysctl /proc/sys/vm/laptop_mode "$LM_SECONDS_BEFORE_SYNC"
958
set_sysctl /proc/sys/vm/dirty_writeback_centisecs "$AGE"
959
set_sysctl /proc/sys/vm/dirty_expire_centisecs "$AGE"
960
set_sysctl /proc/sys/vm/dirty_ratio "$LM_DIRTY_RATIO"
961
set_sysctl /proc/sys/vm/dirty_background_ratio "$LM_DIRTY_BACKGROUND_RATIO"
964
if [ $CONTROL_MOUNT_OPTIONS -eq 1 ]; then
965
echo "Remounting filesystems." >> $OUTPUT
966
cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
968
if ( echo " $PARTITIONS " | grep " $DEV " > /dev/null ) ; then
970
echo "$DEV found in PARTITIONS." >> $OUTPUT
972
echo "$DEV not found in PARTITIONS." >> $OUTPUT
974
if ( echo " $PARTITIONS " | grep " $MP " > /dev/null ) ; then
976
echo "$MP found in PARTITIONS." >> $OUTPUT
978
echo "$MP not found in PARTITIONS." >> $OUTPUT
980
if ( echo " $PARTITIONS " | grep " auto " > /dev/null ) ; then
981
echo "Checking $DEV against HD because PARTITIONS contains \"auto\"." >> $OUTPUT
982
for THISHD in $HD ; do
983
echo " Considering $THISHD." >> $OUTPUT
984
if ( echo " $DEV" | grep "$THISHD" > /dev/null ) ; then
986
echo " $DEV contains $THISHD, which is in HD, so we will remount it." >> $OUTPUT
990
if [ "$DO" -ne 0 ] ; then
991
echo "Original options: $OPTS" >> $OUTPUT
992
if [ "$WAS_ACTIVE" -eq 0 ] ; then
993
# Coming from inactive state: save last known mount options for the device.
994
echo Updating /var/run/laptop-mode-nolm-mountopts. >> $OUTPUT
995
if [ -f /var/run/laptop-mode-nolm-mountopts ] ; then
996
sed -i "s|^$DEV .*$||" /var/run/laptop-mode-nolm-mountopts
998
echo $DEV $OPTS >> /var/run/laptop-mode-nolm-mountopts
1000
echo Not updating /var/run/laptop-mode-nolm-mountopts because laptop mode was already active. >> $OUTPUT
1002
if [ "$FST" = 'unknown' ]; then
1003
echo "Deducing fstype for $MP." >> $OUTPUT
1004
FST=$(deduce_fstype $MP)
1005
echo "Deduced fstype for $MP as $FST." >> $OUTPUT
1007
# Strip stuff like ext3,ext2 into just ext3.
1008
echo Reducing file system type. >> $OUTPUT
1009
FST=`echo $FST | sed s/,.*//`
1012
echo Removing commit mount option from original options. >> $OUTPUT
1013
PARSEDOPTS="$(remove_numeric_mount_option commit "$OPTS")"
1014
echo "Executing: mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_LOST_WORK_SECONDS$NOATIME_OPT" >> $OUTPUT
1015
if (! mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_LOST_WORK_SECONDS$NOATIME_OPT) ; then
1016
if [ "$FST" == "ext3" -a "$MP" == "/" ] ; then
1017
echo "BIG FAT WARNING: Your root filesystem mounted as ext3 seems to lack support for"
1018
echo "the commit mount option. This usually means that your root filesystem is"
1019
echo "mounted as ext2 because there is no ext3 support in the kernel at boot time,"
1020
echo "usually because you compiled ext3 as a module and don't load it in an initrd."
1021
echo "Note that on recent 2.6 kernels, /proc/mounts shows the correct fs type for"
1022
echo "the device /dev/root. You can check your actual root filesystem mount type"
1023
echo "there. To fix the problem, either make ext3 available at boot time by compiling"
1024
echo "it statically into the kernel, or configure the correct filesystem type in"
1030
echo "Executing: mount $DEV -t $FST $MP -o remount,$OPTS$NOATIME_OPT" >> $OUTPUT
1031
mount $DEV -t $FST $MP -o remount,$OPTS$NOATIME_OPT
1034
if [ -b $DEV -a "$CONTROL_READAHEAD" -ne 0 ] ; then
1035
echo "Executing: blockdev --setra $(($LM_READAHEAD * 2)) $DEV" >> $OUTPUT
1036
blockdev --setra $(($LM_READAHEAD * 2)) $DEV >> $OUTPUT 2>&1
1042
# DEACTIVATE w.r.t. kernel options and mount point settings
1043
U_AGE=$((100*$DEF_UPDATE))
1044
B_AGE=$((100*$DEF_MAX_AGE))
1045
set_sysctl /proc/sys/vm/laptop_mode 0
1046
if [ -f /proc/sys/fs/xfs/age_buffer -a ! -f /proc/sys/fs/xfs/lm_age_buffer ] ; then
1047
# These need to be restored, if there are no lm_*.
1048
echo "Restoring default XFS settings (pre-centisecs version)." >> $OUTPUT
1049
set_sysctl /proc/sys/fs/xfs/age_buffer $(($XFS_HZ*$DEF_XFS_AGE_BUFFER))
1050
set_sysctl /proc/sys/fs/xfs/sync_interval $(($XFS_HZ*$DEF_XFS_SYNC_INTERVAL))
1051
elif [ -f /proc/sys/fs/xfs/age_buffer_centisecs ] ; then
1052
# These need to be restored as well.
1053
echo "Restoring default XFS settings." >> $OUTPUT
1054
set_sysctl /proc/sys/fs/xfs/age_buffer_centisecs $((100*$DEF_XFS_AGE_BUFFER))
1055
set_sysctl /proc/sys/fs/xfs/xfssyncd_centisecs $((100*$DEF_XFS_SYNC_INTERVAL))
1056
set_sysctl /proc/sys/fs/xfs/xfsbufd_centisecs $((100*$DEF_XFS_BUFD_INTERVAL))
1060
echo "Adjusting 2.4 kernel parameters to disable laptop mode." >> $OUTPUT
1061
set_sysctl /proc/sys/vm/bdflush "30 500 0 0 $U_AGE $B_AGE 60 20 0"
1064
echo "Adjusting 2.6 kernel parameters to disable laptop mode." >> $OUTPUT
1065
set_sysctl /proc/sys/vm/dirty_writeback_centisecs "$U_AGE"
1066
set_sysctl /proc/sys/vm/dirty_expire_centisecs "$B_AGE"
1067
set_sysctl /proc/sys/vm/dirty_ratio "$NOLM_DIRTY_RATIO"
1068
set_sysctl /proc/sys/vm/dirty_background_ratio "$NOLM_DIRTY_BACKGROUND_RATIO"
1071
if [ $CONTROL_MOUNT_OPTIONS -eq 1 ] ; then
1072
echo "Remounting filesystems." >> $OUTPUT
1073
cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
1075
if ( echo " $PARTITIONS " | grep " $DEV " > /dev/null ) ; then
1077
echo "$DEV found in PARTITIONS." >> $OUTPUT
1079
echo "$DEV not found in PARTITIONS." >> $OUTPUT
1081
if ( echo " $PARTITIONS " | grep " $MP " > /dev/null ) ; then
1083
echo "$MP found in PARTITIONS." >> $OUTPUT
1085
echo "$MP not found in PARTITIONS." >> $OUTPUT
1087
if ( echo " $PARTITIONS " | grep " auto " > /dev/null ) ; then
1088
echo "Checking $DEV against HD because PARTITIONS contains \"auto\"." >> $OUTPUT
1089
for THISHD in $HD ; do
1090
echo " Considering $THISHD." >> $OUTPUT
1091
if ( echo " $DEV" | grep "$THISHD" > /dev/null ) ; then
1093
echo " $DEV contains $THISHD, which is in HD, so we will remount it." >> $OUTPUT
1097
if [ "$DO" -ne 0 ] ; then
1098
# Reset commit and atime options to defaults.
1099
echo "Original options: $OPTS" >> $OUTPUT
1100
if [ "$FST" = 'unknown' ]; then
1101
echo "Deducing fstype for $MP." >> $OUTPUT
1102
FST=$(deduce_fstype $MP)
1103
echo "Deduced fstype for $MP as $FST." >> $OUTPUT
1106
# Strip stuff like ext3,ext2 into just ext3.
1107
echo Reducing file system type. >> $OUTPUT
1108
FST=`echo $FST | sed s/,.*//`
1110
# Retrieve original non-laptop mode mount options and restore them.
1111
# If the file that stores them doesn't exist, then laptop mode
1112
# has never been started.
1113
if [ "$WAS_ACTIVE" -ne 0 -a -f /var/run/laptop-mode-nolm-mountopts ] ; then
1114
SAVED_OPTS=`grep "^$DEV " /var/run/laptop-mode-nolm-mountopts`
756
echo Removing commit mount option from original options. > $OUTPUT
757
PARSEDOPTS="$(remove_numeric_mount_option commit "$OPTS")"
758
echo "Executing: mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_LOST_WORK_SECONDS$NOATIME_OPT" > $OUTPUT
759
if (! mount $DEV -t $FST $MP -o remount,$PARSEDOPTS,commit=$MAX_LOST_WORK_SECONDS$NOATIME_OPT) ; then
760
if [ "$FST" == "ext3" -a "$MP" == "/" ] ; then
761
echo "BIG FAT WARNING: Your root filesystem mounted as ext3 seems to lack support for the commit mount option."
762
echo "This usually means that your root filesystem is mounted as ext2 because there is no ext3 support in the"
763
echo "kernel at boot time, usually because you compiled ext3 as a module and don't load it in an initrd."
1118
PARSEDOPTS="$(replace_numeric_mount_option commit commit=0 $SAVED_OPTS $OPTS)"
1119
PARSEDOPTS="$(replace_yesno_mount_option atime atime $SAVED_OPTS $PARSEDOPTS)"
1120
echo Executing: mount $DEV -t $FST $MP -o remount,$PARSEDOPTS >> $OUTPUT
1121
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
768
echo "Executing: mount $DEV -t $FST $MP -o remount,$OPTS$NOATIME_OPT" > $OUTPUT
769
mount $DEV -t $FST $MP -o remount,$OPTS$NOATIME_OPT
1124
PARSEDOPTS="$(replace_yesno_mount_option atime atime $SAVED_OPTS $OPTS)"
1125
echo Executing: mount $DEV -t $FST $MP -o remount,$PARSEDOPTS >> $OUTPUT
1126
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
772
if [ -b $DEV -a "$CONTROL_READAHEAD" -ne 0 ] ; then
773
echo "Executing: blockdev --setra $(($LM_READAHEAD * 2)) $DEV" > $OUTPUT
774
blockdev --setra $(($LM_READAHEAD * 2)) $DEV > $OUTPUT 2>&1
782
U_AGE=$((100*$DEF_UPDATE))
783
B_AGE=$((100*$DEF_MAX_AGE))
784
echo -n "$STATE, not active"
785
echo 0 > /proc/sys/vm/laptop_mode
786
if [ -f /proc/sys/fs/xfs/age_buffer -a ! -f /proc/sys/fs/xfs/lm_age_buffer ] ; then
787
# These need to be restored, if there are no lm_*.
788
echo "Restoring default XFS settings (pre-centisecs version)." > $OUTPUT
789
echo $(($XFS_HZ*$DEF_XFS_AGE_BUFFER)) > /proc/sys/fs/xfs/age_buffer
790
echo $(($XFS_HZ*$DEF_XFS_SYNC_INTERVAL)) > /proc/sys/fs/xfs/sync_interval
791
elif [ -f /proc/sys/fs/xfs/age_buffer_centisecs ] ; then
792
# These need to be restored as well.
793
echo "Restoring default XFS settings." > $OUTPUT
794
echo $((100*$DEF_XFS_AGE_BUFFER)) > /proc/sys/fs/xfs/age_buffer_centisecs
795
echo $((100*$DEF_XFS_SYNC_INTERVAL)) > /proc/sys/fs/xfs/xfssyncd_centisecs
796
echo $((100*$DEF_XFS_BUFD_INTERVAL)) > /proc/sys/fs/xfs/xfsbufd_centisecs
800
echo "Adjusting 2.4 kernel parameters to disable laptop mode." > $OUTPUT
801
echo "30 500 0 0 $U_AGE $B_AGE 60 20 0" > /proc/sys/vm/bdflush
804
echo "Adjusting 2.6 kernel parameters to disable laptop mode." > $OUTPUT
805
echo "$U_AGE" > /proc/sys/vm/dirty_writeback_centisecs
806
echo "$B_AGE" > /proc/sys/vm/dirty_expire_centisecs
807
echo "$NOLM_DIRTY_RATIO" > /proc/sys/vm/dirty_ratio
808
echo "$NOLM_DIRTY_BACKGROUND_RATIO" > /proc/sys/vm/dirty_background_ratio
811
if [ $CONTROL_MOUNT_OPTIONS -eq 1 ] ; then
812
echo "Remounting filesystems." > $OUTPUT
813
cat /etc/mtab | while read DEV MP FST OPTS DUMP PASS ; do
815
if ( echo " $PARTITIONS " | grep " $DEV " > /dev/null ) ; then
817
echo "$DEV found in PARTITIONS." > $OUTPUT
819
echo "$DEV not found in PARTITIONS." > $OUTPUT
821
if ( echo " $PARTITIONS " | grep " $MP " > /dev/null ) ; then
823
echo "$MP found in PARTITIONS." > $OUTPUT
825
echo "$MP not found in PARTITIONS." > $OUTPUT
827
if ( echo " $PARTITIONS " | grep " auto " > /dev/null ) ; then
828
echo "Checking $DEV against HD because PARTITIONS contains \"auto\"." > $OUTPUT
829
for THISHD in $HD ; do
830
echo " Considering $THISHD." > $OUTPUT
831
if ( echo " $DEV" | grep "$THISHD" > /dev/null ) ; then
833
echo " $DEV contains $THISHD, which is in HD, so we will remount it." > $OUTPUT
837
if [ "$DO" -ne 0 ] ; then
838
# Reset commit and atime options to defaults.
839
echo "Original options: $OPTS" > $OUTPUT
840
if [ "$FST" = 'unknown' ]; then
841
echo "Deducing fstype for $MP." > $OUTPUT
842
FST=$(deduce_fstype $MP)
843
echo "Deduced fstype for $MP as $FST." > $OUTPUT
846
# Strip stuff like ext3,ext2 into just ext3.
847
echo Reducing file system type. > $OUTPUT
848
FST=`echo $FST | sed s/,.*//`
850
# Retrieve original non-laptop mode mount options and restore them.
851
# If the file that stores them doesn't exist, then laptop mode
852
# has never been started.
853
if [ "$WAS_ACTIVE" -ne 0 -a -f /var/run/laptop-mode-nolm-mountopts ] ; then
854
SAVED_OPTS=`grep "^$DEV " /var/run/laptop-mode-nolm-mountopts`
858
PARSEDOPTS="$(replace_numeric_mount_option commit commit=0 $SAVED_OPTS $OPTS)"
859
PARSEDOPTS="$(replace_yesno_mount_option atime atime $SAVED_OPTS $PARSEDOPTS)"
860
echo Executing: mount $DEV -t $FST $MP -o remount,$PARSEDOPTS > $OUTPUT
861
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
864
PARSEDOPTS="$(replace_yesno_mount_option atime atime $SAVED_OPTS $OPTS)"
865
echo Executing: mount $DEV -t $FST $MP -o remount,$PARSEDOPTS > $OUTPUT
866
mount $DEV -t $FST $MP -o remount,$PARSEDOPTS
870
echo "No saved mount options, so apparently we never remounted this filesystem during this session." > $OUTPUT
871
echo "Not remounting." > $OUTPUT
873
if [ -b $DEV -a "$CONTROL_READAHEAD" -ne 0 ] ; then
874
echo "Executing: blockdev --setra $(($NOLM_READAHEAD * 2)) $DEV" > $OUTPUT
875
blockdev --setra $(($NOLM_READAHEAD * 2)) $DEV > /dev/null 2>&1
883
echo "Usage: $0 {start|stop|auto|status}" 2>&1
1130
echo "No saved mount options, so apparently we never remounted this filesystem during this session." >> $OUTPUT
1131
echo "Not remounting." >> $OUTPUT
1133
if [ -b $DEV -a "$CONTROL_READAHEAD" -ne 0 ] ; then
1134
echo "Executing: blockdev --setra $(($NOLM_READAHEAD * 2)) $DEV" >> $OUTPUT
1135
blockdev --setra $(($NOLM_READAHEAD * 2)) $DEV > /dev/null 2>&1
889
1144
# Adjust hard drive powermanagement
1146
# Function for drive capability check. This prevents ugly errors in
1147
# the kernel output about unsupported commands.
1150
# $2 = capability (SDPARM/HDPARM or IDLE_TIMEOUT/POWERMGMT/WRITECACHE)
1152
local dev=${1#/dev/}
1157
if [ -x "$(which udevinfo 2> /dev/null)" ] ; then
1158
UDEVVERSION=$(udevinfo -V | awk '{ print $3; }')
1159
if [ "$UDEVVERSION" -gt 70 ] ; then
1162
echo "udevinfo present but version not > 070, not using udev" >> $OUTPUT
1166
# If we are running udev, this is the most portable way
1167
# It assumes more or less recent udev (> 070)
1168
if [ $HAVE_UDEVINFO -ne 0 ] ; then
1169
echo -n "Querying $1 media type using udevinfo: " >> $OUTPUT
1170
eval "$(udevinfo -q env -n $1 2> $OUTPUT | egrep '(ID_TYPE=|ID_BUS=)' >> $OUTPUT 2>&1)"
1171
if [ -n "$ID_TYPE" -a -n "$ID_BUS" ] ; then
1172
echo "type '$ID_TYPE on bus '$ID_BUS' detected" >> $OUTPUT
1176
echo "failed - udev not active?" >> $OUTPUT
1180
if [ -z "$MEDIA" ] ; then
1181
echo -n "Querying $1 media type using device name: " >> $OUTPUT
1184
if [ -r /proc/ide/$dev/media ]; then
1185
MEDIA="$(cat /proc/ide/$dev/media)"
1187
if [ "$MEDIA" = cdrom ] ; then
1193
# No need to check, sd is always SCSI disk
1198
# No need to check, sr or scd is always SCSI CD-ROM
1204
if [ -n "$MEDIA" ] ; then
1205
echo "type '$MEDIA' on bus '$BUS' detected" >> $OUTPUT
1207
echo "failed - unknown name" >> $OUTPUT
1211
if [ -z "$MEDIA" ] ; then
1212
if [ -x "$(which hdparm 2> /dev/null)" ]; then
1213
echo -n "Querying $1 type using hdparm: " >> $OUTPUT
1214
if hdparm -I $1 2> $OUTPUT | grep -q CD-ROM >> $OUTPUT 2>&1 ; then
1219
BUS=ata # or acts like it anyway, because hdparm supports it.
1220
echo "type '$MEDIA' on bus '$BUS' detected" >> $OUTPUT
1225
if [ -z "$MEDIA" -o -z "$BUS" ] ; then
1226
echo "Querying $1 type - unknown type or bus, disabling hdparm/sdparm" >> $OUTPUT
1230
if [ "$BUS" == "scsi" -a "$ASSUME_SCSI_IS_SATA" -ne 0 ] ;then
1231
# Treat scsi disks as SATA devices. Unfortunately they are hard
1232
# to recognize -- if anybody has a drive and cares to find out
1233
# how to recognize them, please enlighten me!
1237
# Now check what capabilities we support for the
1238
# various media and bus types.
1239
case "$MEDIA:$BUS:$2" in
1240
# Although CD-ROM drives usually support
1241
# idle timeout settings, they don't usually
1242
# support very low values, and we don't want
1243
# to mess with that. We simply ignore anything
1244
# that is a CD player.
1247
# ATA drives support the "hdparm" command but
1248
# not normally the "sdparm" command.
1249
*:ata:HDPARM ) return 0 ;;
1250
*:ata:SDPARM ) return 1 ;;
1252
# SCSI drives support the "sdparm" command, but
1253
# not normally the "hdparm" command.
1254
*:scsi:SDPARM ) return 0 ;;
1255
*:scsi:HDPARM ) return 1 ;;
1257
# On ATA disks everything is supported.
1258
disk:ata:* ) return 0 ;;
1260
# For sdparm we only know how to set the idle
1261
# timeout, nothing else at the moment.
1262
*:scsi:IDLE_TIMEOUT ) return 0 ;;
1264
# No other capabilities are supported.
891
1269
if [ $CONTROL_HD_POWERMGMT -eq 1 ] ; then
892
if [ ! -f `which hdparm` ] ; then
893
echo Warning: CONTROL_HD_POWERMGMT is enabled but hdparm is not installed.
1270
if [ $ON_AC -eq 1 ] ; then
1271
if [ "$ACTIVATE" -eq 1 ] ; then
1272
HD_POWERMGMT=$LM_AC_HD_POWERMGMT
1274
HD_POWERMGMT=$NOLM_AC_HD_POWERMGMT
895
if [ $ON_AC -eq 1 ] ; then
896
if [ "$ACTION" = "start" ] ; then
897
HD_POWERMGMT=$LM_AC_HD_POWERMGMT
899
HD_POWERMGMT=$NOLM_AC_HD_POWERMGMT
902
HD_POWERMGMT=$BATT_HD_POWERMGMT
905
echo "Setting powermanagement on drives to $HD_POWERMGMT." > $OUTPUT
906
for THISHD in $HD ; do
907
if ( ! hdparm -I $THISHD 2>/dev/null |grep CD-ROM > $OUTPUT ) ; then
908
echo "Executing: hdparm -B $HD_POWERMGMT $THISHD" > $OUTPUT
909
hdparm -B $HD_POWERMGMT $THISHD > $OUTPUT 2>&1
911
echo "Skipping $THISHD: is a CD-ROM according to hdparm -I." > $OUTPUT
1277
HD_POWERMGMT=$BATT_HD_POWERMGMT
1280
echo "Setting powermanagement on drives to $HD_POWERMGMT." >> $OUTPUT
1281
for THISHD in $HD ; do
1282
if is_capable $THISHD POWERMGMT ; then
1283
if is_capable $THISHD HDPARM ; then
1284
if [ ! -e `which hdparm 2> /dev/null` ] ; then
1285
echo "ERROR: hdparm not installed."
1287
echo "Executing: hdparm -B $HD_POWERMGMT $THISHD" >> $OUTPUT
1288
hdparm -B $HD_POWERMGMT $THISHD >> $OUTPUT 2>&1
1291
echo "Skipping $THISHD: powermgmt only possible with hdparm but drive does not" >> $OUTPUT
1292
echo "support hdparm." >> $OUTPUT
1295
echo "Skipping $THISHD: powermanagement control not supported." >> $OUTPUT
917
1300
if [ $CONTROL_HD_IDLE_TIMEOUT -eq 1 ] ; then
918
if [ ! -f `which hdparm` ] ; then
919
echo Warning: CONTROL_HD_IDLE_TIMEOUT is enabled but hdparm is not installed.
1301
# Spindown timeouts may only be set when data-loss sensitive
1302
# features are active.
1303
if [ "$ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -eq 1 ] ; then
1304
if [ $ON_AC -eq 1 ] ; then
1305
HD_IDLE_TIMEOUT=$LM_AC_HD_IDLE_TIMEOUT
1306
HD_IDLE_TIMEOUT_SECONDS=$LM_AC_HD_IDLE_TIMEOUT_SECONDS
1308
HD_IDLE_TIMEOUT=$LM_BATT_HD_IDLE_TIMEOUT
1309
HD_IDLE_TIMEOUT_SECONDS=$LM_BATT_HD_IDLE_TIMEOUT_SECONDS
921
if [ "$ACTION" = "start" ] ; then
922
if [ $ON_AC -eq 1 ] ; then
923
HD_IDLE_TIMEOUT=$LM_AC_HD_IDLE_TIMEOUT
925
HD_IDLE_TIMEOUT=$LM_BATT_HD_IDLE_TIMEOUT
928
HD_IDLE_TIMEOUT=$NOLM_HD_IDLE_TIMEOUT
931
echo "Setting spindown timeout on drives to $HD_IDLE_TIMEOUT." > $OUTPUT
932
for THISHD in $HD ; do
933
if ( ! hdparm -I $THISHD 2> /dev/null |grep CD-ROM > $OUTPUT ) ; then
934
echo "Executing: hdparm -S $HD_IDLE_TIMEOUT $THISHD" > $OUTPUT
935
hdparm -S $HD_IDLE_TIMEOUT $THISHD > $OUTPUT 2>&1
937
echo "Skipping $THISHD: is a CD-ROM according to hdparm -I." > $OUTPUT
1312
HD_IDLE_TIMEOUT=$NOLM_HD_IDLE_TIMEOUT
1313
HD_IDLE_TIMEOUT_SECONDS=$NOLM_HD_IDLE_TIMEOUT_SECONDS
1315
echo "Setting spindown timeout on drives to $HD_IDLE_TIMEOUT_SECONDS seconds." >> $OUTPUT
1316
echo "(hdparm configuration value = $HD_IDLE_TIMEOUT.)" >> $OUTPUT
1317
for THISHD in $HD ; do
1318
if is_capable $THISHD IDLE_TIMEOUT ; then
1319
if is_capable $THISHD HDPARM ; then
1320
if [ ! -e `which hdparm 2> /dev/null` ] ; then
1321
echo "ERROR: hdparm not installed."
1323
echo "Executing: hdparm -S $HD_IDLE_TIMEOUT $THISHD" >> $OUTPUT
1324
hdparm -S $HD_IDLE_TIMEOUT $THISHD >> $OUTPUT 2>&1
1326
elif is_capable $THISHD SDPARM ; then
1327
if [ ! -e `which sdparm 2> /dev/null` ] ; then
1328
echo "ERROR: sdparm not installed."
1330
HD_IDLE_TIMEOUT_DECISECONDS=$(($HD_IDLE_TIMEOUT_SECONDS*10))
1331
echo "Executing: sdparm -q -s SCT=$HD_IDLE_TIMEOUT_DECISECONDS $THISHD" >> $OUTPUT
1332
sdparm -q -s SCT=$HD_IDLE_TIMEOUT_DECISECONDS $THISHD >> $OUTPUT 2>&1
1335
echo "Skipping $THISHD: drive supports neither hdparm nor sdparm." >> $OUTPUT
1338
echo "Skipping $THISHD: idle timeout control not supported." >> $OUTPUT
943
1343
if [ $CONTROL_HD_WRITECACHE -eq 1 ] ; then
944
if [ ! -f `which hdparm` ] ; then
945
echo Warning: CONTROL_HD_WRITECACHE is enabled but hdparm is not installed.
947
if [ "$ACTION" = "start" ] ; then
1344
# The writecache may only be enabled when data-loss sensitive
1345
# features are active.
1347
if [ "$ACTIVATE" -eq 1 ] ; then
1348
if [ "$ACTIVATE_WITH_POSSIBLE_DATA_LOSS" -eq 0 ] ; then
948
1351
HD_WRITECACHE=$LM_HD_WRITECACHE
1354
if [ $ON_AC -eq 1 ] ; then
1355
HD_WRITECACHE=$NOLM_AC_HD_WRITECACHE
950
if [ $ON_AC -eq 1 ] ; then
951
HD_WRITECACHE=$NOLM_AC_HD_WRITECACHE
953
HD_WRITECACHE=$NOLM_BATT_HD_WRITECACHE
1357
HD_WRITECACHE=$NOLM_BATT_HD_WRITECACHE
957
echo "Setting write cache on drives to $HD_WRITECACHE." > $OUTPUT
958
for THISHD in $HD ; do
959
if ( ! hdparm -I $THISHD 2> /dev/null |grep CD-ROM > $OUTPUT ) ; then
960
echo "Executing: hdparm -W $HD_WRITECACHE $THISHD" > $OUTPUT
961
hdparm -W $HD_WRITECACHE $THISHD > $OUTPUT 2>&1
963
echo "Skipping $THISHD: is a CD-ROM according to hdparm -I." > $OUTPUT
1360
echo "Setting write cache on drives to $HD_WRITECACHE." >> $OUTPUT
1361
for THISHD in $HD ; do
1362
if is_capable $THISHD WRITECACHE ; then
1363
if is_capable $THISHD HDPARM ; then
1364
if [ ! -e `which hdparm 2> /dev/null` ] ; then
1365
echo "ERROR: hdparm not installed."
1367
echo "Executing: hdparm -W $HD_WRITECACHE $THISHD" >> $OUTPUT
1368
hdparm -W $HD_WRITECACHE $THISHD >> $OUTPUT 2>&1
1371
echo "Skipping $THISHD: writecache only possible with hdparm but drive does not" >> $OUTPUT
1372
echo "support hdparm." >> $OUTPUT
1375
echo "Skipping $THISHD: writecache control not supported." >> $OUTPUT
969
1380
if [ $CONTROL_SYSLOG_CONF -eq 1 ] ; then
970
echo "Adjusting syslog configuration." > $OUTPUT
971
if [ $ON_AC -eq 1 ] ; then
972
if [ "$ACTION" = "start" ] ; then
973
echo "Setting syslog config to $LM_AC_SYSLOG_CONF." > $OUTPUT
974
ln -fs $LM_AC_SYSLOG_CONF $SYSLOG_CONF
975
elif [ "$ACTION" = "stop" ] ; then
976
echo "Setting syslog config to $NOLM_AC_SYSLOG_CONF." > $OUTPUT
977
ln -fs $NOLM_AC_SYSLOG_CONF $SYSLOG_CONF
980
echo "Setting syslog config to $BATT_SYSLOG_CONF." > $OUTPUT
981
ln -fs $BATT_SYSLOG_CONF $SYSLOG_CONF
1381
echo "Adjusting syslog configuration." >> $OUTPUT
1382
if [ "`readlink -f $SYSLOG_CONF`" != "$SYSLOG_CONF" ] ; then
1383
echo "$SYSLOG_CONF is a symlink." >> $OUTPUT
1384
if [ ! -f "$SYSLOG_CONF.no-lm" ] ; then
1385
echo "But there is no $SYSLOG_CONF.no-lm. This must have been done by an earlier" >> $OUTPUT
1386
echo "version of laptop-mode-tools." >> $OUTPUT
1387
echo "Creating it now from $NOLM_AC_SYSLOG_CONF."
1388
cp "$NOLM_AC_SYSLOG_CONF" "$SYSLOG_CONF.no-lm"
1391
echo "$SYSLOG_CONF is not a symlink." >> $OUTPUT
1392
if [ "$STATE" == "enabled" ] ; then
1393
echo "Saving it to $SYSLOG_CONF.no-lm." >> $OUTPUT
1394
cp --backup=numbered "$SYSLOG_CONF" "$SYSLOG_CONF.no-lm"
1398
if [ "$STATE" != "enabled" ] ; then
1399
echo "Laptop mode is not enabled. Restoring $SYSLOG_CONF." >> $OUTPUT
1400
if [ -f "$SYSLOG_CONF.no-lm" ] ; then
1401
mv "$SYSLOG_CONF.no-lm" "$SYSLOG_CONF"
1402
elif [ "`readlink -f $SYSLOG_CONF`" != "$SYSLOG_CONF" ] ; then
1403
echo "ERROR: $SYSLOG_CONF is a symlink but $SYSLOG_CONF.no-lm is not present."
1405
elif [ $ON_AC -eq 1 ] ; then
1406
if [ "$ACTIVATE" -eq 1 ] ; then
1407
echo "Setting syslog config to $LM_AC_SYSLOG_CONF." >> $OUTPUT
1408
ln -fs "$LM_AC_SYSLOG_CONF" "$SYSLOG_CONF"
1410
echo "Setting syslog config to $NOLM_AC_SYSLOG_CONF." >> $OUTPUT
1411
ln -fs "$NOLM_AC_SYSLOG_CONF" "$SYSLOG_CONF"
1414
echo "Setting syslog config to $BATT_SYSLOG_CONF." >> $OUTPUT
1415
ln -fs "$BATT_SYSLOG_CONF" "$SYSLOG_CONF"
983
1417
# Notify syslogd of configuration change.
984
1418
if [ "$SYSLOG_CONF_SIGNAL_PROGRAM" != "" ] ; then
985
echo "Sending SIGHUP to all $SYSLOG_CONF_SIGNAL_PROGRAM processes." > $OUTPUT
1419
echo "Sending SIGHUP to all $SYSLOG_CONF_SIGNAL_PROGRAM processes." >> $OUTPUT
986
1420
killall -q -HUP $SYSLOG_CONF_SIGNAL_PROGRAM
990
# Setting xwindow screen standby suspend off timing
1424
# Setting X screen standby/suspend/powerdown timing
991
1425
if [ $CONTROL_DPMS_STANDBY -eq 1 ] ; then
992
1426
if [ $ON_AC -eq 1 ]; then
993
if [ "$ACTION" = "start" ]; then
1427
if [ "$ACTIVATE" -eq 1 ]; then
994
1428
STANDBY="$LM_AC_DPMS_STANDBY"
995
1429
SUSPEND=$((STANDBY+30))
996
1430
OFF=$((STANDBY+60))