User Tools

Site Tools


Laptop Hacks

Ho boy, this got difficult really quickly - in 2012 I had everything working on my laptop with the LXDE spin of fedora plus fluxbox. After a quick spurt of travel using all the laptoppy things like conserving battery life, suspend/resume and lid up and down, I left it alone, using it like a desktop on AC power but updating through various fedora's. Quite unbeknownst to me, systemd came in and the laptoppy stuff got broken - I had to re-discover how to do everything again. Now I know and understand some of it and hopefully recording it here will help me next time.

Maybe it'll help you too - but you will almost certainly need to some make tweaks for your particular setup.

Why go through all this? Why not just use a full DE like KDE or gnome to take care of it? With KDE the best I could get (without digging just as deep as I have done here) was about 4 hours of battery life. By doing the hard work and understanding what's going on I can get up to 6.5 hours! Not bad.

Who's doing the work?

Several players:

  • acpid: for suspend
  • DBus: for power connect/disconnect
  • acpi: to get battery status
  • systemctl: but, of course!
  • ???: DBus? lid opening & closing - just seems to work


Install acpid and acpi and then:

systemctl enable acpid
systemctl start acpid

Put this into /etc/acpi/events/sleepconf:

action=systemctl suspend

Tweaking touchpad

Seems the synaptics driver is deprecated in favour of libinput - put tweaks in /etc/X11/xorg.conf.d/30-touchpad.conf:

Section "InputClass"
    Identifier "touchpad"
    Driver "libinput"
    MatchIsTouchpad "on"
    Option "Tapping" "on"
    Option "TappingButtonMap" "lmr"
    Option "ScrollMethod" "edge"

Power Disconnect/Connect events

These events come through DBus, so I run this in my .xsession.

# if there's a battery battery then listen on dbus for a/c connect/disconnect:
upower -e |grep -q battery && power-monitor &

Where, power-monitor is this bit of python which just runs the low-power script when the power/battery status changes:

#!/bin/env python

import gobject, os

from dbus import glib
import dbus
bus = dbus.SystemBus()

def backtick(command):
    Equivalent of Bourne shell's backtick
    from subprocess import Popen, PIPE
    #print "backtick: command='%s'\n" % command
    value = Popen(["sh", "-c", command], stdout=PIPE).communicate()[0].rstrip()
    #print "returning '%s'\n" % value

def ac(*args, **kwargs):
    if args[1]['Online'] == 0:
        os.system("sudo /home/bhepple/bin/low-power true")
        print("plugged in")
        os.system("sudo /home/bhepple/bin/low-power false")
def check_battery(*args, **kwargs):
    battery_status = backtick("acpi -b")
    if "Discharging" in battery_status:
        percent = int( backtick("acpi -b | awk '{print $4}' | tr -d '%,'"))
        print percent
        if percent < 10: backtick("battery-alarm&")
    gobject.timeout_add(60 * 1000, check_battery)

# get path from 'upower -e':
bus.add_signal_receiver(ac, signal_name="PropertiesChanged", dbus_interface="org.freedesktop.DBus.Properties", path="/org/freedesktop/UPower/devices/line_power_ADP0")


l = gobject.MainLoop()

Put this in $HOME/bin/low-power:


[[ "${1:-}" && "$1" == "false" ]] && POWER="ON"

(( $(id -u) == 0 )) || {
    echo "$0: needs to run as root"
    exit 1

echo "stdout and stderr will be sent to $LOG"
exec >$LOG 2>&1

case "$POWER" in
        logger -t $0 "power disconnect: killing bluetooth"
        systemctl stop
        BT_PID=$(ps -ef |grep '[/]usr/libexec/bluetooth/bluetoothd' | awk '{print $2}')
        [[ "$BT_PID" ]] && kill -9 $BT_PID
        rmmod bnep btbcm btrtl btusb btintel bluetooth

        sudo /home/bhepple/bin/01-pm-power-display true
        sudo /home/bhepple/bin/02-pm-power-tweaks true
        sudo /home/bhepple/bin/03-pm-power-hda true

        powertop --auto-tune
        sleep 3


        echo "consider turning off wifi"
        echo "consider turning off camera: rmmod uvcvideo"
        echo "consider turning off ethernet: rmmod r8169 mii"
        sudo /home/bhepple/bin/01-pm-power-display false
        sudo /home/bhepple/bin/02-pm-power-tweaks false
        sudo /home/bhepple/bin/03-pm-power-hda false

        logger -t $0 "power connect: starting bluetooth"
        modprobe bluetooth
        systemctl start

        modprobe uvcvideo r8169 mii

pkill -0 i3blocks && pkill  -RTMIN+9 i3blocks

cat $LOG

Put this in $HOME/bin/01-pm-power-display to dim/brighten the display - requires xbacklight:


logger -t $0 "$0 $@"
case "$1" in
    # called by pm-powersave on power disconnect
    xbacklight -display :0 -set 1
    logger -t $0 "power disconnect: xbacklight -set 10"
    xbacklight -display :0 -set 40
    logger -t $0 "power connect: xbacklight -set 40"
    [[ -f $ALARM_PID_FILE ]] && {
        logger -t $0 "alarm pids = $( cat $ALARM_PID_FILE )"
        for PID in $(cat $ALARM_PID_FILE); do
            [[ $PID > 0 ]] && kill $PID
        rm $ALARM_PID_FILE
exit 0

Put this in $HOME/bin/03-pm-power-hda to maximise battery or performance on the hard disc:

logger -t $0 "$0 $@"

case "$1" in
                # called by pm-powersave on power disconnect
                logger -t $0 "power disconnect: hdparm -B1 -S5 /dev/sda"
                hdparm -B1 -S5 /dev/sda
                # called by pm-powersave on power connect
                logger -t $0 "power connect: hdparm -B128 -S60 /dev/sda"
                hdparm -B128 -S60 /dev/sda
exit 0

Put this in $HOME/bin/02-pm-power-tweaks for general tweaking - most of this originates from powertop:

# BH

logger -t $0 "$0 $@"
case "$1" in
    # called by pm-powersave on power disconnect

    echo 5 > /proc/sys/vm/laptop_mode
    echo 0 > /proc/sys/kernel/nmi_watchdog
    echo 1 > /sys/devices/system/cpu/sched_smt_power_savings
    echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
    for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 1 > $i; done
    for i in /sys/bus/usb/devices/*/power/level; do echo auto > $i; done
    echo min_power > /sys/class/scsi_host/host0/link_power_management_policy
    echo min_power > /sys/class/scsi_host/host1/link_power_management_policy
    echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
    echo 1 > /sys/module/snd_hda_intel/parameters/power_save
    for i in /sys/bus/{pci,i2c}/devices/*/power/control; do echo auto > $i; done
    echo 0 > /proc/sys/vm/laptop_mode
    echo 1 > /proc/sys/kernel/nmi_watchdog
    echo 0 > /sys/devices/system/cpu/sched_smt_power_savings
    echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
    echo 500 > /proc/sys/vm/dirty_writeback_centisecs
    for i in /sys/bus/usb/devices/*/power/autosuspend; do echo 2 > $i; done
    # for i in /sys/bus/usb/devices/*/power/level; do echo auto > $i; done
    echo max_performance > /sys/class/scsi_host/host0/link_power_management_policy
    echo max_performance > /sys/class/scsi_host/host1/link_power_management_policy
    #echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
    #echo 1 > /sys/module/snd_hda_intel/parameters/power_save
    #for i in /sys/bus/{pci,i2c}/devices/*/power/control; do echo auto > $i; done

exit 0

Disable nouveau

I find it slow & buggy so /etc/modprobe.d/blacklist.conf gets:

blacklist nouveau

and /etc/default/grub gets:


Run this to get grub updated:

grub2-mkconfig >/boot/grub2/grub.cfg
laptop_hacks.txt · Last modified: 2017/03/05 02:30 by admin