Physical Server

When the Linux system boots, Grub reports an error indicating that no device is found

2024-12-17 08:12:23

Symptom

When the Linux system boots, Grub reports an error indicating that no device is found, as shown in the following figure:

Reason

This is usually due to a Grub configuration file error and the /boot partition cannot be found, resulting in an error.

Solution

Log in to the system and re-generate the Grub configuration file. Grub generally takes information from the current system to generate a correct configuration file.

1. Log in to the system

If you fail to log in to the system due to a fault, log in to the system by using the following methods.

Reboot the system and press "c" when the Grub boot menu (see below) appears to enter the Grub Shell.

This is the Grub Shell interface. Grub Shell is a Linux Shell-like environment where you can manually make configurations to log in to the system.

grub> ls # Check which devices are currently available. Here is the sample output
(proc) (hd0) (hd0,gpt5) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1)
 
grub> ls (hd0,gpt3)/ # You can view which files are in the file system and thus locate the /boot partition./ The boot partition usually contains vmlinuzus-xxx and initramfs-xxx files
lost+found/ efi/ grub2/ grub/ initramfs-3.10.0-957.el7.x86_64.img System.map-3.
10.0-957.el7.x86_64 config-3.10.0-957.el7.x86_64 symvers-3.10.0-957.el7.x86_64.
gz vmlinuz-3.10.0-957.el7.x86_64 ...
 
grub> root=(hd0,gpt3) # Sets the root variable to the /boot partition to avoid repeated input into the /boot partition
grub> linux /vmlinuz-3.10.0-957.el7.x86_64 root=UUID=c74bd658-cd12-414f-80c6-0200fe5a6685 # Specifies the kernel for Linux boot, and the UUID is used to specify the root partition. You can view partition content in ls to determine the root partition, and run ls -l to obtain the UUID of the partition (or the file system on the partition).
grub> initrd /initramfs-3.10.0-957.el7.x86_64.img # Specifies the memory file system for Linux boot. It must match the kernel version.
grub> boot # Boot the system
 It should be noted that the linux/initrd command is most commonly used, but some systems use the linux16/initrd16 or linuxefi/initrdefi command to specify the linux kernel and memory image. If the linux/initrd command does not work, you can use the cat $root/grub2/grub.cfg command in the grub shell to check the original grub.cfg to determine which command to use.
2. Update grub.cfg
After the linux system boots, log in to the system. Run the following command to regenerate grub.cfg.
## Back up the old grub.cfg file, just in case
GRUB_CFG=$(find /boot -name "grub.cfg")cp -v $GRUB_CFG /root
## Update grub.cfg# for centos/redhat/rocky/openEuler distributions
grub2-mkconfig $GRUB_CFG
# debian/ubuntu distributions
update-grub

After updating grub.cfg, reboot to test whether the problem has been fixed.


pErEcKXLTyzl