Skip to content

Instantly share code, notes, and snippets.

@themagicalmammal
Last active November 5, 2024 13:23
Show Gist options
  • Save themagicalmammal/e443d3c5440d566f8206e5b957ab1493 to your computer and use it in GitHub Desktop.
Save themagicalmammal/e443d3c5440d566f8206e5b957ab1493 to your computer and use it in GitHub Desktop.
Set of optimizations, I use on my Void Setup

Index

1. Gummiboot

If you know about systemd-boot you know what this is. Systemd-boot was known as gummiboot before systemd made a d*** move and integrated it with itself, gummiboot is pretty minimal and fast. You can install this instead of grub while installing void or you can replace your grub with it.
To do so you have to follow some steps,

  1. Get gummiboot
sudo xbps-install gummiboot
  1. Check if your efi partition has boot and esp flags, you can do this with gparted, if these flags are not there then add them or use parted to manually add flags (boot, esp).
  2. If your fstab(/etc/fstab) mounts efi partition to /boot/efi change it to /boot and then reboot.
  3. Then install gummiboot to efi partition
sudo gummiboot install
  1. Add Kernel Options
sudo nano /boot/loader/void-options.conf

Then use your options, which might look something like this

root=/dev/sda2 ro loglevel=0 console=tty2 udev.log_level=0 vt.global_cursor_default=0 mitigations=off nowatchdog msr.allow_writes=on pcie_aspm=force module.sig_unenforce intel_idle.max_cstate=1 cryptomgr.notests initcall_debug intel_iommu=igfx_off no_timer_check noreplace-smp page_alloc.shuffle=1 rcupdate.rcu_expedited=1 tsc=reliable resume=UUID=0b27b94d-1f89-4772-aca2-977b62544472

I have set it to sda2 because that is my root and use resume and UUID of your root, either look in your fstab or get it thought blkid

  1. Reconfigure your kernel
sudo xbps-reconfigure -f linux<kernel_version>

Note: To find your Linux kernel version, you can use

sudo xbps-query -l | grep linux
  1. If everything works boot entry "Linux Boot Manager" should work then you can remove grub too.

2. Silent GRUB

If you prefer to use grub over gummiboot you can use this. To hide all the grub output which is displayed during boot.
Copy these parameters to GRUB_CMDLINE_LINUX_DEFAULT, then update the grub

loglevel=0 console=tty2 udev.log_level=0 vt.global_cursor_default==0

The above will esentially hide kernel logs and put them in tty2. But still, there are some messages that can be hidden like "Welcome to GRUB!" which can be removed by this. Also, you can hide booting messages by going to

sudo nano /boot/grub/grub.cfg

And here you can remove all the echo messages. Remember this resets everytime grub is updated This provides a clean-looking boot, which I prefer.

3. Turn off Mitigations

You can turn off CPU mitigations for the highest performance, but least security. If you run a lot of unknown code, then you should skip this. To learn how this affects your pc, go here. To know what kind of vulnerability might arise, you can go here
To enable this, add this to GRUB_CMDLINE_LINUX_DEFAULT, then update the grub

mitigations=off

4. Disable Watchdog

Watchdog is used to monitor if a system is running. It is supposed to automatically reboot hanged systems due to unrecoverable software errors. Personal computer users don’t need a watchdog, as they can reset the system manually. You can learn more about this from here
To enable this, add this to GRUB_CMDLINE_LINUX_DEFAULT, then update the grub

nowatchdog

5. Kernel Parameters

These are some kernel parameters that boost my computer, most of them optimizations are from Clear Linux. These basically disables some checks on boot time, making it faster. You can add your parameters to optimize for your hardware.

intel_idle.max_cstate=1 cryptomgr.notests initcall_debug intel_iommu=igfx_off no_timer_check noreplace-smp page_alloc.shuffle=1 rcupdate.rcu_expedited=1 tsc=reliable

This is what my GRUB looks like after adding the parameters

#
# Configuration file for GRUB.
#
GRUB_DEFAULT=0
GRUB_TIMEOUT=0
GRUB_CMDLINE_LINUX_DEFAULT="loglevel=0 console=tty2 udev.log_level=0 vt.global_cursor_default=0 mitigations=off nowatchdog msr.allow_writes=on pcie_aspm=force module.sig_unenforce intel_idle.max_cstate=1 cryptomgr.notests initcall_debug intel_iommu=igfx_off no_timer_check noreplace-smp page_alloc.shuffle=1 rcupdate.rcu_expedited=1 tsc=reliable resume=UUID=b6063c20-d091-4334-8726-55e0ee6b0aed"
GRUB_DISABLE_OS_PROBER=true
GRUB_DISABLE_RECOVERY=true
GRUB_DISABLE_SUBMENU=true

6. Fstab Modification

Disable File System Check(FSCK)

In Linux, when a file system is mounted for certain times, or its last fsck was more than certain days ago, the system will perform fsck on it when the server reboots. The fsck process can take a few minutes to hours to finish, depending on the file system size. This is more useful on a server machine than a personal computer.
To remove the checks

sudo nano /etc/fstab 

Example:

UUID=f634ad84-2283-4c62-b1ab-d57718e64cbb swap swap sw 0 0
UUID=5c24bcde-e284-457d-b1e1-5845e0e77fb8 / xfs defaults 0 0
UUID=C61D-2685 /boot vfat umask=0077 0 0
tmpfs /tmp tmpfs defaults,nosuid 0 0

The 2 at the end of the first line and 1 at the end of the last line will disable checks for my /boot and my / partition.

Use Noatime instead of Defaults

Turning off atime is a small but effective way to improve system performance. One tweak is atime, which is one of the three timestamps on every file on Linux (more on that later). Since atime is updated every time the file is accessed, my understanding was that it had a significant impact on system performance.
So, get rid of defaults for noatime

sudo nano /etc/fstab 

Example:

UUID=f634ad84-2283-4c62-b1ab-d57718e64cbb swap swap sw 0 0
UUID=5c24bcde-e284-457d-b1e1-5845e0e77fb8 / xfs noatime 0 0
UUID=C61D-2685 /boot vfat umask=0077 0 0
tmpfs /tmp tmpfs noatime,nosuid 0 0

7. Optimizing Boot

This is to optimise your initram basically removing things that you don't want in it and making it faster.

  1. Configure to host only
sudo nano /etc/dracut.conf.d/boot.conf

Add this to the file

hostonly=yes
hostonly_cmdline=no
use_fstab=yes
compress="cat"
omit_dracutmodules+=" dash i18n rpmversion convertfs btrfs lvm qemu multipath qemu-net lunmask fstab-sys terminfo securityfs img-lib biosdevname caps crypt crypt-gpg dmraid dmsquash-live mdraid nbd nfs network "
nofscks=yes
no_hostonly_commandline=yes
  1. Reconfigure your kernel, according your kernel name
sudo xbps-reconfigure -f linux<kernel_version>

Note: To find your Linux kernel version, you can use

sudo xbps-query -l | grep linux

Tip: You can use rEFInd instead of grub if you are not using XFS file system and might find it faster.

8. Fix bad font rendering

Font rendering is a issue in lot of apps in Void one of the most popular being Firefox. The easiest way to fix it is (Void Handbook)

sudo ln -s /usr/share/fontconfig/conf.avail/70-no-bitmaps.conf /etc/fonts/conf.d/
sudo xbps-reconfigure -f fontconfig

9. Getting rid of unnecessary packages

Getting rid of some core packages Example: If you are using btrfs remove xfsprogs instead and if you are using ext4 you can get rid of both
Add this to the file

sudo nano /etc/xbps.d/99-ignore.conf
ignorepkg=btrfs-progs

Then remove btrfs-progs

sudo xbps-remove -Rcon btrfs-progs

Just like this, there are some other core packages I removed which doesn't get used in my pc. Please be sure of what you are doing if you don't want to break your system.

ignorepkg=btrfs-progs
ignorepkg=f2fs-tools
ignorepkg=ipw2100-firmware
ignorepkg=ipw2200-firmware
ignorepkg=linux-firmware-amd
ignorepkg=linux-firmware-broadcom
ignorepkg=mobile-broadband-provider-info
ignorepkg=nvi
ignorepkg=openssh
ignorepkg=os-prober
ignorepkg=rtkit
ignorepkg=void-artwork
ignorepkg=xbacklight
ignorepkg=xf86-input-wacom
ignorepkg=xf86-video-amdgpu
ignorepkg=xf86-video-fbdev
ignorepkg=xf86-video-nouveau
ignorepkg=xf86-video-vesa
ignorepkg=xf86-video-vmware
ignorepkg=zd1211-firmware
ignorepk

Plasma Specific

ignorepkg=ksystemstats
ignorepkg=oxygen
ignorepkg=plasma-systemmonitor
ignorepkg=plasma-thunderbolt
ignorepkg=plasma-workspace-wallpapers
sudo xbps-remove -Rcon f2fs-tools ipw2100-firmware ipw2200-firmware ksystemstats linux-firmware-amd linux-firmware-broadcom mobile-broadband-provider-info nvi openssh os-prober oxygen plasma-systemmonitor plasma-thunderbolt plasma-workspace-wallpapers rtkit void-artwork xbacklight xf86-input-wacom xf86-video-amdgpu xf86-video-fbdev xf86-video-nouveau xf86-video-vesa xf86-video-vmware

Some other packages that I remove

sudo xbps-remove -Rcon lvm2 cryptsetup micro rsync ntfs-3g vim AppStream appstream-glib flatpak xdg-desktop-portal-gtk gnome-keyring dialog grub-i386-efi inetutils accounts-integration kaccounts-providers kwrite ntp octoxbps p7zip topgrade vdpauinfo void-repo-multilib xterm

Note : Somethings are specific to plasma desktop here.

10. Xorg Config(iGPU)

While using your pc you might find screen tears or graphical bugs, to fix them you need to create a config file

sudo mkdir /etc/X11/xorg.conf.d
sudo nano /etc/X11/xorg.conf.d/20-intel.conf

Place this inside it

Section "Device"
        Identifier      "Intel Graphics"
        Driver          "Intel"
        Option          "AccelMethod"           "sna"
        Option          "TearFree"              "True"
EndSection

Note: Please crosscheck this before you use it because this may not be correct for you & might make your Xorg crash.
Note: If your Xorg crashed try commenting some lines under Option & that might fix your issue but if it doesn't just remove the file.

11. Intel Graphic Parameters

These are specific parameters that I use on my setup to boost my intel graphic card, these were picked from the arch wiki according to my hardware specs. You need to go through the wiki to check if the same or other parameters apply to you.

sudo nano /etc/modprobe.d/i915.conf

Place this inside it

options i915 enable_guc=2 enable_dc=4 enable_hangcheck=0 error_capture=0 enable_dp_mst=0 fastboot=1 #parameters may differ

Note: Options maybe specific for my graphics card so please do crosscheck if you apply anyway and display crashes just remove this file and restart. You need to reconfigure your kernel according to these changes.

sudo xbps-reconfigure -f linux<kernel_version>

Note: To find your linux kernel version, you can use

sudo xbps-query -l | grep linux

Note: Please be sure of what you do because this is risky & might give you a complete OS crash.

12. NVIDIA

Way to install NVIDIA Drivers

  1. Install Non-Free Repo
sudo xbps-install void-repo-nonfree
  1. Install NVIDIA Driver
sudo xbps-install nvidia #(use nvidia390 is your model is of 400/500 series) 
  1. Copy the Xorg file, then reboot
wget https://raw.githubusercontent.com/uditkarode/dots/master/xorg/xorg.conf
sudo mv xorg.conf /etc/X11/
  1. Check if NVIDIA is working
glxinfo
prime-run glxinfo #should have different output from glxinfo

13. Bumblebee

For better battery backup you can install bumblebee which enables smart power management of the NVIDIA GPU & bbswitch to automatically turn off the Nvidia GPU whenever it's not in use.

  1. Install bumblebee, complete the user mod instructions
