DEV Community

wx-yz
wx-yz

Posted on β€’ Edited on

1

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

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

Image of Docusign

πŸ› οΈ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (2)

Collapse
 
geoeduca profile image
GeoEduca β€’

according to your experience, because it is better to compile,
like this: make CC=clang -j4
and not, like this: make -j4
Or is it that there are factors that determine when to use one or the other ?

Collapse
 
mccurcio profile image
Matt Curcio β€’

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

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay