Skip to content

Instantly share code, notes, and snippets.

@chappy84
Last active February 13, 2018 21:47
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chappy84/2787972 to your computer and use it in GitHub Desktop.
Install the native kernel on a CentOS 6 and Newer Linode
### Starting from a fresh CentOS 6 or newer Linode
### Enable the native kernel to boot from pvgrub
### It will autoconfigure itself with each yum update.
### This is adapted from a previous script for CentOS 5.5 found here:
### http://www.linode.com/docs/assets/542-centos5-native-kernel-selinux-enforcing.sh
### Provided via the linode wiki
### https://www.linode.com/docs/tools-reference/custom-kernels-distros/run-a-distributionsupplied-kernel-with-pvgrub#centos-5
### Provided without warranty, although since it should only be run
### on first box build if your box gets broken simply rebuild it
mkdir /boot/grub/
DISTRO_PLATFORM=`uname -p`
AWK_VERSION_MATCH="{if(\$1==\"kernel.$DISTRO_PLATFORM\") print \$2}"
KERNEL_VERSION=`yum -q list kernel | awk "$AWK_VERSION_MATCH"`
### Write template grub.conf
cat > /boot/grub/grub.conf << EOF
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initramfs paths are relative to /boot/, eg.
# root (hd0)
# kernel /boot/vmlinuz-version ro root=/dev/xvda
# initrd /boot/initramfs-version.img
#boot=/dev/xvda
default=0
timeout=3
title CentOS ($KERNEL_VERSION.$DISTRO_PLATFORM)
root (hd0)
kernel /boot/vmlinuz-$KERNEL_VERSION.$DISTRO_PLATFORM root=/dev/xvda
initrd /boot/initramfs-$KERNEL_VERSION.$DISTRO_PLATFORM.img
EOF
ln -s /boot/grub/grub.conf /boot/grub/menu.lst
yum -y install kernel
if [ $? -ne 0 ]; then
echo "ERROR aborting..."
exit 1
fi
@rwky
Copy link

rwky commented Sep 20, 2016

I've found that on CentOS 6 /dev/xvda needs to be /dev/sda

@chappy84
Copy link
Author

chappy84 commented Dec 11, 2016

@rwky specifically on Linode CentOS 6 builds or in general? If specifically on Linode this is possibly dependant on whether it's running on a Xen or KVM host, and the different CentOS 6 images Linode has for those

@chappy84
Copy link
Author

As far as the above is concerned. Linode themselves now provide a couple of guides:
CentOS 6 with GRUB (Legacy): https://linode.com/docs/tools-reference/custom-kernels-distros/use-the-distribution-supplied-kernel-on-centos-6-with-grub-legacy/
CentOS 7+ using GRUB 2 on KVM host: https://linode.com/docs/tools-reference/custom-kernels-distros/run-a-distribution-supplied-kernel-with-kvm/
I'd encourage you to use GRUB 2 instead of this if you're using CentOS 7+ on a KVM host (most likely on KVM after the Meltdown / Spectre issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment