Manually booting a Linux Kernel

After updating a server, rebooting it to load the new Kernel, removing the old Kernel and rebooting again, I got the GRUB minimal BASH-like prompt (I still can’t understand why, honestly), as if GRUB wasn’t able to see any info on how it should load the Kernel and the OS.

I know I could be very distracted but deleting all the Kernels seemed a little too much so I tried to manually boot the Kernel.

First, I checked what GRUB could see:

grub> ls
(hd0) (hd0,msdos1) (hd0,msdos2)

Listed the content of the disks to see what files were present and determine which one was the root filesystem:

grub> ls (hd0,1)/
lost+found/ vmlinuz-5.10.21-200... initramfs-5.10.21-200....img vmlinuz-0-rescue... initramfs-0-rescue....img

Set it as boot volume:

grub> root=(hd0,msdos1)

Loaded the Kernel image and RAM disk:

grub> linux /vmlinuz-5.10.21-200... root=/dev/sda1
grub> initrd initramfs-5.10.21-200....img

And finally booted the system:

grub> boot

Just in case, I also created a new GRUB config based on the currently running system:

grub2-mkconfig -o /boot/grub2/grub.cfg

Reset root password on CentOS

In the GRUB menu, select the kernel to edit and press e.

Go to the line starting with linux16 and add rd.break. You can remove rhgb quiet to see the boot process. Press Ctrl+x to boot in single user mode.

To access the system type mount -o remount,rw /sysroot and chroot /sysroot to treat sysroot as root directory.

Use passwd to change root password or pam_tally2 to unlock the account.

touch /.autorelabel to tell SELinux to do a restoreconf on next boot.

Exit and reboot.

Recover GRUB in CentOS 7

To recover GRUB, you’ll need the OS ISO image, in this case CentOS 7, and boot from it.

From the ISO menu, choose Trobleshooting -> Rescue a CentOS system and then 1) Continue; the system will be mounted under /mnt/sysimage.

To make your system the root environment run:

chroot /mnt/sysimage

Identify GRUB installation:

ls /sbin | grep grub

Install GRUB:

/sbin/grub2-install /dev/sdX

Exit and reboot.