Updated on 2026-06-16 GMT+08:00

Changing Disk Identifiers in the GRUB File to UUID

Scenarios

To ensure that Linux can correctly identify disks when starting the file system, you need to change the disk identifier in the GRUB file of the ECS to UUID before creating a Linux private image.

Modifying the GRUB file is a high-risk operation. Incorrect configurations may cause system startup failures. We strongly recommend that you create snapshots or backups for the VMs or servers so that you can quickly roll back in case of misoperations.

Procedure

  1. Log in to an ECS as user root.
  2. Check the GRUB version and the configuration file path. Linux usually uses GRUB2 or GRUB Legacy, each with different configuration file paths.
    • GRUB2 (used by most modern Linux distributions, such as CentOS 7/8, and Ubuntu 18.04+): The configuration file is usually located in the /boot/grub2/grub.cfg or /boot/grub/grub.cfg directory.
    • GRUB Legacy (used by older systems): The configuration file is usually located in the /boot/grub/menu.lst or /boot/grub/grub.conf directory. To verify the bootloader version, check the directory structure by running ls /etc/grub.d/. If files such as 00_header and 10_linux are present, the system is configured for GRUB2.
  3. List all types of mounted file systems and their device UUIDs. In the command output, copy the UUID value.
    blkid

    The command output is as follows:

    /dev/vda1: UUID="ec51d860-34bf-4374-ad46-a0c3e337fd34" TYPE="ext4"
    /dev/vda2: UUID="7a44a9ce-9281-4740-b95f-c8de33ae5c11" TYPE="ext4"
  4. Query the grub.cfg file. (The following uses /boot/grub/grub.cfg as an example. You can adjust it as needed.)
    cat /boot/grub/grub.cfg | grep 'root='
    The command output is as follows:
    linux /boot/vmlinuz-3.13.0-24-generic root=/dev/xvda1 ro
  5. Check whether the /boot/grub/grub.cfg configuration file contains root=/dev/vda1 or root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34.
    • If root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 is contained, the root partition is in the UUID format. There is no need to change it.
    • If root=/dev/vda1 is contained, the root partition is in the device name format. Go to the next step.
  6. Identify the UUID of the root partition device based on root=/dev/vda1 (device name of the root partition) and the partition information obtained by running the blkid command.
  7. Open the grub.cfg file.
    vi /boot/grub/grub.cfg
  8. Press i to enter insert mode. Change the identifier of the root partition to the UUID format. For example, change root=/dev/vda1 to root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34.

    Replace the UUID value with the one obtained in 3. There is no need to retain the quotation marks.

  9. Press Esc, enter :wq, and press Enter. The system saves the configuration and exits the vi editor.
  10. Verify the change.
    cat /boot/grub/grub.cfg | grep 'root='
    The change is successful if information similar to the following is displayed:
    linux /boot/vmlinuz-3.13.0-24-generic root=UUID=ec51d860-34bf-4374-ad46-a0c3e337fd34 ro