Switching Linux kernel on OVH Dedicated Server with Soft RAID

OVH ships dedicated servers with their custom Linux kernels. I had to switch it for some functionality of our production site to run properly. First of all, grab a kernel using yum, and check its boot entry name.

yum install kernel
grub2-mkconfig -o /boot/grub2/grub.cfg
awk -F\' '/menuentry / {print $2}' /boot/grub2/grub.cfg

Here I had CentOS Linux (4.4.222-1.el7.elrepo.x86_64) 7 (Core) installed. Now we need to make it our default boot OS.

grub2-set-default 'CentOS Linux (4.4.222-1.el7.elrepo.x86_64) 7 (Core)'
grub2-mkconfig -o /boot/grub2/grub.cfg

At this point do not reboot yet. The initramfs has to be rebuilt since we're using soft RAID here. Check your RAID type:

$ cat /proc/mdstat
Personalities : [raid1]
md2 : active raid1 nvme1n1p2[1] nvme0n1p2[0]
      499054528 blocks [2/2] [UU]
      bitmap: 3/4 pages [12KB], 65536KB chunk

unused devices: <none>

I got raid1 here. So run dracut with raid1 driver:

dracut --mdadmconf --fstab --add="mdraid" --add-drivers="raid1" -f /boot/initramfs-4.4.222-1.el7.elrepo.x86_64.img 4.4.222-1.el7.elrepo.x86_64

If unfortunately you can't boot, for example GRUB2 doesn't work and it boots directly into rEFInd, go to the OVH panel and boot using network mode. This will most likely bring you to the OVH rescue kernel. Then re-install GRUB2:

yum reinstall grub2-efi grub2-efi-modules shim
grub2-install /dev/nvme0n1
grub2-install /dev/nvme0n2

Then it should work!