sudo xbps-install bumblebee 
sudo usermod -a -G bumblebee <username>
sudo ln -sfv /etc/sv/bumblebeed /var/service/
  1. Install bbswitch, then reboot
sudo xbps-install bbswitch
  1. Check bbswitch, should be OFF
cat /proc/acpi/bbswitch

14. Backlight

The brightness value does not get saved when the system reboots, to fix that you have to get it from here & enable it.

git clone https://github.com/madand/runit-services
cd runit-services
sudo mv backlight /etc/sv/
sudo ln -s /etc/sv/backlight /var/service/

PSD is a service that symlinks & syncs browser profile directories to RAM, thus reducing HDD/SSD calls & speeding up browsers.
You can get it from here. This helps Firefox & Chromium reduce ram usage.

git clone https://github.com/graysky2/profile-sync-daemon
cd profile-sync-daemon
make
sudo make install
sudo rm -rf /usr/lib/systemd/
cd
git clone https://github.com/madand/runit-services
cd runit-services
sudo mv psd /etc/sv/
sudo ln -s /etc/sv/psd /var/service/

Note: Make sure you have all of the build tools. Note: rsyncd should also be enabled.

16. Colord

Colord is a system service that makes it easy to manage, install & generate color profiles to accurately color manage input & output devices. You can get it from

sudo xbps-install colord colord-kde gnome-color-manager #I am using kde a thats why I need colord-kde
sudo ln -sfv /etc/sv/colord /var/service/

Irqbalance is a daemon that monitors the cpu load created by various interrupt sources and attempts to distribute that load over the available cpus in your system in an attempt to better balance system latency and throughput.

sudo xbps-install irqbalance
sudo ln -sfv /etc/sv/irqbalance /var/service/

Ananicy (ANother Auto NICe daemon) — is a shell daemon created to manage processes' IO and CPU priorities, with community-driven set of rules for popular applications.

git clone https://github.com/Nefelim4ag/Ananicy.git
cd Ananicy 
sudo make install 
sudo rm -rf /lib/systemd
sudo mkdir /etc/sv/ananicy 
sudo nano /etc/sv/ananicy/run

Paste this,

#!/bin/sh
exec /usr/bin/ananicy start

Then,

sudo nano /etc/sv/ananicy/finish

Paste this,

#!/bin/sh
exec /sbin/sysctl -e kernel.sched_autogroup_enabled=1

Then,

sudo ln -sfv /etc/sv/ananicy /var/service

19. EarlyOOM (OOM-killer)

EarlyOOM checks the amount of available memory & swap periodically & kills memory according to the set pre-configured value. You can get it from

sudo xbps-install earlyoom
sudo ln -sfv /etc/sv/earlyoom /var/service/

To set values, do this

sudo nano /etc/default/earlyoom

Set the EARLYOOM_ARGS to this value

EARLYOOM_ARGS=" -m 96,92 -s 99,99 -r 5 -n --avoid '(^|/)(runit|Xorg|sshd)$'"

You can also experiment with this, I have set this according to my personal preference.

Thermald is a Linux daemon used to prevent the overheating of platforms. This daemon monitors temperature & applies compensation using available cooling methods. You only need this if your pc heats and can't manage its heating internally. You can get it from

sudo xbps-install thermald
sudo ln -sfv /etc/sv/thermald /var/service/

Preload is an ‘Adaptive read-ahead Damon’ which effectively what it does speeds up application load time by monitoring the software that is loaded & used day-to-day, the software used most often, & cache them in memory. This is only useful for HDD(s). You can get it from

sudo xbps-install preload
sudo ln -sfv /etc/sv/preload /var/service/

22. Power saving

1. TLP

TLP is a feature-rich command line utility for Linux, saving laptop battery power without the need to delve deeper into technical details. You can get it from

sudo xbps-install tlp
sudo ln -sfv /etc/sv/tlp /var/service/

To configure it do this

sudo nano /etc/tlp.conf

It's pretty simple to configure. You can leave it as is and you would get a amazing battery life.

