Replace device-name-based partition identifiers with UUIDs in the GRUB configuration file to prevent GRUB boot failures after disk operations such as image imports.
Background
Device names such as /dev/vda1 can change after operations like image imports. If the device name in the GRUB configuration no longer points to the correct partition, the kernel fails to load the file system and the instance cannot start.
Procedure
Configure GRUB to identify the root partition by UUID to ensure reliable boot.
Modifying the GRUB configuration is a high-risk operation. Incorrect modifications can prevent your instance from starting. Before you proceed, create a snapshot for your instance to ensure data security.
Check the GRUB version
GRUB has two major versions: GRUB2 and GRUB Legacy. GRUB Legacy only receives bug fixes. Check your GRUB version as follows.
-
Identify your
GRUBversion:GRUB2
Check the structure of the
GRUBconfiguration directory:sudo ls /etc/grub.d/If the output includes files such as
00_headerand40_custom, you are usingGRUB2. Example output:00_header 05_debian_theme 10_linux 20_linux_xen 30_os-prober 30_uefi-firmware 40_custom 41_customGRUB Legacy
Check the contents of the
/boot/grub/directory:sudo ls /boot/grub/If the
/boot/grubdirectory contains amenu.lstfile, you are usingGRUB Legacy.
Locate the configuration file
GRUB2 and GRUB Legacy use different configuration file paths.
-
GRUB2:/boot/grub/grub.cfgor/boot/grub2/grub.cfg. -
GRUB Legacy:/boot/grub/menu.lstor/boot/grub/grub.conf.
Navigate to the /boot directory to find the GRUB configuration file.
Get disk partition UUIDs
Obtain the UUID of each disk partition for use in the GRUB configuration file.
-
View disk partition UUIDs:
sudo blkidExample output:
/dev/vda1: LABEL="/" UUID="e7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645" TYPE="ext4" PARTUUID="0efbxxxx-01"Here, the
UUIDof/dev/vda1ise7e8xxxx-xxxx-xxxx-xxxx-xxxxb9263645.
Modify the configuration file
-
Back up the current
GRUBconfiguration file:sudo cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bakImportantTo restore the
GRUBconfiguration file, run:sudo cp -f /boot/grub2/grub.cfg.bak /boot/grub2/grub.cfg -
Open the
GRUBconfiguration file:sudo vim /boot/grub2/grub.cfg -
Press
ito enter insert mode. Replace all occurrences ofroot=/dev/vda1withroot=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,115200n8Modified line:
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 -
Press
Escto exit insert mode, then type:wqto save and exit. -
(Optional) Verify that all disk partition identifiers in
GRUBnow useUUID:sudo cat /boot/grub2/grub.cfg
References
To configure the fstab file to auto-mount a data disk, see Auto-mount data disk using UUID.