Restore the boot using grub2 for a Debian Squeeze VM

A given Debian Squeeze server running on a virtual machine was "cloned" using the vmSphere conversion tool.

The process was unsuccessful, it fail at 98%, after the tool tried to install grub. So, the VM have no boot loader.

I booted from CD into rescue mode, used the "grub reinstall" and reboot. Now grub was installed in MBR but it reports an error telling there is no such device and show an a string UUID and then fail (failing to find the root partition there is no way to continue).

After few hours of debugging I finally was able to make the virtual machine boot.

The problem and solution was very simple (only after you know it :) )

 - Debian Squeeze use grub2 which uses a file /boot/grub/grub.cfg for the boot process. This file is generated by grub-installer which uses grub-makecfg to combine the files in /etc/grub.d/ and generate that file.

In the grub.cfg file the root device is specified in a lot of places using UUID value which changed(as I should have expected) in the clone virtual machine since the created virtual drive is different.

Theoretically if you use grub-install --recheck /dev/xxx it should do the magic trick and change these values by itself. I remember I've had a similar problem and solved it with grub-install --recheck on a server that has software RAID1 problems but in this case, for some reasons, it did not worked.

If you are in a hurry and don't have time to make these tools work from a rescue environment which is pretty dump then the solution is very simple: all you need to do is to find out the new UUID of the root partition and replace it in the grub.cfg

To find the actual UUID of the root partition you can use

# blkid

If you are not sure which of the /dev/xxx is your root partition have a look in the /etc/fstab or use

# fdisk -l

to try to guess.

Another way is to mount each of those partitions and look into their content to find which one is the root.

Once you have the new id you use sed to replace the old UUID.

Suppose you've mounted the root partition under /target

# sed -i 's/old-uuid-here/new-uuid-here/g' /target/boot/grub/grub.cfg

Check the file to be sure the UUID has been changed and if not verify the UUID strings again in the sed command.

You must check the UUID's values carefully before start worrying why it's not working.

Suppose that you changed the UUID correctly, now you can reboot and the system will start correctly.

Related content