All Products
Search
Document Center

:Change the disk partition identifiers in the GRUB configuration file to UUIDs

Last Updated:Mar 31, 2025

GRUB is a program used to boot the operating system. You can use device names or UUIDs as disk partition identifiers in the GRUB configuration file. This topic describes how to change the disk partition identifiers in the GRUB configuration file to UUIDs.

Background information

In the GRUB configuration file, if a device name (such as /dev/vda1) is used to identify a disk partition, its device name may change due to operations such as instance startup after an image is imported. If the specified UUID does not match the actual UUID of the disk partition, the kernel may fail to load the file system when the system boots. This can result in a system boot failure.

Procedure

To ensure that the disk partition identifier of the root file system in the GRUB configuration file can be read by the program, we recommend that you use a UUID to identify the disk partition in the configuration file. Procedure:

Warning

Modifying GRUB configurations is a high-risk operation. If the operation is improper, the instance may fail to start. Before you perform this operation, make sure that you have created a snapshot for the instance to ensure data security.

Check the GRUB version

The GRUB program comes in two versions: GRUB2 and GRUB Legacy. GRUB Legacy is no longer developed and maintained except for occasional bug fixes. To check the current GRUB version, perform the following steps:

  1. Use Workbench to connect to the Linux instance over SSH.

  2. Refer to the following method to check the GRUB version.

    GRUB2

    Run the following command to view the structure of the GRUB configuration file:

    sudo ls /etc/grub.d/

    The following command output is returned. If the output contains content such as 00_header and 40_custom, you are using GRUB2.

    00_header  05_debian_theme  10_linux  20_linux_xen  30_os-prober  30_uefi-firmware  40_custom  41_custom

    GRUB Legacy

    Run the following command to view the structure of the configuration file in the /boot directory:

    sudo ls /boot/grub/

    If the /boot/grub directory exists and contains a file named menu.lst, you are using GRUB Legacy.

Check the GRUB configuration file

GRUB2 and GRUB Legacy differ in their configuration files.

  • GRUB2: The configuration file is usually located in /boot/grub/grub.cfg or /boot/grub2/grub.cfg.

  • GRUB Legacy: The configuration file is usually located in /boot/grub/menu.lst or /boot/grub/grub.conf.

You can refer to the preceding example to go to the /boot directory and check the GRUB configuration file.

Obtain disk information

You need to obtain the disk partition information of the current instance for later use in the modification of the GRUB configuration file. Procedure:

  1. Run the following command to view the disk partition information of the current instance:

    sudo blkid

    The following command output is returned:

    /dev/vda1: LABEL="/" UUID="e7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645" TYPE="ext4" PARTUUID="0efbxxxx-01"

    The preceding output shows that the UUID of the /dev/vda1 device is e7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645.

Modify the GRUB configuration file

Important

The following example uses the GRUB2 configuration file in the /boot/grub2/grub.cfg directory. If you use GRUB Legacy, or if your system has been customized for the GRUB configuration file, adjust the commands involved in Step 1 and Step 2 based on your business requirements.

  1. Run the following command to back up the current GRUB configuration file:

    sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
    Important

    If you want to restore the GRUB configuration file to the state before the modification, run the following command:

    sudo cp -f /boot/grub2/grub.cfg.bak /boot/grub2/grub.cfg

  2. Run the following command to open the GRUB configuration file:

    sudo vim /boot/grub2/grub.cfg
  3. Press the I key to enter the edit mode and replace all instances of root=/dev/vda1 in the configuration file with root=UUID=e7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645.

    linux   /boot/vmlinuz-3.16.0-4-amd64 root=/dev/vda1 ro single debian-installer=en_US net.ifnames=0 vga=792 console=tty0 console=ttyS0,115200n8

    Content after modification:

    linux   /boot/vmlinuz-3.16.0-4-amd64 root=UUID=e7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645 ro single debian-installer=en_US net.ifnames=0 vga=792 console=tty0 console=ttyS0,115200n8
  4. Press the Esc key to exit the edit mode. Enter :wq and press the Enter key to save and close the file.

  5. (Optional) Run the following command to view the configuration file after modification. Ensure that the disk partition identifiers configured in the GRUB configuration file are all changed to UUIDs.

    sudo cat /boot/grub2/grub.cfg

Reference

For information about how to configure the fstab file to mount data disks, see Configure UUIDs in the fstab file to automatically mount data disks.