Giter Site home page Giter Site logo

linux-powersave-scripts's Introduction

Scripts for controlling power on (Intel) Linux laptops

(credit to Maythux and Ventto)

I have an Acer Nitro 5 (AN515-53) running Arch Linux:

Having not opted to use any proper desktop environment, having some form of battery notification and power saving mechanism would have been great!

If there is any better way to do this, please tell me!!!

The sadness

There's a script that utilizes notify-send to send notifications about your batteries state: batify

However, this script relies entirely on your laptop actually sending the battery status to udev. Which mine does not.

For power-saving, a thing I wanted to do was to underclock my machine when the charger was unplugged. If I was to do anything intensive, I'd be plugged in anyways.

However, the intel_pstate driver would have said otherwise, likely because of how my laptop is.

This meant that I couldn't easily just call cpupower to change the governor from powersave to performance and vice-versa, as it did little to nothing.

For this to properly work, I'd have to set each thread to allow turbo boost. I had found a script to do so at this AskUbuntu thread, and tweaked it to forcefully enable turbo after setting each thread.

To make matters funnier, hibernating within udev usually either put the machine to sleep, caused systemd-networkd to fuck off upon restore, and took too damn long.

This is a hacky solution, but it is what works for me, hence I'm publishing it here.

Installation

This entirely assumes you use systemd as your init daemon, that you use mkinitcpio to create your initrd.img, and that your CPU is from Intel and above like 6th gen or something.

  • Install cpupower, msr-tools, and xpub. xpub will allow our script to send notifications to our X session.
  • Include msr in your initrd's MODULES (in /etc/mkinitcpio.conf for mkinitcpio).
  • Tweak capacity and charger in battery-check.py to match your laptop's battery and AC jack. You can also tweak the threshold for each notification, and eventual hibernation.
  • Edit the path to battery-check.py in the battery-check.service unit file.
  • Edit the path to turboctl.sh in both udev rules in rules.d/.
  • Copy battery-check.service to /etc/systemd/system.
  • Enable and start battery-check.service.
  • Reboot your system to fully initialize the new udev rules.

Enabling hibernation

This was something that I ended up struggling with for a bit.

You cannot use a swap file in this case.

  • Resize your root partition to allow space for a 2nd swap partition.
  • Turn your existing swap off, and delete it.
  • Create 2 partitions, both according to your system memory size + 2G.
  • Set them as swap, and write the partition table.
  • Turn both swap partitions on, and add them to /etc/fstab.
  • Edit your kernel cmdline to include resume=<devicepath> (<devicepath> can be either a device file (/dev/sda6) or a UUID (UUID=ffffffff-ffff-ffff-ffff-ffffffffffff)).
  • Reboot.

linux-powersave-scripts's People

Contributors

samicrusader avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.