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:
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:
Refer to the following method to check the GRUB version.
GRUB2
Run the following command to view the structure of the
GRUBconfiguration file:sudo ls /etc/grub.d/The following command output is returned. If the output contains content such as
00_headerand40_custom, you are usingGRUB2.00_header 05_debian_theme 10_linux 20_linux_xen 30_os-prober 30_uefi-firmware 40_custom 41_customGRUB Legacy
Run the following command to view the structure of the configuration file in the
/bootdirectory:sudo ls /boot/grub/If the
/boot/grubdirectory exists and contains a file namedmenu.lst, you are usingGRUB 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.cfgor/boot/grub2/grub.cfg.GRUB Legacy: The configuration file is usually located in/boot/grub/menu.lstor/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:
Run the following command to view the disk partition information of the current instance:
sudo blkidThe 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
UUIDof the/dev/vda1device ise7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645.
Modify the GRUB configuration file
Run the following command to back up the current
GRUBconfiguration file:sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bakImportantIf 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.cfgRun the following command to open the
GRUBconfiguration file:sudo vim /boot/grub2/grub.cfgPress the
Ikey to enter the edit mode and replace all instances ofroot=/dev/vda1in the configuration file withroot=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,115200n8Content 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,115200n8Press the
Esckey to exit the edit mode. Enter:wqand press the Enter key to save and close the file.(Optional) Run the following command to view the configuration file after modification. Ensure that the disk partition identifiers configured in the
GRUBconfiguration 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.