How to install and compile the kernel on Debian and Ubuntu.

Advertisement

The kernel is the central component of an operating system and serves as the primary interface between the computer's physical hardware and the processes running on it via software. In other words, we could define the kernel as the heart or core of the operating system.

One of the biggest draws of using Linux is its easy customization, and one of the most fun things about customizing is the kernel itself, the heart of the Linux operating system.

You'll most likely never need to compile your own kernel. The one that comes with your distribution and updates via its package management system are usually sufficient, but there are times when it may be necessary to recompile the kernel.

Some of these reasons may include special hardware needs, the desire to create a monolithic kernel instead of a modular one, optimizing the kernel by removing useless drivers, running a development kernel, or simply learning more about Linux.

In this case, we're going to compile a newly released kernel on Debian systems that includes several new features, such as new drivers for graphics cards, and offers significant improvements to the file system.

Video about: Compiling kernel 6.6 LTS on Linux Mint 21.3 Virginia with base kernel 5.15 successfully:

Install dependencies required for kernel compilation:

To get started, we'll need a few packages, namely build-essential and kernel headers.

$ sudo apt update
$ sudo apt install build-essential linux-headers-$(uname -r)
$ sudo apt install autoconf automake autotools-dev dh-make debhelper debmake devscripts dpkg fakeroot file gfortran git gnupg fp-compiler lintian patch pbuilder perl quilt xutils-dev pkg-config python-is-python3 2to3 dwarves

Now, visit the official kernel website to download the desired kernel version. https://www.kernel.org/I have chosen the Kernel longterm 6.6.23 2024-03-26 for the rock of Debian Linux 12 as of 02/04/2024 because the «Kerneles de Linux» of «Largo plazo (Longterm)» They are those that provide support for error corrections and maintenance for an extremely long time (years) and thus also benefit the «Kerneles de Linux» older ones.

Alternatively, you can use the following commands to download the font directly and unzip the file.

$ wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.6.23.tar.xz
$ tar -xvf linux-6.6.23.tar.xz
$ cd linux-6.6.23/

We install some dependencies for localmodconfig to work on Debian 12, mxlinux:

$ sudo apt-get install libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf

Now we create the configuration file .config with this command inside the directory linux-6.6.23/ in case it is not created by giving everything intro:

$ sudo make localmodconfig

Now we'll need to configure the kernel; it's a good idea to start with the current configuration and build upon it. To do this, we'll copy the existing configuration from the directory /boot to the current working directory and save it as .config .

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

Installing and compiling the new kernel on Debian.

To begin the actual setup process, you have one of two options.

  • If you have X11 installed, you can run make xconfig and have a nice time GUI menu to help you configure your Kernel.
  • If you are running on a CLI environment, can run make menuconfig, but you will need to have the package installed libncurses5-dev to use it.
  • If you use a cli environment, make sure to install the package libncurses5-dev to start the kernel configuration process as shown.
$ sudo apt install libncurses5-dev
$ sudo make menuconfig

As you'll see, once you're in the configuration of your choice, there are a ton of different options available for your kernel. In fact, there are too many for the scope of this tutorial.

When selecting kernel options, the best way is through trial and error, and a lot of Googling is the best way to learn. If you're simply trying to update your kernel to the latest version, you don't have to change anything and can simply select "Save configuration«. Since we copied the current kernel configuration file to the file .config of the new kernel.

Please note that «Kernel module loader» is selected in «Support for loadable modules«. If you don't and you're using kernel modules, you can seriously mess things up.

NOTE: For Ubuntu Linux and Linux Mint

If you encounter this error during compilation, it is due to the following: The program you are trying to compile uses OpenSSL, but the necessary development files (libraries and header files) needed to link with OpenSSL on your Linux platform are missing. To install the OpenSSL development package on Debian, Ubuntu, or their derivatives:

$ sudo apt-get install libssl-dev

Fatal error: libelf.h: The compilation of that file or directory could not be completed because the path does not exist. To install the libelf development package on Debian, Ubuntu, or their derivatives:

$ sudo apt install libelf-dev

After running «make menuconfig», if you get the certificate error: make[1]: *** No rule to make target 'debian/canonical-certs.pem', needed by 'certs/x509_certificate_list'. Stop. , run the following in the root of the kernel source:

$ scripts/config --disable SYSTEM_TRUSTED_KEYS
$ scripts/config --disable CONFIG_SYSTEM_REVOCATION_KEYS

END NOTE

Now start the kernel compilation process using the following commands, which will compile the kernel, install the modules, and copy the necessary files to the home directory.

Advertisement

If you want to customize the name of the new kernel you can use:

$ sudo make LOCALVERSION=-0-amd64
$ sudo make
$ sudo make modules_install
$ sudo make install

If you want to compile with all the cores of your processor instead of using 1 default processor core to make the kernel compilation faster, we will first check how many cores our processor has with this command:

// npro o nproc
$ npro
8

We will modify the previous command to make it faster and run the compilation and installation of the kernel with all the processor cores with the -j8 command:

If you want to customize the name of the new kernel, you can use:

$ sudo make -j8 LOCALVERSION=-0-amd64
$ sudo make -j8
$ sudo make modules_install -j8
$ sudo make install -j8

ANDThis is the error I got when compiling and installing kernel 6.1.90 LTS on MX-Linux

If you have several computers with identical hardware and operating system, you may be interested in creating the deb packages to later install on several Debian systems and save us from long compilations, saving time.

If you wish to generate ".deb packages"of the new"Linux Kernel» compiled and installed, run the following command:

$ sudo apt install libelf-dev
$ sudo make -j8 bindeb-pkg LOCALVERSION=-0-amd64

We will list the contents of the parent directory, /home/eyesofcat (because that is where it is generated by default):

We are interested in the 2 Deb packs and we will not install kernel debugging:

$ sudo dpkg -i linux-headers-6.6.23_6.6.23-6_amd64.deb && sudo dpkg -i linux-image-6.6.23_6.6.23-6_amd64.deb

Update GRUB to reflect build changes.

$ sudo update-grub
$ sudo update-grub2 
$ sudo update-initramfs -u

Once installed, simply reboot and select the new kernel from the GRUB menu.

Be sure to pay close attention to any error messages during the startup process so you can troubleshoot any problems.

Check the success of compiling and installing the new kernel.

To check for the new kernel version on Debian, you can use the following command in the terminal.

$ uname -r
6.6.23-0-amd64

If you want to see a list of installed kernels, you can check the contents of the directory /boot:

$ ls /boot

Removing the old kernel on Debian:

To remove old kernels on Debian, you must first list the installed kernels to identify the ones you want to remove using the command dpkg.

$ dpkg --list | grep linux-image

To remove an old kernel, use the following apt command and make sure to replace linux-image-OLD_VERSION with the version number of the kernel you want to remove.

// sudo apt purge linux-image-OLD_VERSION
$ sudo apt purge linux-image-6.1.0-18-amd64
$ sudo apt purge linux-headers-6.1.0-18-amd64

After removing the old kernels, update GRUB to reflect the changes.

$ sudo update-grub
$ sudo update-grub2 
$ sudo update-initramfs -u

In conclusion, compiling a kernel in Debian is a valuable skill that allows users to tailor their operating system to specific needs, incorporating the latest features and optimizations.

To perform this update of the Linux Kernel to version linux-6.6.23 on Debian 12 and work, I have dedicated an afternoon to creating this documentation to collaborate with the global Linux community and the most important thing is that it works.

Our score
Click to rate this post!
(Votes: 0 Average: 0)
Advertisement
Share on social media...

Deja un comentario

Your email address will not be published. Required fields are marked *

Basic information on data protection
ResponsibleJavier Cachón Garrido +info...
PurposeManage and moderate your comments. +info...
LegitimationConsent of the concerned party. +info...
RecipientsAutomattic Inc., USA to spam filtering. +info...
RightsAccess, rectify and cancel data, as well as some other rights. +info...
Additional informationYou can read additional and detailed information on data protection on our page política de privacidad.

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.

Scroll al inicio

Descubre más desde javiercachon.com

Suscríbete ahora para seguir leyendo y obtener acceso al archivo completo.

Seguir leyendo