Low Orbit Flux Logo 2 F

Linux Kernel Info

Distro Action Update initramfs Update DKMS GRUB Update
Ubuntu update with apt triggered triggered triggered
Ubuntu update with mainline manual manual triggered
Ubuntu manual download dpkg triggered manual triggered
Ubuntu custom build - versioned manual ( usually ) manual manual
Ubuntu custom build - git cloned manual manual manual
Arch update with pacman triggered manual triggered
Arch custom build - versioned manual manual manual
Arch custom build - git cloned manual manual manual

Ubuntu - Upgrade Kernel

Using apt:



uname -r
sudo apt update && sudo apt upgrade
apt list --upgradable | grep linux-image        # check available kernels
sudo apt install --install-recommends linux-generic  # upgrade to latest kenel
sudo reboot
uname -r

Install Latest Mainline Kernel (Bleeding Edge):



sudo add-apt-repository ppa:cappelikan/ppa
sudo apt update
sudo apt install mainline
mainline --list
mainline --install v6.6.1
mainline-gtk               # or use GUI
sudo reboot
uname -r

Update initramfs and DKMS modules for this kernel version:



sudo update-initramfs -c -k 6.6.1

sudo dkms autoinstall -k 6.6.1
dkms status

Manual download ( https://kernel.ubuntu.com/~kernel-ppa/mainline/ ):



wet https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.6.1/amd64/linux-image-6.6.1-xxxx.deb
wget https://kernel.ubuntu.com/~kernel-ppa/mainline/v6.6.1/amd64/linux-headers-6.6.1-xxxx.deb

sudo dpkg -i linux-*.deb
sudo reboot
uname -r

Update DKMS modules for this kernel version:



sudo dkms autoinstall -k 6.6.1
dkms status

Ubuntu - Compile Kernel



uname -r

sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential libncurses-dev bison flex libssl-dev libelf-dev bc

Download from Kernel.org (Recommended for Latest Kernel)



cd /usr/src
sudo wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.1.tar.xz
sudo tar -xf linux-6.6.1.tar.xz
cd linux-6.6.1

Get Ubuntu’s Kernel Source (More Stable)



sudo apt install -y git fakeroot
git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/mainline linux-source
cd linux-source

cat Makefile | grep -E '^VERSION|^PATCHLEVEL|^SUBLEVEL'   # grab kernel version for this latest cloned source
git describe --tags                                       # could also use this if it has tags

Configure:

cp -v /boot/config-$(uname -r) .config # copy old config if using it



make olddefconfig     # Uses old config, applies default values for any new options introduced in the newer kernel version.
make oldconfig        # Uses old config but asks about new options.
make defconfig        # Uses a default minimal config.
make menuconfig       # use interactive menu
make tinyconfig       # minimal config

Can use these together:



make olddefconfig       # get a good config to start
make menuconfig         # customize it

Build:



make -j$(nproc)

Install:



sudo make modules_install
sudo make install

Create new initramfs, update DKMS modules, update GRUB, and reboot:



sudo update-initramfs -c -k 6.6.1
sudo dkms autoinstall -k 6.6.1
sudo update-grub
sudo reboot

Verify:



uname -r

Remove old kernels if you want:



sudo apt remove --purge linux-image-<old-version>
sudo update-grub

Arch Linux - Upgrade Kernel

Use Pacman:



uname -r

sudo pacman -Syu                             # update entire system including kernel

sudo pacman -S linux linux-headers            # update just the kernel and headers
sudo pacman -S linux-lts linux-lts-headers    # for LTS kernel

sudo dkms autoinstall                         # rebuild DKMS modules if used ( need to do manually )

sudo grub-mkconfig -o /boot/grub/grub.cfg     # update grub ( usually automatic but do anyway )

sudo reboot
uname -r

Arch Linux - Compile Kernel



uname -r

sudo pacman -Syu --needed base-devel bc kmod cpio flex bison libelf pahole git

latest stable:



cd /usr/src
sudo git clone --depth=1 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
cd linux

cat Makefile | grep -E '^VERSION|^PATCHLEVEL|^SUBLEVEL'   # grab kernel version for this latest cloned source
git describe --tags                                       # could also use this if it has tags


OR specific version:



sudo wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.7.tar.xz
sudo tar -xvf linux-6.7.tar.xz
cd linux-6.7

Use current kernel’s config as a base:



zcat /proc/config.gz > .config

make olddefconfig     # Uses old config, applies default values for any new options introduced in the newer kernel version.
make oldconfig        # Uses old config but asks about new options.
make defconfig        # Uses a default minimal config.
make menuconfig       # use interactive menu
make tinyconfig       # minimal config

Can use these together:



make olddefconfig       # get a good config to start
make menuconfig         # customize it

Build:



make -j$(nproc)

Install:



make modules_install
sudo make install

Update the initramfs, update DKMS modules, update GRUB, and reboot:



sudo mkinitcpio -P
sudo dkms autoinstall
sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo reboot

Reboot:



uname -r

Kernel Configuration Options – Common settings for a custom kernel

Types of options/parameters:

CPU and More

Some CPU settings:



CONFIG_SCHED_CORE=y         # Enable Multi-core Scheduling - Improves performance in multi-threaded workloads.
CONFIG_HZ_1000=y            # High Timer Frequency - Increase timer tick rate to 1000Hz for finer time granularity
CONFIG_NO_HZ=n              # Disable Dynamic Ticks (NO_HZ) - Ensures consistent CPU cycles by avoiding tickless idle states
CONFIG_CPU_FREQ=n           # Disable CPU Frequency Scaling to lock CPU speed to max performance
CONFIG_PM_ADVANCED_DEBUG=n  # Disables power debugging features to save CPU cycles

Fully Preemptible Kernel (RT)



CONFIG_PREEMPT_RT_FULL=y    # full real time patchs for max RT performance
CONFIG_PREEMPT_RT=y         # enable real time premption
CONFIG_PREEMPT_VOLUNTARY=y  # only voluntary premption
CONFIG_PREEMPT=y            # General preemption without full real-time guarantees

Memory Management Tweaks

Swappiness



CONFIG_SWAP=n     Disable Swappiness

Enable HugePages / Transparent Huge Pages (THP)



CONFIG_TRANSPARENT_HUGEPAGE=y

Configure in runtime:



echo always > /sys/kernel/mm/transparent_hugepage/enabled

Transparent Huge Pages (THP)

Huge Pages

Network

Distributes network packets across CPU cores to reduce bottlenecks.



CONFIG_RPS=y    # Receive Packet Steering (RPS) - distribute packets to mulitple CPU cores
CONFIG_RFS=y    # Receive Flow Steering (RFS) - match to core with relevant app

CONFIG_NETWORK_PHY_TIMESTAMPING=y   # Enable High-Resolution Timestamps for precise latency measurements

Kernel IO Scheduler

Enable schedulers:



CONFIG_IOSCHED_DEADLINE=y         # enable deadline IO scheduler, Avoid CFQ, which prioritizes fairness over speed. For time-sensitive applications and predictable I/O.
CONFIG_IOSCHED_NOOP=y
CONFIG_IOSCHED_CFQ=y
CONFIG_MQ_IOSCHED_DEADLINE=y      # when Multi-Queue Block I/O Layer (blk-mq) is enabled ( default for new systems )
CONFIG_MQ_IOSCHED_KYBER=y
CONFIG_MQ_IOSCHED_BFQ=y

CONFIG_DEFAULT_IOSCHED="noop"     # change default ( for Single-Queue NOT blk-mq )

Change default IO scheduler for blk-mq ( kernel param, can’t do at compile time ):

/etc/default/grub
GRUB_CMDLINE_LINUX="elevator=mq-deadline" #

For Legacy Block Layer (Single-Queue)

For Multi-Queue Block Layer (blk-mq)

Disk



CONFIG_NVME_MULTIPATH=y     # For enterprise SSDs

Security Enhancements



CONFIG_STACKPROTECTOR_STRONG=y   # Enable StackProtector, Hardens against buffer overflow attacks.
CONFIG_SECURITY_APPARMOR=y       # Enable AppArmor
CONFIG_SECURITY_SELINUX=y        # Enable SELinux
CONFIG_HARDENED_USERCOPY=y       # Enable Hardened Usercopy

Reducing Bloat (Minimal Kernel)



CONFIG_BLK_DEV_FD=n    # remove floppy disk support
CONFIG_DEBUG_KERNEL=n  # disable debugging
CONFIG_DEBUG_INFO=n    # disable debugging
CONFIG_KGDB=n          # disable kernel debugger