All Products
Search
Document Center

:How to Modify the File Disk Identifier to UUID in a Linux Image Grub File

Last Updated:Jul 12, 2022

Overview

This topic describes how to change the disk identifier of a Linux image in the Grub file to UUID.

Background information

In the Grub configuration, one of the kernel parameter Linux startup items is the root file system parameter. If this parameter does not point to the partition where the root file system of the system disk resides, such as the /dev/vda1, or the specified UUID does not match the actual UUID of the root file system on the system disk, the kernel may fail to properly load the root file system at system startup, resulting in system startup failures. The following example shows an incorrect configuration:

cat  /boot/grub2/grub.cfg
......
linux16 /boot/vmlinuz-3.10.0-1160.11.1.el7.x86_64 root=/dev/xvda1
......

In the above configuration, the root partition configuration name is /dev/xvda1. The name of the device may change due to the migration of the virtualization environment, such as the /dev/xvda1 change to /dev/vda1. Therefore, configuring the device name is not a reliable method. We recommend that you configure the device name as the device's UUID.

Solution

To modify the disk identifier of a file in a Linux image Grub file to UUID, perform the following operations:

  1. Connect to an ECS instance. For more information about how to connect to an ECS instance, see Use password or key authentication to log on to a Linux instance.
  2. Run the following command to view information about the block devices that exist in the current Linux instance:
    blkid
    If an output similar to the following one is returned, one of the solutions is applicable to your system kernel version:
    /dev/vda1: UUID="989ac477-64f2-449f-8415-25b1a5f7d47f" TYPE="xfs"
  3. Run the following command to edit the Grub configuration file, modify the UUID of the root partition as the root device, and save the modification and exit.
    vim /boot/grub2/grub.cfg
    The modified system display is similar to the following.
    ......
    linux16 /boot/vmlinuz-3.10.0-1160.11.1.el7.x86_64 root=UUID=989ac477-64f2-449f-8415-25b1a5f7d47f
    ......
  4. Run the following command to check the configurations of all root devices in Grub:  
    grep -n -E "(kernel|linux[16]*[efi]*)[[:space:]]+(/boot)?/vmlinuz-.*root=" /boot/grub2/grub.cfg /boot/grub2/grubenv
    If an output similar to the following one is returned, one of the solutions is applicable to your system kernel version:
    /boot/grub2/grub.cfg:100:       linux16 /boot/vmlinuz-3.10.0-1160.11.1.el7.x86_64 root=UUID=989ac477-64f2-449f-8415-25b1a5f7d47f ro console=tty0
    /boot/grub2/grub.cfg:115:       linux16 /boot/vmlinuz-3.10.0-1160.el7.x86_64 root=UUID=989ac477-64f2-449f-8415-25b1a5f7d47f ro console=tty0 
    /boot/grub2/grub.cfg:129:       linux16 /boot/vmlinuz-0-rescue-20201221114405071604847697217993 root=UUID=989ac477-64f2-449f-8415-25b1a5f7d47f ro console=tty0 
    /boot/grub2/grub.cfg:143:       linux16 /boot/vmlinuz-0-rescue-f607f552c07b43ff9c3a0fc5fe50ddf3 root=UUID=989ac477-64f2-449f-8415-25b1a5f7d47f ro console=tty0 

References

The following are the Grub versions and configuration files of each Linux distribution:

distro

System major version

Grub configuration file

grub-default

Grub version

CentOS

5

/boot/grub/grub.conf

None

grub-legacy

CentOS

6

/boot/grub/grub.conf

None

grub-legacy

CentOS

7

/boot/grub2/grub.cfg

/etc/default/grub

grub2

Debian

6

/boot/grub/grub.cfg

/etc/default/grub

grub2

Debian

7

/boot/grub/grub.cfg

/etc/default/grub

grub2

Debian

8

/boot/grub/grub.cfg

/etc/default/grub

grub2

Debian

9

/boot/grub/grub.cfg

/etc/default/grub

grub2

Ubuntu

12

/boot/grub/grub.cfg

/etc/default/grub

grub2

Ubuntu

14

/boot/grub/grub.cfg

/etc/default/grub

grub2

Ubuntu

16

/boot/grub/grub.cfg

/etc/default/grub

grub2

Opensuse

13

/boot/grub2/grub.cfg

/etc/default/grub

grub2

Opensuse

42

/boot/grub2/grub.cfg

/etc/default/grub

grub2

Sles

11

/boot/grub/menu.lst

None

grub-legacy

Sles

12

/boot/grub2/grub.cfg

/etc/default/grub

grub2

The image Grub file started by uefi is usually in the EFI partition directory. Run the following command. If the directory exists, the system is in the uefi startup mode.

ls /sys/firmware/efi/

The Grub profile path list in uefi startup mode is as follows:

 

distrio Grub configuration file
Centos /boot/efi/EFI/centos/grub.cfg
Redhat
/boot/efi/EFI/redhat/grub.cfg
Alibaba Cloud Linux
/boot/efi/EFI/alinux/grub.cfg
Fedora
/boot/efi/EFI/fedora/grub.cfg
CentOS Stream /boot/efi/EFI/centos/grub.cfg
Anolis OS
/boot/efi/EFI/anolis/grub.cfg
Rocky Linux
/boot/efi/EFI/rocky/grub.cfg
AlmaLinux
/boot/efi/EFI/almalinux/grub.cfg
Sles
/boot/efi/EFI/sles/grub.cfg
Opensuse
/boot/efi/EFI/opensuse/grub.cfg
Uebian
/boot/efi/EFI/debian/grub.cfg
Ubuntu
/boot/efi/EFI/ubuntu/grub.cfg

Ideal For

  • ECS