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
- DKMS module update is triggered automatically when using apt on Ubuntu
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
- The kernel image (/boot/vmlinuz-linux)
- The system map (/boot/System.map)
- The configuration (/boot/config)
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:
- Kernel Configuration Options - They control which features and modules are included in the kernel binary.
- Sysctl Parameters - Used for adjusting kernel behavior at runtime.
- Kernel Command Line Parameters - Configure the kernel during the boot process. Passed by bootloader and can’t be changed at runtime.
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)
- Set to “Preempt-RT” for hard real-time behavior
- Ensures minimum jitter in response times.
- Reduces context-switching delays.
- real-time tasks can interrupt lower-priority or non-real-time tasks without significant delay
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
- don’t swap unless necessary
- Reduces reliance on swap memory if you have enough RAM.
- may use OOM Killer instead of swapping
- may fail to allocate memory and crash
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)
- Prob improve performance if you have the mem, can cause issues if you don’t.
- Reduces TLB misses, improving memory access speed.
- Pages will be 2MB or higher instead of standard 4kb
- Great for things that use a lot of memory
- Great for databases, VMs and containerized environments
- May cause (or avoid) memory fragmentation
- Might negatively affect latency-sensitive applications
- Can waste memory
- Excessive compaction when searching for pages can increase CPU usage
- Managed by OS
Huge Pages
- Managed by application
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/grubGRUB_CMDLINE_LINUX="elevator=mq-deadline" #
For Legacy Block Layer (Single-Queue)
- noop - A simple, minimal I/O scheduler that passes requests directly with no reordering. Ideal for SSDs or virtualized environments.
- deadline - Prioritizes I/O requests with deadlines to prevent starvation. Good for latency-sensitive applications.
- cfq - (Completely Fair Queuing) Provides fairness across processes and is often used for traditional HDDs. Prioritizes fairness over raw performance.
For Multi-Queue Block Layer (blk-mq)
- mq-deadline - The multi-queue version of the Deadline scheduler. Maintains low latency while ensuring fairness.
- kyber - A lightweight I/O scheduler designed for fast storage devices (e.g., NVMe SSDs). Focuses on low latency and throughput.
- bfq - (Budget Fair Queueing) Provides strict bandwidth and latency guarantees. Best suited for desktop or interactive workloads.
- none - Disables any scheduling. Often used for devices where hardware handles I/O management, like some RAID controllers.
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)
- Disable Unused Features
- Remove unused filesystems (Btrfs, XFS, NTFS, ReiserFS if using only ext4).
- Disable unnecessary drivers (Bluetooth, Sound, USB, Legacy Hardware).
- Disable Support for Legacy Hardware
- Remove Old CPU architectures (i386, MIPS, etc.).
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