Knowledge Base

Browse our knowledge base for free solutions to common problems

Rebuilding GRUB From Dracut Shell On CentOS Machines Failing To Boot

Created On: 14 September 2022
Written by: Ben


When Virtual Machine boots it complains that UUID's are incorrect.

From dracut shell run the following:

mkdir /mnt

Now mount the primary disk:

mount /dev/sda1 /mnt

Or depending on what disk drivers you are using:

mount /dev/vda1 /mnt

Bind the directories which grub needs to detect the other operating systems:

mount --bind /dev /mnt/dev &&
mount --bind /dev/pts /mnt/dev/pts &&
mount --bind /proc /mnt/proc &&
mount --bind /sys /mnt/sys

chroot to the /mnt/ directory:

chroot /mnt/

Ensure that fstab is correct and does not use UUID's:

nano /etc/fstab

My /etc/fstab was using UUID's instead of /dev/vda1 and /dev/vda2 so I changed them:

# /etc/fstab
# Created by anaconda on Wed Apr 15 08:07:35 2015
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
/dev/vda1        /                       ext4    defaults        1 1
/dev/vda2        swap                    swap    defaults        0 0

We now need to tell grub to not use UUID's when rebuilding. To do this open the grub config here:

nano /etc/default/grub

Add the following line to the bottom so that it looks like this:

GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"

Reinstall grub on the main disk:

grub2-install /dev/sda

Check everything is good with grub:

grub2-install  --recheck /dev/sda

Now rebuild grub:

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

To confirm that grub has been rebuilt correctly you can cat the boot.cfg file to look for any UUID references:

cat /boot/grub2/grub.cfg | grep UUID

If nothing appears all should be good.

Exit chroot and unmount all directories:

exit &&
sudo umount /mnt/sys &&
sudo umount /mnt/proc &&
sudo umount /mnt/dev/pts &&
sudo umount /mnt/dev &&
sudo umount /mn

Reboot the machine and watch her boot up fine.

ICTU LTD is a company registered England and Wales (Company No. 09344913) 15 Queen Square, Leeds, West Yorkshire, England, LS2 8AJ
Copyright © 2024 ICTU LTD, All Rights Reserved.