Improve Battery & Optimize Your Linux Laptop


This is for people who want to improve battery life and optimize their laptop without compromise on Linux.


Kernel & Drivers


Kernel

Picking what kernel to use (Mainline or LTS).

Mainline will have better performance and battery life because it’s more updated, especially on newer hardware.

LTS will be more stable and reliable, you may also find it works better on older hardware.

  • Distributions already choose the kernel for you, but if there isn’t an official way of changing the kernel, don’t worry because the developers know what they are doing better than you or me.

Drivers

Intel or AMD GPUs shouldn’t need to install anything because the kernel already has the drivers.

Your laptop might have two GPUs, if it does, you should use PRIME GPU switching to switch to your iGPU when you don’t plan to use your laptop for heavy GPU workloads like gaming or video editing.

NVIDIA GPU users should install the proprietary driver from their distribution’s repository.

Refer to the links below for installing the NVIDIA driver, if your distribution isn’t linked, Google how to install it.

  • Do not install from NVIDIA directly because it will cause stability issues.
  • Proprietary driver will offer better performance and battery life than the open-source one, this might change soon.

Hardware Video Acceleration


Hardware video acceleration uses the GPU for decoding and encoding video, so the benefits are less power draw, a quieter laptop and better battery life.

Installing The Codecs For Your GPU

You’ll need to install the codecs for your GPU, some distributions already have them pre-installed.

Distributions might not have codecs pre-installed or disabled some codecs because of legal reasons, and Fedora Linux is one of them.

Below, I’ve left a list from the ArchWiki that shows what codecs to install for what GPU, these rules apply to every distribution not just Arch Linux.

  • Package names might be slightly different for your distribution.
  • Flatpak and Snap apps should have the codecs bundled in, so you won’t need to install the codecs from your distribution.
  • Fedora Linux provides a way to install missing codecs like H.264, if your distribution is missing codecs they might provide a way of installing them.

Configuring Your Browser

Enable video hardware acceleration in your browser and any app that you use.

Refer to these links, also if your browser is a derivative of these, the settings should be the same.

Unsupported VP9 Codec

Your GPU might not support VP9, so YouTube might make your fans spin up because video hardware acceleration isn’t working.

Installing the linked extension for your browser, will make the problem go away!

Sleep / Suspend


Sleep Modes

Laptops have one or both sleep modes, those being S3 Sleep and (S0ix or “Modern Standby”).

  • For older laptops, you’ll want to use S3.
  • Newer laptops will support S0ix, but might also support S3 Sleep.

S0ix Sleep mode gets hate because of the way Windows handles it. Issues are laptop heating and low battery when you need to use the laptop, this is because Windows run back round processes. Linux doesn’t have this issue and will suspend everything.

What Sleep Mode To Use

It’s recommended to use S0ix Sleep because it causes fewer difficulties than S3 Sleep on Linux.

Check your BIOS sometimes there is a setting to switch between S3 Sleep and S0ix Sleep, otherwise, Google if your laptop supports this sleep mode.

For switching the sleep mode inside Linux, run cat /sys/power/mem_sleep inside terminal.

You’ll see an output of “Deep” and or “S2idle“, “Deep” means S3 Sleep. So “S2idle” means S0ix sleep.

Once you confirmed that your laptop supports S0ix make sure it’s enabled, otherwise you can switch to s2idle with the “mem_sleep_default=s2idle" kernel parameter and reboot.

Older laptops possibly won’t support S0ix, so I recommend running cat /sys/power/mem_sleep in terminal and making sure “Deep” is enabled, otherwise set the “mem_sleep_default=deep kernel parameter and reboot.

  • MacBook users running Fedora Linux might not have suspend working properly, check out my fix.

SSD TRIM & HDD Defragmentation


Encryption, TRIM & HDD Fragmentation

If you have an HDD everything is done for you, skip this whole section.

FSTRIM is enabled and works automatically on most distributions, check by running systemctl status fstrim.timer in terminal, but if it’s not Google how to enable it for your distribution.

Your encrypted installation might not have FSTRIM working however this is fixable at the risk of a security issue, depending on your threat model this shouldn’t cause issues.

Check your encrypted installation has working TRIM, run lsblk in terminal to see where the encrypted partition is located.

Once found, run sudo cryptsetup luksDump /dev/your-partiton | grep Flags to check if there is an “allow-discards” flag set.

For setting the flag you need to copy “luks-000000-0000-0000-0000-0000000000” from the lsblk command, and run sudo cryptsetup –allow-discards –persistent refresh luks-000000-0000-0000-0000-0000000000.

That will enable “allow-discards“, now you’ll have working TRIM.

CPU Power Management


  • Most distributions that use GNOME or KDE will have this.
  • I won’t show how to disable CPU turbo boosting feature because I think slowing down the CPU is a compromise.

Check your distribution has CPU power management, run systemctl status power-profiles-daemon in terminal, if it’s running, you can pick power settings from GNOME or KDE; Otherwise enable it by running systemctl enable power-profiles-daemon and rebooting.

  • You might need to install CPU Power Management, Google how to install power-profiles-daemon for your distribution.

PowerTop


PowerTop is a power saving utility developed by Intel, it will disable PCIe and USB devices when not in use.

Start by installing PowerTop, the package name is most likely “powertop” however if it’s not, Google instructions on how to install it for your distribution.

We will make a systemd service file to enable PowerTop automatically.

Run sudo nano /etc/systemd/system/powertop.service in terminal.

Copy and paste the configuration below.

[Unit]
Description=Powertop tunings

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/powertop --auto-tune

[Install]
WantedBy=multi-user.target

Once you made the service file, run sudo systemctl enable –now powertop.service.

Your laptop is ready to reboot.

Now you have a laptop that’s optimized!

Leave a Comment

Your email address will not be published. Required fields are marked *