In this post, I describe how to write a shell script that switches off a laptop screen. The instructions are tested with Ubuntu Linux 5.10 (Breezy) on a Dell Latitude C810.
First, set the governor for the CPU frequency with the following command.
echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
This command can be run automatically at run-level 2 by putting it in /etc/rc2.d/S30freq-scaling
.
Out of the box Breezy is configured to manage power, but we need additional configuration for some laptops.
First, on the C810 the kernel needs the acpi_irq_balance
option in order to report certain ACPI events (for example, closing the lid). We fix this by adding the kernel option acpi_irq_balance
in GRUB’s menu.lst
.
title Ubuntu, kernel 2.6.12-9-686 root (hd0,0) kernel /boot/vmlinuz-2.6.12-9-686 root=/dev/hda1 acpi_irq_balance ro quiet splash resume=/dev/hda5 initrd /boot/initrd.img-2.6.12-9-686 savedefault boot
Second, it seems that the command xset dpms force off
does not switch off the screen. Instead, we must use the command vbetool
to do this. Although it is reported to cause unexpected behaviour, it works with the C810.
After configuring the kernel as describe above, we can write the script /etc/acpi/screen.sh
to turn on and to turn off the laptop screen.
#!/bin/sh case "$1" in on) /usr/sbin/vbetool dpms on ;; off) /usr/sbin/vbetool dpms off ;; *) N=/etc/acpi/screen.sh echo "Usage: $N {on|off}" ;; esac
The script takes as argument on
or off
, as in the example below.
/etc/acpi/screen.sh off