How to fix the UUID in Grub after restore from another machine?
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.
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.
Presumably this means grub starts and displays an option to boot to Ubuntu but when you select that it doesn't boot?
There are two options, I think:
- Use the GRUB line editor to modify the linux boot option to correctly load linux (and then run grub-install as root to permanently set the correct config).
- Boot from an Ubuntu USB stick, mount the ubuntu disk partition, chroot into it and then run grub-install.
The first case should be easier if you only have Ubuntu and only have a single hard disk, in which case select the "Ubuntu recovery" option, and press "e" to edit:
The entry should look something like:
insmod gzio
insmod part_msdos
insmod ext2
set root=('hd0,msdos0')
search --no-floppy --fs-uuid --set=root XXXXXX
linux /boot/vmlinuz-YYYYY root=UUID=XXXXXX ro recovery nomodeset
initrd /boot/initrd.img-YYYYY
Remove the "search" line and replace "root=UUID=XXXXX" in the "linux" line with "root=/dev/sda1". Try and boot this and hopefully after a short time it will give you the Ubuntu recovery menu, which should have a grub option, which should properly re-install grub.
Otherwise, or if you'd rather not mess around with grub directly (which should carry a health warning, use a CD/USB stick as documented in https://help.ubuntu.com/community/Grub2/Installing#Reinstalling_GRUB_2
What I did instead of editing fstab and grub:
- I backed up those files on the fresh install of ubuntu
(
tar -cvf /somedir/boot.tar /etc/fstab /boot/grub/grub.cfg
) - Restored from backup (
tar -xvpf /mnt/remotebk/full.tar
) - copy restored fstab file (
cp /etc/fstab /somedir/fstab.restored
) - restore my fresh install boot files (
tar -xvpf /somedir/boot.tar -C /
) - Rebooted and it worked.
I'm using vmware virtual machines, I did this process to move one linux server from one host to another host.