Compiling your own Kernel for Debian and CentOS (or alike)

For various reasons you might need to (re)-compile your own kernel. For instance if the installed kernel by your distribution does not support a certain feature you need.
I recently discovered that the kernels provided by OVH for their servers do NOT support loadable modules. Even the “original” kernels they provide dont. So you need to compile your own kernel to use things like cryptsetup (dm-crypt).

Fortunately compiling your own kernel is easy if you know howto do it.

Necessary packages

# RHEL / Fedora / CentOS
yum groupinstall "Development Tools"
yum install ncurses ncurses-devel

# Ubuntu / Debian
apt-get install lzma kernel-package debhelper fakeroot build-essential libtool automake make gcc ncurses ncurses-dev

Preparation

cd /usr/src/
# get the desired kernel source
wget https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.27.tar.xz
tar xJf linux-2.6.32.tar.xz
cd linux-2.6.32/
# cleanup
make mrproper
# copy current kernel config as a base to use. Note: 'make mrproper' deletes .config
cp /boot/config-2.6.32-358.6.2.el6.x86_64 .config
make menuconfig
# edit config and save, see screenshot how the menu looks like
make menuconfig

make menuconfig

Compiling and installing

This step might take a while depending on your hardware.

# for faster compilation time do this. It adjusts compiling to the number of your CPU cores
export CONCURRENCY_LEVEL=`getconf _NPROCESSORS_ONLN`

# RHEL / Fedora / CentOS
make rpm
# install kernel after build
rpm -ivh /root/rpmbuild/RPMS/x86_64/kernel-2.6.32.27-1.x86_64.rpm

# Ubuntu / Debian
fakeroot make-kpkg clean
fakeroot make-kpkg --initrd kernel_image
cd ..
# install kernel after build
dpkg -i

Final touches

# RHEL / Fedora / CentOS
mkinitrd initramfs-2.6.32.27.img 2.6.32.27
grubby --add-kernel=/boot/vmlinuz-2.6.32.27  --initrd=/boot/initramfs-2.6.32.27.img --title=2.6.32.27 --make-default --copy-default
# check /etc/grub.conf and modify kernel flags if necessary

# Ubuntu / Debian
# check /boot/grub/grub.cfg to see your new kernels menuentry
# edit /etc/default/grub  and edit GRUB_DEFAULT=1  to match menuentry, counting starts with 0
  1. No comments yet.

  1. No trackbacks yet.