loading...

HOWTO: Compile Linux kernel (on Ubuntu, applies to any distro)

wxyz profile image wx-yz Updated on ・1 min read

Happy CPUs when compiling the kernel

Happy CPUs when compiling the kernel

Ubuntu 20.04 comes with Linux kernel 5.4.0-37. I had to reboot every time my machine wake up from sleep to fix screen flickering issues. Latest stable kernel (5.7.2) fixed this issue for me.

Notes,

  • It's easy to start with a working config and test the kernel first
  • If it's working, move on to remove things you don't need. This will result in a smaller kernel
  • Kernel modules built against the running kernel have to be recompiled. Notably Nvidia drivers and VirtualBox

Steps to compile the kernel,

  1. Download latest stable from kernel.org

  2. Unzip
    ➜ tar xf linux-5.7.2.tar.xz && cd linux-5.7.2

  3. Copy existing config (make things easy)
    ➜ cp /boot/config-$(uname -r) .config

  4. Use terminal based configuration tool
    ➜ make menuconfig
    If you have relatively recent hardware, this step will take most of your time. Add/remove stuff based on your hardware

  5. Compile the kernel with Clang (Remove CC for compiling with gcc - the default C compiler)
    make CC=clang -j12

  6. Install the kernel
    sudo make install

  7. Update grub
    sudo update-grub

  8. Reboot
    sudo reboot

Posted on by:

Discussion

markdown guide
 

These look like notes I make for my own benefit. ;))