You are here:

Recompiling the Kernel in Gentoo: A Step-by-Step Guide

Recompiling the Kernel in Gentoo: A Step-by-Step Guide

Ideally, before updating the portage tree on your VPS Gentoo image, install the gentoo-sources image. This step provides the Linux kernel source code necessary for compilation. The image will be installed in the /usr/src directory under the linux-4.9.16-gentoo directory. Additionally, /usr/src/linux will point to the current kernel source.

emerge -av gentoo-sources

It appears that the kernel was constructed using the genkernel package. Since the configuration file has already been generated, there’s no need to use genkernel. Simply copy the config file to the /usr/src/linux directory; it will be utilized for the kernel build process.

cp /proc/config.gz .
tar -xvf config.gz
gunzip config.gz
cp config /usr/src/linux/.config

For enabling/disabling options, it is generally more straightforward to use the menuconfig option. This command opens a console GUI, allowing you to navigate through various options within the Linux kernel. Additionally, it provides helpful information on each configuration choice.

make menuconfig

Once you have finished configuring the kernel, proceed to build the kernel and modules, and subsequently, install the modules.

make && make modules_install

After compiling, the gentoo-sources kernel with the original VPS configuration is stored as /usr/src/linux/arch/x86/boot/bzImage. To use it for booting, you should copy it to the boot directory. However, before doing this, you have the option of either overwriting the original kernel or creating another entry in grub.conf. This allows you to boot off the original kernel in case the new one encounters issues.

Option 1: Overwriting the Original Kernel

cp ./arch/x86/boot/bzImage /boot/kernel-genkernel-x86_64-4.9.16-gentoo

Option 2: Creating a New Entry in the grub.conf File

To create a new entry in the grub.conf file:

  1. Open the grub.conf file.
  2. Copy the existing 4 lines starting with the title line.
  3. Change the kernel on the new entry to the name of the new kernel (e.g., kernel-new-x86_64-4.9.16-gentoo). Keep the initramfs image name the same.
  4. Optionally, change the default 0 line to default 1 to make it boot the new kernel automatically.
nano /boot/grub/grub.conf
cp ./arch/x86/boot/bzImage /boot/kernel-new-x86_64-4.9.16-gentoo

You can now proceed to reboot. If you have created a new entry in the grub.conf file, make sure to select that entry during the boot process.

reboot
Was this article helpful?
Dislike 0