How To Install A Higher Version of the Kernel, Build/Compile and Make the System Used It

Alexzee

Well-Known Member
Joined
Jun 1, 2019
Messages
4,277
Reaction score
2,353
Credits
26,433
In this thread is one of those things (installing and compiling a new kernel) that I'm not well versed in.
I'll have to learn to install a new kernel (6.12) maybe 3 times (I'll see) on a new desktop build that doesn't belong to me.

Why? You ask, because the newer hardware that I've invested the time in looking up the specs require a higher version of the kernel. This is what I've repeatedly come across in doing the research.

I'm reading this article for now to try understand what I need to wrap my brain around.:)

My biggest concern is 'configuring the kernels features' and selecting or 'adding the modules' that my friends new system will need.

Good instructions, precise direction and being well advised in this situation is highly favored.

Thanks in advance-
Alex
 


This is usually somewhat distro dependent. For example the build tools are usually named differently
for different distro's. Some distro's such as fedora require openssl-devel because parts of the communication
between the kernel and other system processes is encrypted. Also it's slightly different depending on it you
do it from the command line, or if you do it with GUI config tool.

But here is the basic outline. I have done a number of times so I know it works with these instructions for my distro.
Results may vary.

Step-by-Step Guide to Download, Compile, and Install a Newer Kernel​

1. Download the Latest Kernel Source Code​

Visit the official kernel.org website and download the latest stable kernel source code. - https://www.kernel.org/

2. Extract the Source Code​

Extract the downloaded tarball:
Code:
 tar xvf linux-6.12.9.tar.xz cd linux-6.12.9

3. Install Required Packages​

For RPM-based systems, install the necessary development tools and libraries:
Code:
dnf group install "c-development"
dnf install ncurses-devel
dnf install qwt-qt6-devel

Optional:
Code:
dnf install gtk+-devel gtk2-devel libglade2-devel

For Debian-based systems, install the build-essential package:
Code:
sudo apt update
sudo apt install build-essential
apt install libncurses-dev
apt install libqwt-qt6-dev

4. Configure the Kernel​

Copy the current kernel configuration as a starting point:
Code:
 cp /boot/config-$(uname -r) .config

For systems running a GUI, you can use xconfig to configure the kernel:
Code:
 make xconfig

Alternatively, for non-GUI systems, use:
Code:
 make menuconfig

Customize the kernel options as needed and save the configuration. For the most part you can just go with the
defaults that were copied from your old config.

5. Compile the Kernel​

Compile the kernel and its modules:
Code:
 make -j$(nproc)

The -j flag uses more cores to speed things up, even on a fast system, this usually takes at least an hour or two.
If you add too many cores, it can actually slow you down.

Install the modules:
Code:
 sudo make modules
make modules_install

6. Install the Kernel​

Install the compiled kernel:
Code:
 sudo make install

7. Update the Bootloader​

Ensure the bootloader is updated to include the new kernel:
Code:
 sudo grub2-mkconfig -o /boot/grub2/grub.cfg

8. Reboot the System​

Reboot your system to use the new kernel:
Code:
 sudo reboot

After rebooting, you can verify the new kernel is running by checking the kernel version:
Code:
 uname -r
 
Last edited:
1736551229374.png
 

Attachments

  • Screenshot 2025-01-10 151352.png
    Screenshot 2025-01-10 151352.png
    14.1 KB · Views: 24
Slackware? Debian? Arch?, Gentoo?
Slackware and Gentoo are simple just use sources from www.kernel.org.
Debian and Arch require post-compilation packaging

Based on the pic from your post you plan to update kernel on Slack. Then Grub or lilo or elilo?
First blacklist kernels in:
sudo nano /etc/slackpkg/blacklist
uncomment
kernel-generic.*
kernel-huge.* <- if you are running -current this is not anymore needed as -current does not use -huge
kernel-modules.*
kernel-source

once custom kernel works and you want to use only custom kernel you can uninstall Slackware default kernels with slackpkg uninstall but keep it for now.

Next question: do you want to tailor this for your hardware only or make it similar to the default Slackware kernel? Personally I don't see a reason to just compile generic Slackware kernel. To make sure that your all hardware is recognized you have to make sure that all hardware you want to use is connected and running during generation of config file. This is one time deal only once config containing your hardware is made, you can re-use this config for the next time when building kernels in the future.


1) sudo tar xpvf ~/virtual/shared/kernel/linux-6.12.9.tar.xz -C /usr/src
2) sudo cp /boot/efi/config (or download the latest config file from https://slackware.uk/cumulative/slackware64-current/kernels/generic.s/ and copy to the folder:
3) cd /usr/src/linux-6.12.9
4) sudo make localmodconfig <- this will trim config to fit your hardware (whatever is enabled)

5) make -j $(nproc)
6) make modules_install
7) cp arch/x86_64/boot/bzImage /boot/efi/EFI/Slackware/vmlinuz-custom
8) ?? different steps for lilo, elilo, grub
but you must add your kernel as separate entry not replacement so this way if your kernel fail, you can boot the old one

That s all.

Hint I was using the same kernel config for different distros
 
This is usually somewhat distro dependent. For example the build tools are usually named differently
for different distro's. Some distro's such as fedora require openssl-devel because parts of the communication
between the kernel and other system processes is encrypted. Also it's slightly different depending on it you
do it from the command line, or if you do it with GUI config tool.

But here is the basic outline. I have done a number of times so I know it works with these instructions for my distro.
Results may vary.

Step-by-Step Guide to Download, Compile, and Install a Newer Kernel​

1. Download the Latest Kernel Source Code​

Visit the official kernel.org website and download the latest stable kernel source code. - https://www.kernel.org/

2. Extract the Source Code​

Extract the downloaded tarball:
Code:
 tar xvf linux-6.12.9.tar.xz cd linux-6.12.9

3. Install Required Packages​

For RPM-based systems, install the necessary development tools and libraries:
Code:
dnf group install "c-development"
dnf install ncurses-devel
dnf install qwt-qt6-devel

Optional:
Code:
dnf install gtk+-devel gtk2-devel libglade2-devel

For Debian-based systems, install the build-essential package:
Code:
sudo apt update
sudo apt install build-essential
apt install libncurses-dev
apt install libqwt-qt6-dev

4. Configure the Kernel​

Copy the current kernel configuration as a starting point:
Code:
 cp /boot/config-$(uname -r) .config

For systems running a GUI, you can use xconfig to configure the kernel:
Code:
 make xconfig

Alternatively, for non-GUI systems, use:
Code:
 make menuconfig

Customize the kernel options as needed and save the configuration. For the most part you can just go with the
defaults that were copied from your old config.

5. Compile the Kernel​

Compile the kernel and its modules:
Code:
 make -j$(nproc)

The -j flag uses more cores to speed things up, even on a fast system, this usually takes at least an hour or two.
If you add too many cores, it can actually slow you down.

Install the modules:
Code:
 sudo make modules
make modules_install

6. Install the Kernel​

Install the compiled kernel:
Code:
 sudo make install

7. Update the Bootloader​

Ensure the bootloader is updated to include the new kernel:
Code:
 sudo grub2-mkconfig -o /boot/grub2/grub.cfg

8. Reboot the System​

Reboot your system to use the new kernel:
Code:
 sudo reboot

After rebooting, you can verify the new kernel is running by checking the kernel version:
Code:
 uname -r
Thanks for the heads up on the build tools being named differently on other distributions.

Glad to hear that you know this works....this is exactly what I needed.
 
Slackware? Debian? Arch?, Gentoo?
Slackware and Gentoo are simple just use sources from www.kernel.org.
Debian and Arch require post-compilation packaging

Based on the pic from your post you plan to update kernel on Slack. Then Grub or lilo or elilo?
First blacklist kernels in:
sudo nano /etc/slackpkg/blacklist
uncomment
kernel-generic.*
kernel-huge.* <- if you are running -current this is not anymore needed as -current does not use -huge
kernel-modules.*
kernel-source

once custom kernel works and you want to use only custom kernel you can uninstall Slackware default kernels with slackpkg uninstall but keep it for now.

Next question: do you want to tailor this for your hardware only or make it similar to the default Slackware kernel? Personally I don't see a reason to just compile generic Slackware kernel. To make sure that your all hardware is recognized you have to make sure that all hardware you want to use is connected and running during generation of config file. This is one time deal only once config containing your hardware is made, you can re-use this config for the next time when building kernels in the future.


1) sudo tar xpvf ~/virtual/shared/kernel/linux-6.12.9.tar.xz -C /usr/src
2) sudo cp /boot/efi/config (or download the latest config file from https://slackware.uk/cumulative/slackware64-current/kernels/generic.s/ and copy to the folder:
3) cd /usr/src/linux-6.12.9
4) sudo make localmodconfig <- this will trim config to fit your hardware (whatever is enabled)

5) make -j $(nproc)
6) make modules_install
7) cp arch/x86_64/boot/bzImage /boot/efi/EFI/Slackware/vmlinuz-custom
8) ?? different steps for lilo, elilo, grub
but you must add your kernel as separate entry not replacement so this way if your kernel fail, you can boot the old one

That s all.

Hint I was using the same kernel config for different distros
This kernel compilation is for my friends new build. Sparky Linux (Debian 12 based), LMDE6 and a fresh installation of Linux Mint 22 will have to be installed on the 3rd drive.
Grub is the main bootloader:-

And, yes, I do want to tailor this kernel to the new hardware on the new desktop build.

In the future I will want to install and compile a newer kernel for my Slackware installation.
For now I'm focused on helping my friend with getting his hardware components and assisting him with the build.
 
I've copied and pasted both of your helpful instructions.:)
Vim is handy when you don't have a lot of time.

I'll go through these instructions at least once in a vm before installing kernel 6.12 on my friends new build.

Question-----------

@dos2unix ....if there are any patches to this new kernel how would I find out and how would I apply the patch file to all 3 distro's?

OR> should I not concern myself with a patch as it may be added along with the update/upgrades to the Debian based systems?
 

Attachments

  • New Kernel 1.png
    New Kernel 1.png
    184.6 KB · Views: 21
  • New kernel 2.png
    New kernel 2.png
    224.9 KB · Views: 21
@dos2unix ....if there are any patches to this new kernel how would I find out and how would I apply the patch file to all 3 distro's?

LOL, I had a feeling that might be your next question. Now it's gets tricky, there are always patches...


Almost every day new patches are released, the vast majority are hardware fixes, so unless you're targeting
a specific thing ( wi-fi card, network card, bluetooth chip, logical volume manager, etc... )
It's hard to know what to patch.

There are literally hundreds, but I suspect for a VM with "generic" drivers you won't need most of them.
If you're going to put these on real hardware, you'll need to know what chipsets you have.

what cpu? what soundcard? what network card? what wi-fi chip? etc...

If you're doing this on multiple PC's, you need to know those chipsets too.
The good news is, the newer the kernel, the less patches you need.
Also all hardware modules/patches are not included in the kernel source, if you have a newer broadcom or realtech or mediaTek you may have to go out to the vendors site, download the code and patch it in yourself.

By now, you have probably realized the difference between external dynamically loaded modules, and internally compiled in modules. You have something called an initramfs ( different distro's call this different things )

This is starting to get into another subject, I will have AI try to summarize this part for me.

Purpose of Initramfs​

Initramfs is a temporary root filesystem loaded into memory during the early stages of the Linux boot process. It contains the necessary drivers and tools to mount the real root filesystem. The kernel unpacks the initramfs archive into a RAM disk, mounts it, and uses it as the initial root filesystem. This allows the kernel to load essential modules and perform initial setup tasks before switching to the actual root filesystem

Purpose of Dracut​

Dracut is a tool used to create initramfs images. It provides a modular framework for generating initramfs images by including only the necessary components required for the system to boot. Dracut is highly configurable and can be tailored to include specific drivers, tools, and configurations needed for different environments

Debian can use dracut, but more typically use...
update-initramfs: This command is used to generate or update initramfs images.
mkinitramfs: This script is called by update-initramfs to create the actual initramfs image.

Determining Which Kernel Modules Get Loaded​

The process of determining which kernel modules get loaded involves several steps:

Module Inclusion: Dracut includes modules based on the system's configuration and the installed Dracut modules. These modules are located in the /usr/lib/dracut/modules.d directory and provide specific functionalities, such as support for different filesystems, hardware drivers, and network configurations

Configuration Files: Dracut reads configuration files located in /etc/dracut.conf and /etc/dracut.conf.d/. These files can specify which modules to include or exclude, additional files to add, and other customization options

Kernel Command Line: The kernel command line can also influence which modules are loaded. Parameters passed to the kernel at boot time can instruct Dracut to include specific modules or enable debugging options

Automatic Detection: Dracut can automatically detect the necessary modules based on the current hardware and system configuration. This is particularly useful for creating a generic initramfs that works across different systems

Yeah, it can really get complicated if you really want to specialize in custom kernels. But the point here is
your kernel only loads the modules it needs, the only disadvantage to having all the other modules around is
they use a little more space on your hard drive.

You can test this using lsmod. I personally rarely ( if ever ) see a module loaded for hardware I don't have ).
But I won't say it never happens.
 
Last edited:
Slackware has all needed tools for kernel compilation pre-installed.
4) sudo make localmodconfig <- this will trim config to fit your hardware (whatever is enabled)
will detect all hardware connected and working (you need modules loaded for your hardware) and remove everything that is not loaded. Exception being build-in hardware that this script does not touch. Because this is kernel script it works in any distro being part of kernel sources. Limiting kernel hardware to the one that is needed has few advantages: affect security (e.g. not having IPv6 has advantage of avoiding constant issues with IPv6 security issues) and really shorten kernel build time. Finally once you grasp the concept, kernel has a lot of security settings not enabled by default that you can test and use.

