Found something useful? Don't forget to leave a comment!

Wednesday, September 9, 2009

Hardware-independent Cloning of a Linux (Fedora) Install, Part 1


WARNING: The following tutorial is highly technical. If you are not proficient in a Linux environment, particularly with mounting, the following is NOT for you. As always, backup any and all important data.

A complete OS (re)install and format is always a pain. There’s so much more to do afterwards – installing drivers, setting up software, fine-tuning your user environment, and transferring personal documents and data. Combined, all these chores can make for a massive headache.

In the corporate world, this obstacle is often overcome by imaging. Simple bit-for-bit disk imaging works great when you have many computers with identical hardware configurations, but for those of us at home, what are the chances every single computer is the same? In this two-part series, I’m going to demonstrate how to clone a Fedora Linux 11 system from one machine to another, regardless of how different the hardware may be.

Before we begin, we’ll need to prepare a few things. In particular, you’ll need a reliable external storage device (aka a USB hard drive). Make sure your backup drive is large enough to hold your entire Linux install and then some.

Now we’ll need to prepare either a LiveCD or LiveUSB of PartedMagic. PartedMagic is an excellent live distro suited for system maintenance, disk partitioning and management, etc. In particular, PartedMagic comes with FSArchiver, the filesystem backup tool that will be the core of our efforts. One of the limitations of traditional imaging tools is that images must be restored onto disk partitions that are at least as big as the source disk. For example, a 50GB partition must be restored onto a partition >50GB – even if the partition is only partially filled to capacity. FSArchiver is much more lenient: images can be restored anywhere as long as there is sufficient capacity. If you only had 1GB of data on that 1TB partition, you only need a partition size of 1GB.

At the time of this writing the latest available versions were PartedMagic 4.4 which shipped with FSArchiver 0.5.8. Currently, FSArchiver 0.5.9 is out but unless you want to do some binary file replacement, we’re not going to bother.

There is documentation on preparing the LiveCD/LiveUSB at the PartedMagic website. The process is quite straightforward, so I will not go into detail here.

PART I – Backing up the Linux system

Boot into the Parted Magic environment. First, you need to take stock of your particular hard drive configuration and where your Linux is installed. Open a terminal and enter:

# fdisk –l


This will list all the hard disks present as well as the partitions on each drive. A typical Linux install may use anywhere from 1-3 partitions, or more if you have a complicated setup. On my example system, I have a 250MB /boot partition, a 15GB root (/) partition, and a big 250GB /home partition. As you can see in the screenshot above,, these partitions correspond to the devices /dev/hda1, /dev/hda5, and /dev/hda6 respectively.

Now that you know what partition(s) you are targeting, it’s time to mount the external drive to which the image will be written. This is a trivial task thanks to Parted Magic’s graphical mount utility – simply click the “Mount” button next to the relevant device/partition. My example drive is a Seagate 250GB USB disk on /dev/sdc1. The mount point in Parted Magic, then, would be /media/sdc1.


The target partitions – hda1, hda5, hda6 – are marked with a red stripe. My backup drive sdb1 for storing the image is marked with a blue stripe.

Finally, we arrive at the imaging step. Execute the command below, adjusting parameters as necessary. Change EXT to the /dev name of your backup media, and add the /dev name(s) of the target partition(s) you want to backup at the end.

# fsarchiver –v savefs /media/EXT/fedora.fsa /dev/TARGET1 [/dev/TARGET2 /dev/TARGET3]

Optionally, you can add the option –j X if you have a multi-core processor. Replace X with the number of processor cores. Also, if you wish to use compression, use –z Y, where Y is an integer from 1-9 (9 is the highest compression level, using LZMA).

Fore more information about FSArchiver’s command line options, please see this page.

Upon running FSArchiver as described above, you should see a scrolling readout of directories and files present on your system. The running time will vary depending on your CPU and disk speed, as well as the compression level used (if any).

This concludes Part I. Later, we’ll take a look at the steps required to successfully restore and boot the image on another computer, regardless of hardware differences.

No comments: