Backing up / migrating your hard disk data with a Ubuntu live CD

Recently two hard disks died in my household, both of which were Windows boot disks, just as if I needed a reminder how quickly one can lose important data. This and some troubles while upgrading my Gateway M-6750 notebook from Ubuntu 9.04 to Ubuntu 9.10 (“Karmic Koala”) prompted me to get some spare hard disks and do a complete backup / upgrade.

I upgraded my notebook from 250 GB to 500 GB, and I can now keep my old drive as a safe snapshot to go back to if anything should ever go wrong with the new drive.

The most important tools needed for this were an Ubuntu 9.10 live CD from an ISO image (downloaded with uTorrent) and the NewerTech Universal USB 2.0 Adapter, which lets you hook up just about any IDE or SATA drive to a USB-equipped computer.

My notebook has Windows Vista on it, for which Gateway did not ship an install DVD – theres’s only a recovery partition. For installing Ubuntu I had originally shrunk the Vista NTFS partition on the 250 GB drive to make space for a 60 GB Linux partition, which provides a dual-boot feature via the GRUB loader.

I ordered some WD Scorpio Blue 500 GB notebook hard disks (WD5000BEVT) from Amazon and they arrived the next day. These are good work horse drives. I hooked one up to the NewerTech Universal USB 2.0 Adapter and booted into the Ubuntu Live CD.

From there I started a terminal window and used the “dd” command to make an image copy of the drive, see below. Be very careful with the source and destination specification. Use fdisk -l to verify which drive is which and in some cases the USB drive will appear as /dev/sdc instead or /dev/sdb. For IDE (PATA) drives the names could be /dev/hda, /dev/hdb, etc. If you specify the wrong drive as the destination you could wipe out all your data!

sudo dd if=/dev/sda of=/dev/sdb

This will copy every single byte from the first SATA hard disk to the second SATA (or USB 2.0) hard disk on the machine. You won’t have to worry about what partitions there are and which one is bootable, because it will simply copy all of them.

I started it last thing before I went to bed. It took about 2 hours to copy the entire 250 GB of the existing to the existing WD2500BEVS to the new drive. In the morning I shut down Ubuntu, opened the bottom of the case and transplanted the new drive inside, which took a small screw driver and about 10 minutes. Then I fired up the machine again and it successfully booted both Windows Vista and Ubuntu 9.10 off the new drive.

Since the new drive had more space, I wanted to resize the partitions so that each could take 250 GB instead them having to share that space. GNU utility gparted lets you do that. It can shrink, grow and move partitions pretty any way you like. You can tell it the new size of a partition and how much space to leave before and after it.

I first did not know that gparted can move partitions as well as resizing them, so I decided to remove the Ubuntu partitions, grow the NTFS (Windows) partitions and the reinstall Ubuntu into the remaining space. Be careful when removing an Ubuntu partition in a dual-boot system, because the active loaded and its menu file will be in the Ubuntu partition. Thus if you shoot it without first making the Windows partition the active boot partition you won’t be able to boot off that hard disk any more! Either boot of your operating system install CD/DVD or off an operating system recovery partition (if available) and select the command prompt. From there use fixldr /mbr (2000/XP/2003) or bootrec /FixMbr (Vista / 7) to rewrite the Master Boot Record. This will disable the Ubunto bootstrap loader. Make sure Windows will boot without the Ubuntu boot menu coming up. No you can remove the Ubuntu
partitions.

With sudo gparted on the Ubuntu Live CD you can resize the NTFS partition for Windows to any sensible value. In my case I got an error because some NTFS data structures were in an inconsistent state. To fix that I had to boot Windows and run chkdsk /f from a command prompt and then restart. Windows fixed the problem and one restart later I was back in Ubuntu live and gparted was able to resize the partition

After that I installed Ubuntu into the free space that I’d left for it on the 500 GB drive.

Given the low cost of SATA and USB 2.0 drives versus the time and data lost when something goes wrong with your hard disk, I do recommend a full image backup like mine. The dd command also lets you copy drives or partitions to files, so you can back up multiple machines to one large drive.

2 thoughts on “Backing up / migrating your hard disk data with a Ubuntu live CD

  1. Thanks for sharing this Joe!
    Your information is helpful.
    I have two p4 pc’s about 8 years old and both have 2 hdd’s. I’ve upgraded the hdd’s and other hardware over the years so hopefully there’s no crash in the near future..
    I have Ubuntu 9.10 on slave hdd and xp pro on main hdd dual boot, on “my” pc. And only xp pro on main hdd on my wife’s pc.
    On my pc I set up her account in Ubuntu after getting mine set up.
    Making sure all is working properly “before” trying to copy this system onto the other pc.
    Problem may be with smaller hdd’s on the target pc, so I need to research some more before I proceed.

    Cliff

  2. Pingback: Björn’s Blog » Blog Archive » Exchanging a hard drive with Ubuntu LiveCD and gparted, disk image created with dd

Leave a Reply

Your email address will not be published. Required fields are marked *