dracut is available for Slackware by the way.
Also initramfs is needed for systemd (and boot encryption) but non-systemd distros give you a choice to build kernel with or without initramfs. Personally I don't use iniramfs (this means I have disk and root fs build-in).

If installing Linux in VM (type II hypervisor), you are in the luck: hardware setup is really conservative and drivers for virtual devices (network, sound, disk, video) are long incorporated in the kernel. With hypervisor type I it really depends what you allow clients to see. Kernels are released quite often but it does not mean that you need every new kernel to compile as new release may not have updates for your hardware (you can check changelogs at www.kernel.org)
 
dracut is available for Slackware by the way.

I am not trying to dis slackware or arch here, I like both distro's, the only reason I didn't include them in my examples
is because I haven't actually compiled kernels on those. I wanted to use examples that I have actually done.
I used slackware for a couple years, many years ago. That was before a lot of distro's that are around now even existed.

I do appreciate your input here, I know I am missing some things. :)
 
Last edited:
LOL, I had a feeling that might be your next question. Now it's gets tricky, there are always patches...


Almost every day new patches are released, the vast majority are hardware fixes, so unless you're targeting
a specific thing ( wi-fi card, network card, bluetooth chip, logical volume manager, etc... )
It's hard to know what to patch.

There are literally hundreds, but I suspect for a VM with "generic" drivers you won't need most of them.
If you're going to put these on real hardware, you'll need to know what chipsets you have.

what cpu? what soundcard? what network card? what wi-fi chip? etc...

If you're doing this on multiple PC's, you need to know those chipsets too.
The good news is, the newer the kernel, the less patches you need.
Also all hardware modules/patches are not included in the kernel source, if you have a newer broadcom or realtech or mediaTek you may have to go out to the vendors site, download the code and patch it in yourself.

By now, you have probably realized the difference between external dynamically loaded modules, and internally compiled in modules. You have something called an initramfs ( different distro's call this different things )

This is starting to get into another subject, I will have AI try to summarize this part for me.

Purpose of Initramfs​

Initramfs is a temporary root filesystem loaded into memory during the early stages of the Linux boot process. It contains the necessary drivers and tools to mount the real root filesystem. The kernel unpacks the initramfs archive into a RAM disk, mounts it, and uses it as the initial root filesystem. This allows the kernel to load essential modules and perform initial setup tasks before switching to the actual root filesystem

Purpose of Dracut​

Dracut is a tool used to create initramfs images. It provides a modular framework for generating initramfs images by including only the necessary components required for the system to boot. Dracut is highly configurable and can be tailored to include specific drivers, tools, and configurations needed for different environments

Debian can use dracut, but more typically use...
update-initramfs: This command is used to generate or update initramfs images.
mkinitramfs: This script is called by update-initramfs to create the actual initramfs image.

Determining Which Kernel Modules Get Loaded​

The process of determining which kernel modules get loaded involves several steps:

Module Inclusion: Dracut includes modules based on the system's configuration and the installed Dracut modules. These modules are located in the /usr/lib/dracut/modules.d directory and provide specific functionalities, such as support for different filesystems, hardware drivers, and network configurations

Configuration Files: Dracut reads configuration files located in /etc/dracut.conf and /etc/dracut.conf.d/. These files can specify which modules to include or exclude, additional files to add, and other customization options

Kernel Command Line: The kernel command line can also influence which modules are loaded. Parameters passed to the kernel at boot time can instruct Dracut to include specific modules or enable debugging options

Automatic Detection: Dracut can automatically detect the necessary modules based on the current hardware and system configuration. This is particularly useful for creating a generic initramfs that works across different systems

Yeah, it can really get complicated if you really want to specialize in custom kernels. But the point here is
your kernel only loads the modules it needs, the only disadvantage to having all the other modules around is
they use a little more space on your hard drive.

You can test this using lsmod. I personally rarely ( if ever ) see a module loaded for hardware I don't have ).
But I won't say it never happens.
Passing a parameter using Dracut sounds good however; I'll use "update-initramfs" first and see how that fairs.
I found the Intel wifi6 driver's for Linux so that's done....that is 'if' I need one for the mobo/chipset of his choice.

Glad I'll need less patches with higher versions of the kernel. I suspected that to be true and I'm glad that you confirmed it, thanks!
 
Slackware has all needed tools for kernel compilation pre-installed.

will detect all hardware connected and working (you need modules loaded for your hardware) and remove everything that is not loaded. Exception being build-in hardware that this script does not touch. Because this is kernel script it works in any distro being part of kernel sources. Limiting kernel hardware to the one that is needed has few advantages: affect security (e.g. not having IPv6 has advantage of avoiding constant issues with IPv6 security issues) and really shorten kernel build time. Finally once you grasp the concept, kernel has a lot of security settings not enabled by default that you can test and use.

dracut is available for Slackware by the way.
Also initramfs is needed for systemd (and boot encryption) but non-systemd distros give you a choice to build kernel with or without initramfs. Personally I don't use iniramfs (this means I have disk and root fs build-in).

If installing Linux in VM (type II hypervisor), you are in the luck: hardware setup is really conservative and drivers for virtual devices (network, sound, disk, video) are long incorporated in the kernel. With hypervisor type I it really depends what you allow clients to see. Kernels are released quite often but it does not mean that you need every new kernel to compile as new release may not have updates for your hardware (you can check changelogs at www.kernel.org)
Found it thanks!
 
I've got Virtual Boxed installed on my Debian 12 install. I'll use Debian 12 in the vm to install/compile and build the new kernel. I'll have to follow these instructions the two of you have given me, from the laptop as the Debian 12 host is on my Asus Tuf Gaming Desktop.

I'll let you know how this goes come Monday:-:)
 
This kernel compilation is for my friends new build. Sparky Linux (Debian 12 based), LMDE6 and a fresh installation of Linux Mint 22 will have to be installed on the 3rd drive.
On Mint I would think it's easier to use this than compiling it manually, it's for Ubuntu but should also work on Mint.
 
Last edited:
On Mint I would think it's easier to use this than compiling it manually, it's for Ubuntu but should also work on Mint.
Agreed, hands down. Much easier to use Mainline, thanks!
Once the ppa is installed it should be a breeze.
 
Just a side note here. This has bitten me more than once, so I'll just mention it here.

I went the exercise of trying optimize all the drivers once, it took a very long time.
Then once I got it all how I wanted it, I added a USB dongle with a different chipset, then
I swapped my SSD hard drive for an m.2 nvme drive, then I added a webcam... etc...
you get the idea. It was more trouble than it was worth and I had to do this for every new kernel.
 
Just a side note here. This has bitten me more than once, so I'll just mention it here.

I went the exercise of trying optimize all the drivers once, it took a very long time.
Then once I got it all how I wanted it, I added a USB dongle with a different chipset, then
I swapped my SSD hard drive for an m.2 nvme drive, then I added a webcam... etc...
you get the idea. It was more trouble than it was worth and I had to do this for every new kernel.
Wow! What a mess:-
The forthcoming on that is worth more than diamonds.

Like you I've been bitten a a handful of times with Linux and the config's on some things.
Not a fun place to be however; we do learn from our shortcomings and mistakes. And, the good news from that is we tend to not rinse and repeat. LOL!

Enjoy the weekend or what's left of it-
 
Fresh install of Debian 12 went well in VBox.
Taking a break now, bb Monday with progress on installing a new kernel.
 

Attachments

  • Deb 12 VM.png
    Deb 12 VM.png
    110.7 KB · Views: 17
  • Deb12 VM Finished.png
    Deb12 VM Finished.png
    109.9 KB · Views: 21
I am not trying to dis slackware or arch here, I like both distro's, the only reason I didn't include them in my examples
is because I haven't actually compiled kernels on those. I wanted to use examples that I have actually done.
I used slackware for a couple years, many years ago. That was before a lot of distro's that are around now even existed.

I do appreciate your input here, I know I am missing some things. :)
ohh, I don't think that you dis Slackware :)
I think though that if anything in regards of kernel custom installation I think that Slackware is the easiest just need kernel sources. But everything is relative so whatever is most convenient for the user is the best.
 

Members online


Top