PowerTop is a software utility designed to measure, explain & minimize a computer's electrical power consumption. You can also use powertop instead of TLP or with it, which won't have much significant impact if you use powertop with it. This is a alternative to TLP. So, I use this to add stuff from it in my rc.local of the stuff which isn't optimised by tlp. You can get it from

sudo xbps-install powertop

then enable it with (instead of tlp)

powertop --auto-tune

inside /etc/rc.local
Note: If you use powertop or scripts, you also have to use

echo 60000 > /sys/bus/usb/devices/2-1.5/power/autosuspend_delay_ms
echo 60000 > /sys/bus/usb/devices/2-1.6/power/autosuspend_delay_ms
echo 60000 > /sys/bus/usb/devices/3-1.5/power/autosuspend_delay_ms
echo 60000 > /sys/bus/usb/devices/3-1.6/power/autosuspend_delay_ms
echo 60000 > /sys/bus/usb/devices/4-1.5/power/autosuspend_delay_ms
echo 60000 > /sys/bus/usb/devices/4-1.6/power/autosuspend_delay_ms

The auto suspend timer needs to higher or your external mouse/keyboard may go to sleep again & again which is very annoying adding this line increases the auto suspend counter.

23. Intel Undervolt

Intel-Undervolt is a tool for undervolting & throttling limits alteration for Intel CPUs. So, we reduce some of the power that is going to our cpu/gpu/cpu-cache.... which results in less battery consumption & less heating, but you have to be sure that it's not too less because otherwise, your system will crash since it's not getting enough power to work. It might reduce your fps because it esentially reduces some extra power and might also reduce some performance which is not a lot but still you should thing before acting into it. This is not bad for hardware, but you should be sure about what you are doing. You can get it from

sudo xbps-install intel-undervolt

Then change it's config

sudo nano /etc/intel-undervolt.conf
sudo intel-undervolt apply

My current under volt config is here.
Also, you need to create a runit service to run it on boot. Do this

sudo mkdir /etc/sv/intel-undervolt
sudo nano /etc/sv/intel-undervolt/run

Put this code inside

#!/bin/sh
intel-undervolt apply >/dev/null 2>&1
exec chpst -b intel-undervolt pause

Then,

sudo chmod +x /etc/sv/intel-undervolt/run
sudo ln -sfv /etc/sv/intel-undervolt /var/service/

24. Intel's Microcode

Intel microcode is microcode that runs inside x86 processors made by Intel. Since the P6 microarchitecture introduced in the mid-1990s, the microcode programs can be patched by the operating system or BIOS firmware to workaround bugs found in the CPU after release.

Install Non-Free Repo

sudo xbps-install void-repo-nonfree

Steps to get it working

sudo xbps-install intel-ucode #You need non-free repo

Reconfigure your kernel, according your kernel name

sudo xbps-reconfigure -f linux<kernel_version>

Note: To find your Linux kernel version, you can use

sudo xbps-query -l | grep linux

25. Bash Alias

Instead of writing full commands, you can use keywords, which can save a significant amount of your work. I am currently using this.
Alias: Bash Zsh

@akhiljalagam
Copy link

thanks for backlight, noatime and nowatchdog

@slightly-seasoned
Copy link

Thanks for this. The descriptions of the optimizations are easy to read and very straightforward.

@rilysh
Copy link

rilysh commented Dec 28, 2022

At silent-grub instead of editing grub.cfg in the boot directory, you can edit /etc/default/grub file and run update-grub.

Each time you issue update-grub or update the grub or the kernel through the package manager, it will overwrite the previous configuration in /boot/grub/grub.cfg.

@themagicalmammal
Copy link
Author

At silent-grub instead of editing grub.cfg in the boot directory, you can edit /etc/default/grub file and run update-grub.

Each time you issue update-grub or update the grub or the kernel through the package manager, it will overwrite the previous configuration in /boot/grub/grub.cfg.

I have written that in bold just below it. I think I was unable to find ways to remove "Welcome to GRUB!" message, so the alternative as written on it, is using the grub-shusher.

@mindmix703
Copy link

Thank you very much. Useful, accessible, concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment