27

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.

1
  • 1
    Why don't you use clonezilla (clonezilla.org) to make a snapshot of your old computer and restore it on the new one? I think it would really be easier because you seem to want to keep absolutely everything as is. Otherwise, making a backup (/home, /etc, /usr/local, /var) and restoring your data and customizations, except softwares is really easy too... To solve your current problem, you'll have to change the UUID(s) in /etc/fstab and /boot/grub/menu.lst. You can use Ubuntu install CD to get the UUID(s) [gparted or command line] and make the changes.
    – Golboth
    Aug 3, 2012 at 8:45

4 Answers 4

25

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.

2
  • Thanks Golboth. I ended up using your suggestion of using the boot repair disk and that worked.
    – snowguy
    Aug 3, 2012 at 12:50
  • please note that clonezilla might not actually fix this. i just copied my whole hdd (via clonezilla) to an SSD and had the exact same UUID for hdd and SSD, ended up changing the uuid manually on the ssd and then in the above mentioned files on the ssd to still have the fallback hdd as possible boot OS Jan 17, 2019 at 16:07
4

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:

  1. 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).
  2. 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

2
  • FYI, when I started I did not see the grub startup option (maybe though because it just boot directly into Ubuntu since it was the only OS). In any case I appreciate your help. I ended up creating a boot repair disk.
    – snowguy
    Aug 3, 2012 at 12:51
  • Thanks a lot! Your answer saved me from a bad end, when I foolishly changed the UUID of my fstab and Ubuntu could no longer start!
    – reexmonkey
    Aug 9, 2019 at 15:10
3

What I did instead of editing fstab and grub:

  1. I backed up those files on the fresh install of ubuntu ( tar -cvf /somedir/boot.tar /etc/fstab /boot/grub/grub.cfg )
  2. Restored from backup ( tar -xvpf /mnt/remotebk/full.tar )
  3. copy restored fstab file (cp /etc/fstab /somedir/fstab.restored)
  4. restore my fresh install boot files ( tar -xvpf /somedir/boot.tar -C / )
  5. 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.

1

In my case, the UUID that grub installed was different from my present UUID (sudo blkid) for my Windows partition (confirmed in grub.cfg). I tried various methods unsuccessfully. Finally I mounted the Windows partition with file manager and ran update-grub again and the UUID was updated successfully in grub.cfg.

1
  • The program is called update-grub and not grub-update. This is not quit obvious as the most grub commands starts with grub-.... Jul 30, 2013 at 8:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .