User Tools

Site Tools


This is an old revision of the document!

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

# needs to run as normal user under X (so that battery-alarm can popup)

import gobject, os, sys

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

sys.dont_write_bytecode = True

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

# power connection events
def ac(*args, **kwargs):
    print("[" + backtick("date '+%Y%m%d:%H%M%S'") + "] power-monitor: ac: args = ")
    print args
        if args[1]['Online'] == 0:
            print("power-monitor: ac: unplugged - calling low-power true")
            os.system("low-power true")
            print("power-monitor: ac: plugged in - calling low-power false")
            os.system("low-power false")

# warn user or suspend
def check_battery(*args, **kwargs):
    battery_status = backtick("acpi -b")
    print("[" + backtick("date '+%Y%m%d:%H%M%S'") + "] power-monitor: " + battery_status)
    if "Discharging" in battery_status:
        percent = int( backtick("acpi -b | awk '{print $4}' | tr -d '%,'"))
        if percent < 5:
            print("power-monitor: check-battery: systemctl hibernate")
            os.system("pkill battery-alarm; sudo systemctl hibernate")
        if percent < 10:
            print("power-monitor: check-battery: 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:

#!/usr/bin/env bash 

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

echo "$0: POWER=$POWER"

case "$POWER" in

        #sudo $( which 01-pm-power-display) true
        sudo $( which brightness ) 20
        sudo $( which 02-pm-power-tweaks) true
        sudo $( which 03-pm-power-hda) true

        sudo powertop --auto-tune
        sleep 3

        #sudo $( which 01-pm-power-display) false
        sudo $( which brightness ) 100
        sudo $( which 02-pm-power-tweaks) false
        sudo $( which 03-pm-power-hda) false

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

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:

#!/usr/bin/env bash
# BH

logger -t $0 "$0 $@"
case "$1" in
    logger -t $0 "power disconnect"
    systemctl stop
    rfkill block bluetooth
    BT_PID=$(ps -ef |grep '[/]usr/libexec/bluetooth/bluetoothd' | awk '{print $2}')
    [[ "$BT_PID" ]] && kill -9 $BT_PID

    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 powersave > /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/devices/*/power/control; do echo auto > $i; done
    iw dev wlp3s0 set power_save on
    logger -t $0 "power connect"
    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 performance > /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/devices/*/power/control; do echo auto > $i; done

    modprobe bluetooth
    rfkill unblock bluetooth

    systemctl start

    modprobe uvcvideo r8169 mii
    iw dev wlp3s0 set power_save off

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.1502931553.txt.gz · Last modified: 2017/08/16 18:59 by admin