I recently had a problem with VirtualBox, the free open source software I use for running virtual machines. The problem is that VirtualBox cannot compile the kernel modules for the new kernel, so VirtualBox does not start and I cannot run my VMs. This has happened a few times over the last few years.
The solution is simple – I need to revert to booting the previous kernel. Linux is designed to be able to do this for reasons just such as this one. Every time a new kernel is installed during upgrades older kernels are not discarded, they are saved. I usually save up to nine older kernels.
So I configured grub2 to boot to the previous kernel by changing the line GRUB_DEFAULT=saved to GRUB_DEFAULT=1 in /etc/default/grub. Normally the “saved” option specified in that line says that every time that Linux boots, grub saves the identity of the kernel that was booted and that becomes the default kernel for the next boot. So if I were local to the computer, I could simply choose a different kernel to boot to at the initial Grub selection menu and that would become the default from then on.
Changing that option to 1 tells grub to boot to the first saved kernel. The numbering system starts at zero (0) for the current kernel and increases by 1 for each sequentially older kernel. You can see the older kernels in the /boot directory. Grub2 creates the boot menu on the fly using the kernel files in this directory.
After making that change to /etc/default/grub I generate the new grunb.cfg file using the following command.
[root@studentvm1 grub2]# grub2-mkconfig > /boot/grub2/grub.cfg
Now I can reboot and the desired kernel is loaded and VirtualBox runs as it should.
You can read more about Linux boot, startup, and grub2 in Volume 1, Chapter 16, “Linux Boot and Startup,” of my self-study series “Using and Administering Linux: Zero to SysAdmin.”