Ubuntu – How to fix the UUID in Grub after restore from another machine

boot failuregrub2

I want to restore a complete tar backup of Ubuntu 12.04 with all my customizations, documents, installed software, etc. to a different machine.

I made the backup with the following commands:

sudo su
cd /
tar cvpzf ububackup.tgz --exclude=/ububackup.tgz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/tmp --exclude=/media /

On the new computer I did a fresh install of Ubuntu 12.04, moved the backup file to it and then restored with the backup file with the following:

tar xvpfz backup.tgz -C /

As expected (see Mike Whatever's answer to this question: Copy Ubuntu distro with all settings from one computer to a different one) this broke grub. When I turn on the computer I get an error:

error: no such device: ...

press any key to continue ...

I believe the reason that Grub is broken is that the UUID it is looking for matches on the old hard drive not on the hard-drive for the computer.

How can I fix my grub to recognize the new hard-drive? I looked online for help "Fix GRUB UUID" but the steps seemed either out of date or complex. The response from Mike I linked to above gives me hope that there is a fairly simple way to repair this.

Best Answer

To solve your current problem, you'll have to change the UUID(s) in "/etc/fstab" and "/boot/grub/grub.cfg" (very tricky).

You can use Ubuntu install CD to get the UUID(s) with gparted (you just have to right click on the partition for which you want to get the UUID, and click on "Information", then select UUID and copy it with CTRL + C) or command line (sudo blkid).

Then you have to edit "/etc/fstab" on the right volume with gedit, nano or else.

In a terminal, type:

gksudo gedit /etc/fstab

and replace the old UUIDs by the new ones.

IMPORTANT : Of course, if you use a boot CD to do that you'll have to add "/media/xxxxx" before "/etc/fstab" : "/media/xxxxx/etc/fstab". You can also use gksudo gedit and open the file to edit yourself.

WARNING : Modifying "/boot/grub/grub.cfg" is very tricky. It should normally be generated with the command sudo update-grub.

Replace the old UUIDs by the new ones in "/boot/grub/grub.cfg" by entering the following in a terminal :

gksudo gedit /boot/grub/grub.cfg

IMPORTANT : Of course, if you use a boot CD to do that you'll have to add "/media/xxxxx" before "/boot/grub/grub.cfg" : "/media/xxxxx/boot/grub/grub.cfg". You can also use gksudo gedit and open the file to edit yourself.

If you use the tricky solution, I recommend you to launch sudo update-grub once you have successfully booted the system.

A cleaner but simple way to reconfigure grub properly may be using a boot repair disk like "Boot-Repair-Disk" : http://sourceforge.net/p/boot-repair-cd/home/Home/

I hope that this will help you to solve your problem.

However you might consider using Clonezilla to replicate the old computer on the new one as indicated in my comment.

Related Question