Wednesday, 16 March 2016

Building a custom / newer kernel with CentOS 7

In this tutorial I will be installing the latest stable version of the Linux kernel (4.4.5 as of 15/03/2016).

There is the easy method (using a pre-compiled RPM from a source like ELRepo) or the more daunting task of manually compiling it from source..! I will be doing both...

Compiling from source

This generally involves the following:

- Download kernal, compile

- Add grub boot entry

Please refer to: https://www.howtoforge.com/kernel_compilation_centos

From a repository


Ensure you have added the ELRepo:

cd /tmp
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum update


We also need to enable the 'ELRepo.org Community Enterprise Linux Kernel Repository - el7' as it is disabled by default in /etc/yum.repos.d/elrepo.repo - although we can do this as a one of with:

yum --enablerepo=elrepo-kernel install kernel-ml

This will place the initramfs into:

/boot/initramfs-4.5.0-1.el7.elrepo.x86_64.img

The grub bootloader will automatically be updated / re-generated with a new entry for the newer kernel e.g. (taken  from grub.cfg):

menuentry 'CentOS Linux (4.5.0-1.el7.elrepo.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_6$
        load_video
        set gfxpayload=keep
           insmod gzio
        insmod part_msdos
           insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  93af92d3-387a-4ab8-8d5f-83f8c36785b1
        else
          search --no-floppy --fs-uuid --set=root 93af92d3-387a-4ab8-8d5f-83f8c36785b1
        fi
        linux16 /vmlinuz-4.5.0-1.el7.elrepo.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_GB.UTF-8
        initrd16 /initramfs-4.5.0-1.el7.elrepo.x86_64.img
}

And once booted into the new kernel - confirm version with:

uname -r

You might (like myself) also want to install the corresponding kernel headers - we can do this with: 

yum --enablerepo=elrepo-kernel install kernel-ml-devel.x86_64 kernel-ml-headers.x86_64 kernel-ml-tools.x86_64 kernel-ml-tools-libs.x86_64 kernel-ml-tools-libs-devel.x86_64

* Note: You will have to remove your existing kernel headers - as it will cause a conflict otherwise! *

0 comments:

Post a comment