Cadastre-se agora para um orçamento mais personalizado!

NOTÍCIAS QUENTES

How to compile your first Linux kernel (and 3 reasons why you should)

Mar, 25, 2025 Hi-network.com
Andrew Peacock/Getty Images

I remember the first time I compiled a Linux kernel. I was nervous. It was something I'd never done before, and it seemed like an incredibly difficult task. After all, isn't the kernel the stuff of elite programmers? If so, why would I even bother?

Because I could.

Also: These Linux distributions are best for developers

And because all of the cool open-source, alternakids were doing it.

If I wanted to fit in, I had to make (see what I did there?) it happen.

So, I downloaded the kernel source, took a deep breath, and dove in.

This would have been around 2000 or 2001, and when I successfully pulled it off, I'm sure I did a happy dance or two.

But how did I do it?

Believe it or not, the process of compiling the Linux kernel isn't nearly as hard as you might think. It is time-consuming, but it's a challenge you can certainly overcome.

Why would you want to compile the kernel?

There are three reasons why you might want to do this:

  • You want to use a newer or different kernel than your distribution provides (such as a real-time or low-latency kernel).
  • You need a kernel with very specific configurations and only specific modules.
  • You want to brag to your friends that you compiled a Linux kernel.

Also: This is the best-looking Linux desktop of 2025 (so far)

Let me show you how it's done.

How to compile the Linux kernel from source

What you'll need: To compile a kernel, you'll need to download the kernel source, a user with sudo privileges, and plenty of time. I'm going to demonstrate this on an instance of Ubuntu Desktop 24.04. If you're using a distribution not based on Debian or Ubuntu, you'll need to make sure to install the necessary dependencies with your distribution's package manager.

Before you embark on this journey, find a spare machine or deploy a virtual machine. You do not want to compile your first Linux kernel on a production machine.

1. Download the source

The first thing you're going to do is download the source of the kernel you want to use. I would suggest going straight to The Linux Kernel Archives and downloading the tarball file of the kernel you want. I'm going to download the 6.13 source for demonstration purposes.

Show more

2. Install the necessary dependencies

Open a terminal window and issue the following command to install the dependencies:

Show more

sudo apt-get install build-essential libncurses-dev git bison flex libssl-dev -y

2. Extract the archived file

Open a terminal window and change into the directory housing the downloaded file and extract it with the command:

Show more

unxz --keep linux-XXX.tar.xz

Where XXX is the release number.

3. Extract the file

We can now extract the tar file with the command:

Show more

tar -xf linux-XXX.tar

Where XXX is the release number.

4. Configuring the kernel

At this point, you can either use the generic configuration or you can manually edit the .conf file within the newly created directory (which will be named linux-XXX -where XXX is the release number). Another method you can use (which I would suggest for your first go-round) is copying your distribution's configuration file. 

Before you do this, change into the newly created folder with the command:

Show more

cd linux-XXX

Where XXX is the release number.

Next, copy the configuration file with the command:

cp /boot/config-"$(uname -r)" .config

Alternatively, you could manually configure the kernel by using the command:

make menuconfig

The above command opens the menuconfig utility, where you can browse and enable/disable various features. This is how I've always compiled kernels. This method does take some time (because there are a lot of modules to go through). If you go that route, make sure to save it to a file with:

make savedconfig

The above command will create a new directory housing your .config file.

Also: The first 5 Linux commands every new user should learn

5. Update the configuration

After copying the configuration, you need to update the configuration file (because the one shipped with your distribution is most likely out of date). To do this, issue the command:

Show more

make oldconfig

The .config file is now updated for the kernel source you downloaded.

6. Disable the signing module

For users of Debian-based distributions, you'll need to disable the module that is used to sign kernel modules, because the certificate used for this is not included. To do this, issue the commands:

Show more

scripts/config --disable SYSTEM_TRUSTED_KEYS
scripts/config --disable SYSTEM_REVOCATION_KEYS

If you do not do this, the build will fail later in the process, which means you will have wasted a lot of time (been there, done that...too many times).

7. Building the kernel

It's now time to build the kernel with the command:

Show more

make -j$(nproc)

This will take quite a long time to complete.

8. Install the kernel modules

You don't want every Linux kernel module loading at bootup. Instead, we build loadable modules. This process not only installs the kernel modules but also signs them, which means the process will (once again) take some time. The command for this is:

Show more

sudo make modules_install -j$(nproc)

9. (Optional) Install kernel header files

There are some instances when you might need the kernel header files (such as if you were going to write your own modules or install certain server software). For that, issue the command:

Show more

sudo make headers_install

10. Install the kernel

It's now time to install the kernel, which is done with the command:

Show more

sudo make install

11. Generating the initial ramdisk

The ramdisk (initial RAM filesystem) is required for booting and can be created with:

Show more

sudo dracut --force /boot/initrd.img-XXX-generic XXX-generic

Where XXX is the release number of the kernel you're installing.

12. Update grub

Finally, update the grub bootloader (so it's aware of your new kernel) with:

Show more

sudo update-grub2

You can now reboot your machine and select the newly compiled kernel.

Also: The best Linux laptops you can buy

Remember, do this on a virtual machine or a test machine because you don't want to monkey around with your daily driver and wind up with a machine that won't boot.

Get the morning's top stories in your inbox each day with our Tech Today newsletter.

Open Source

The open-source tools that could disrupt the entire IT incident management marketThis Linux distro could let your old laptop 'shine on' after Windows 10's sunset6 Linux myths, busted5 lightweight Linux distributions with very low system requirements
  • The open-source tools that could disrupt the entire IT incident management market
  • This Linux distro could let your old laptop 'shine on' after Windows 10's sunset
  • 6 Linux myths, busted
  • 5 lightweight Linux distributions with very low system requirements

tag-icon Tags quentes : Tecnologia Serviços & Software Sistemas Operacionais

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.
Our company's operations and information are independent of the manufacturers' positions, nor a part of any listed trademarks company.