The kernel version is controlled by the EXTRAVERSION variable in the Makefile and CONFIG_LOCALVERSION in your config.
cd /usr/src/linux
# Edit .config and find/add this line:
CONFIG_LOCALVERSION="-custom"
# Or use menuconfig:
make menuconfig
# Navigate to: General setup --> Local version - append to kernel release
# Enter: -custom (or -latest, -untested, etc.)# At the top of the Makefile you'll see:
VERSION = 6
PATCHLEVEL = 12
SUBLEVEL = 6
EXTRAVERSION =
# Change EXTRAVERSION to:
EXTRAVERSION = -customFor your learning process, I recommend this progression:
- 6.12.6 (your current working kernel - KEEP THIS)
- 6.12.6-v2 (first optimization attempt)
- 6.12.6-v3 (further refinements)
- 6.12.6-stripped (when you've removed lots of stuff)
- 6.12.6-final (when you're happy with it)
Or use dates:
- 6.12.6-20241220 (today's build)
- 6.12.6-20241221 (tomorrow's build)
cd /usr/src/linux
# 1. Set the version name
make menuconfig
# Set Local version to: -v2
# 2. Build
make -j4 2>&1 | tee build.log # 4 cores = -j4
make modules -j4
# 3. Install (this creates versioned directories automatically)
sudo make modules_install # Creates /lib/modules/6.12.6-v2/
sudo make install # Creates /boot/vmlinuz-6.12.6-v2
# 4. Update bootloader
sudo update-grub # Debian/Ubuntu
# or
sudo grub-mkconfig -o /boot/grub/grub.cfg # Other distros# List installed kernels
ls -lh /boot/vmlinuz-*
ls /lib/modules/
# Current running kernel
uname -r
# Remove old kernel (BE CAREFUL!)
sudo apt remove linux-image-6.12.6-v2 # If installed via package
# or manually:
sudo rm /boot/vmlinuz-6.12.6-v2
sudo rm /boot/initrd.img-6.12.6-v2
sudo rm /boot/config-6.12.6-v2
sudo rm /boot/System.map-6.12.6-v2
sudo rm -rf /lib/modules/6.12.6-v2/
sudo update-grubYour GRUB menu will automatically list all kernels. To choose at boot:
- Reboot
- Press ESC/Shift during boot to see GRUB menu
- Select "Advanced options"
- Choose your kernel
To set default kernel:
# Edit /etc/default/grub
sudo nano /etc/default/grub
# Find and modify:
GRUB_DEFAULT=0 # First kernel in list
# or
GRUB_DEFAULT="Advanced options for Debian GNU/Linux>Debian GNU/Linux, with Linux 6.12.6"
# Apply changes
sudo update-grubBased on your lspci and lsmod output, here's what you have:
- CPU: Intel Core i5-4460 (Haswell, 4 cores, 3.2GHz base, 3.4GHz boost)
- GPU: Intel HD Graphics (integrated, i915 driver)
- Ethernet: Realtek RTL8111 (r8169 driver)
- Audio: Intel HD Audio
- Storage: SATA via Intel AHCI controller
- USB: XHCI (USB 3.0) and EHCI (USB 2.0) controllers
- Chipset: Intel H97
- No WiFi, no Bluetooth, no discrete GPU
# Your modules have debug info:
$ file /lib/modules/6.12.6/kernel/drivers/net/ethernet/realtek/r8169.ko
... with debug_info, not stripped
# Debian's don't:
$ file /lib/modules/6.1.0-41-amd64/kernel/drivers/net/ethernet/realtek/r8169.ko
... not stripped (but no debug_info!)This is why your modules are 515M vs Debian's 395M!
Fix in .config:
CONFIG_DEBUG_INFO=n
CONFIG_DEBUG_INFO_NONE=y
CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT=n
CONFIG_DEBUG_KERNEL=n
Or in menuconfig:
Kernel hacking -->
Compile-time checks and compiler options -->
[ ] Compile the kernel with debug info # DISABLE THIS
Many of these are networking/firewall modules you may not need.
cd /usr/src/linux
cp /boot/config-6.12.6 .config
make menuconfig- Set Local version:
-v2 - Kernel compression: Change to ZSTD (faster boot than XZ)
- DISABLE: Auditing support (unless you need SELinux/AppArmor auditing)
- Control groups: Keep (needed by systemd)
- initramfs support: Keep enabled
- Processor family: Change from generic to
Core 2/newer Xeon- Location: Processor type --> Processor family
- Your Haswell i5 is covered by this option
- Maximum number of CPUs: Change from 512/1024 to
4- You have exactly 4 cores, no hyperthreading
- SMT (Hyperthreading): Disable (you don't have it - Model 60, 1 thread per core)
- Preemption Model: Select
Preemptible Kernel (Low-Latency Desktop) - Timer frequency: Select
1000 HZ - NUMA: Disable (single socket system)
- DISABLE: CPU microcode loading facility (you can use fwupd in userspace instead)
- CPU Frequency scaling: Keep enabled
- ACPI: Keep
- CPU Frequency scaling: Keep
- CPU idle: Keep
- Suspend to RAM: Keep if you use it
- Hibernate: Keep if you use it
- PCI support: Keep
- PCI Express hotplug: Probably disable
- DISABLE: CardBus support
- DISABLE: PCMCIA support
You have extensive netfilter/iptables modules loaded. If you don't run a firewall:
- Consider disabling or building as modules:
- Netfilter (iptables/nftables) - but keep if you use a firewall
- Bridge support - disable unless you use VMs/containers
- 802.1Q VLAN - disable unless needed
Keep enabled:
- TCP/IP networking
- Unix domain sockets
- IPv6 (or disable if you really don't use it)
Definitely disable:
- Amateur Radio support
- IrDA subsystem
- Bluetooth (you don't have it)
- Wireless (you don't have WiFi)
- NFC
- Old protocols: IPX, AppleTalk, etc.
Device Drivers -->
Graphics support -->
[*] /dev/agpgart (AGP Support) # Keep for Intel
[M] Intel 8xx/9xx/G3x/G4x/HD Graphics # i915
[*] Enable modesetting on intel by default
[*] Enable Intel GVT-g graphics virtualization host support # Disable unless you use VMs
DISABLE all of these GPU drivers:
- ATI Radeon
- AMD GPU
- Nouveau (NVIDIA)
- All other GPU vendors
Device Drivers -->
Serial ATA and Parallel ATA drivers (libata) -->
[*] ATA ACPI Support
[*] SATA Port Multiplier support
[M] AHCI SATA support # Your SATA controller
[M] Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support # For Intel chipset
DISABLE:
- All AMD SATA
- All Marvell SATA
- All other vendor SATA controllers
- Old PATA/IDE drivers (unless you have IDE drives)
- NVMe (you don't have NVMe)
Device Drivers -->
Network device support -->
Ethernet driver support -->
[M] Realtek devices
[M] Realtek 8169/8168/8101/8125 gigabit ethernet support
DISABLE EVERYTHING ELSE:
- Intel network cards
- AMD network cards
- Broadcom
- Atheros
- All wireless drivers
- All other ethernet chipsets
Device Drivers -->
Sound card support -->
Advanced Linux Sound Architecture -->
[M] Intel HD Audio
[M] HD Audio PCI
[M] Build HDMI/DisplayPort HD-audio codec support
DISABLE:
- USB Audio
- FireWire audio
- All other sound card vendors
- OSS emulation
Device Drivers -->
USB support -->
[M] XHCI HCD (USB 3.0) support
[M] EHCI HCD (USB 2.0) support
[M] USB Mass Storage support
DISABLE:
- OHCI (USB 1.1)
- UHCI (USB 1.1) - unless you have really old USB devices
- USB over IP
- USB Gadget support
Device Drivers -->
Input device support -->
[*] Keyboards
[*] Mice
[M] Event interface # evdev
You have:
- Cooler Master keyboard (USB)
- SteelSeries mouse (USB)
DISABLE:
- Touchscreens
- Tablets (unless you have drawing tablet)
- Joysticks (unless gaming with joystick)
Keep sensors for your Intel chipset, disable everything else.
Based on your lsblk:
- You're using ext4 (or similar)
- No LVM visible
- Multiple partitions
Keep:
- ext4
- FAT/VFAT (for EFI partition)
- tmpfs
- proc/sys/devtmpfs
Consider:
- NTFS (if dual-boot with Windows)
- ISO9660 (for reading CDs)
DISABLE:
- Btrfs (unless you use it)
- XFS (unless you use it)
- JFS, ReiserFS (ancient)
- Network filesystems (NFS, CIFS) - or build as modules
- Most exotic filesystems
DISABLE EVERYTHING HERE for production kernel:
Kernel hacking -->
[ ] Kernel debugging # DISABLE
Compile-time checks and compiler options -->
[ ] Compile the kernel with debug info # CRITICAL - DISABLE THIS
[ ] Provide GDB scripts # DISABLE
Memory Debugging -->
[ ] All options # DISABLE ALL
[ ] KGDB # DISABLE
[ ] Tracers # DISABLE ALL
Keep only:
- Magic SysRq key (for emergencies)
Here's a starting .config snippet for your next build:
# In menuconfig, make these changes:
CONFIG_LOCALVERSION="-v2"
# Processor
CONFIG_MCORE2=y # Core 2/newer Xeon
CONFIG_NR_CPUS=4 # Exactly 4 cores
CONFIG_SCHED_SMT=n # No hyperthreading
CONFIG_PREEMPT=y # Low-latency desktop
CONFIG_HZ_1000=y # 1000 Hz timer
CONFIG_NUMA=n # Single socket
# Debugging - DISABLE ALL
CONFIG_DEBUG_INFO=n
CONFIG_DEBUG_INFO_NONE=y
CONFIG_DEBUG_KERNEL=n
CONFIG_KGDB=n
CONFIG_FTRACE=n
# Compression
CONFIG_KERNEL_ZSTD=y # Fast boot
# Features you don't need
CONFIG_BT=n # No bluetooth
CONFIG_WLAN=n # No WiFi
CONFIG_PCMCIA=n # No PCMCIA
CONFIG_HAMRADIO=n # No amateur radioCreate a helper script:
#!/bin/bash
# ~/kernel-build.sh
set -e # Exit on error
VERSION="v2"
CORES=4
cd /usr/src/linux
echo "Building kernel version: $VERSION"
echo "Using $CORES cores"
# Build
echo "=== Building kernel ==="
time make -j${CORES} 2>&1 | tee /tmp/kernel-build.log
echo "=== Building modules ==="
time make modules -j${CORES}
echo "=== Installing modules ==="
sudo make modules_install
echo "=== Installing kernel ==="
sudo make install
echo "=== Updating bootloader ==="
sudo update-grub
echo ""
echo "✓ Build complete!"
echo " Version: $(make kernelrelease)"
echo " Kernel: /boot/vmlinuz-$(make kernelrelease)"
echo " Modules: /lib/modules/$(make kernelrelease)/"
echo ""
echo "Reboot and select the new kernel from GRUB menu"Make it executable:
chmod +x ~/kernel-build.sh# Compare sizes
ls -lh /boot/vmlinuz-*
du -sh /lib/modules/*
# Expected results with debug disabled:
# Modules: 515M → ~100-150M (massive reduction!)
# Kernel: Similar size or slightly smaller# After booting new kernel:
uname -r # Verify correct kernel
lsmod | wc -l # Check module count
dmesg | grep -i error # Look for errors
dmesg | grep -i firmware # Check firmware loading
# Test hardware:
# - Ethernet: ping 8.8.8.8
# - Sound: speaker-test -c2 -t wav
# - Graphics: glxinfo | grep -i opengl
# - USB: plug/unplug devices
# - Disk: dd if=/dev/zero of=~/test bs=1M count=100Keep notes for each build:
mkdir -p ~/kernel-builds
cat > ~/kernel-builds/6.12.6-v2.txt << 'EOF'
Build: 6.12.6-v2
Date: 2024-12-20
Based on: 6.12.6 (working)
Changes:
- Disabled debug symbols (CONFIG_DEBUG_INFO=n)
- Set processor to Core 2/newer Xeon
- Set max CPUs to 4
- Disabled SMT (no hyperthreading)
- Disabled WiFi/Bluetooth (not present)
- Disabled most other vendor network/storage drivers
- Preemption: Low-latency desktop
- Timer: 1000 Hz
Results:
- Module size: 515M → XXX M
- Boot time: [to be filled]
- Issues: [to be filled]
Status: TESTING
EOF- Make v2 build with debug symbols disabled
- Test thoroughly
- Measure size reduction
- Make v3 with hardware-specific optimizations
- Strip out unused drivers
- Fine-tune performance settings
- Compare performance (boot time, responsiveness)
- Create final optimized config
- Consider upgrading to newer kernel (6.13 is coming)
- NEVER remove the working 6.12.6 kernel until the new one is proven stable
- Always keep at least 2 bootable kernels
- Document every change before you forget why you made it
- Test one major change at a time
- Keep the previous .config as
.config.backup
If the new kernel doesn't boot:
- Reboot
- Select old kernel (6.12.6) from GRUB
- Review changes
- Try again
If GRUB menu doesn't appear:
- Hold Shift during boot
- Or press ESC repeatedly
# Compare two configs
cd /usr/src/linux
diff .config.backup .config > changes.txt
scripts/diffconfig .config.backup .config
# Find what changed
grep "^[+-]" changes.txt
# Check if option is enabled
grep CONFIG_DEBUG_INFO .config
# See all debug options
grep -i debug .config | grep "=y"
# Current kernel config
zcat /proc/config.gz > running.config # if CONFIG_IKCONFIG_PROC=y
# or
cat /boot/config-$(uname -r)
# Module info
modinfo i915
lsmod | grep i915
# Module dependencies
modprobe --show-depends i915Good luck with your kernel optimization journey! 🚀