Re-Compiling Kernel on Gentoo

Ideally before you update the portage tree on the VPS Gentoo image install the gentoo-sources image. This will give the linux kernel source code for you to compile. It will install the image in /usr/src under the linux-4.9.16-gentoo dir (/usr/src/linux) also points to the current kernel.

emerge -av gentoo-sources

It looks as though the kernel was built using the genkernel package. We don't need to use this as the config file has already been created. We copy the config file to the /usr/src/linux directory to be used to build the kernel.

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

To enable/disable options it is usually easier to use the menuconfig option. This will give you a console GUI for you to look at the different options within the linux kernel as well it provides some help on each.

make menuconfig

Once you have finishing configuring the kernel. You need to build the kernel and modules and then install the modules

make && make modules_install

This will give you the compiled gentoo-sources kernel with the original VPS configuration it is stored as /usr/src/linux/arch/x86/boot/bzImage so we need to copy it to the boot directory so we can boot with it. Before you do this however you have the option either overwriting the original kernel or creating another entry in grub.conf so you can boot off the original kernel if this one fails.

Option 1:- To overwrite the original kernel

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

Option 2:- To create a new entry in the grub.conf file, open the grub.conf file and copy the existing 4 lines starting with the title line. Change the kernel on the new entry to the name of the new kernel kernel-new-x86_64-4.9.16-gentoo (Leave the initramfs image name the same). You could also change the default 0 line to default 1 so that it boots 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 reboot. If you have created a new grub.conf entry be sure to select that entry when booting.

reboot