Search:  
Gentoo Wiki

HOWTO_Clone_a_Gentoo_system

This article is still a Stub. You can help Gentoo-Wiki by expanding it.

Contents

Introduction

To have a fully functional Gentoo system with a desktop environment as KDE takes several hours of compilation time. Everything is stored on the hard disk and it would be very frustrating to start the process from the beginning in case of a disk failure. Sometimes, we unmask too many packages and we want to get back to a clean and stable stage, preferably without recompiling anything.

We'll see how to take a snapshot of our Gentoo system and then how to restore it. Before you take a snapshot you have to decide where to store it. Usually, the snapshot is stored on a server but it could also be stored on a different partition of our hard disk (but then if we have a disk failure we do not have a snapshot to restore!). The snapshot is also named image because it is a copy of the state of the hard disk sector by sector.

There are many programs (most of them are commercial ones) that can do a system cloning, we'll use rsync, an open source utility that provides fast incremental file transfer. We'll put the snapshot on a dedicated server (from here on called BkServer) which should have enough disk space.

Before we start

Make sure that on the Gentoo system (i.e. the system which we want to clone) an ssh daemon is running and that rsync is installed. From now on we call this system SourceServer.

On the BkServer create a directory, called SourceServer_img, on a partition with enough disk space. One of the advantages of rsync is, that the source and destination partitions may be of different size: just be sure that the destination partition has at least the size which is used by files on the source partition.

Note: Make sure that rsync is installed on both SourceServer and BkServer.

Clone a system

Log on BkServer and execute the command

Code:
 # rsync -Saq --numeric-ids --exclude=/proc --exclude=/sys \
   -e 'ssh -c blowfish' SourceServer:/ path_to_SourceServer_img/

If we want to compress file data during the transfer we may add -z to rsync option but, on a 100 Mb ethernet connection, it takes more time to do compression than to transfer the bytes.

The '--numeric_ids' option will keep rsync from mapping uid/gid values by user/group name defined on the BkServer

The '-c blowfish' will speed up ssh (unless you use a system with hardware AES support and the fitting ssh patch, e.g. VIA padlock, leave this out then)

The '--exclude' will exclude files or directory based on PATTERN RULES. Please refer to the rsync man page for more and complete information.

Note: If you make use of '--exclude' option you may want to add '--list-only' to list the files instead of copying them before performing a cloning just to be sure that you don't miss any file
Note: Don't forget to create the /proc and /sys directories on the target system!

A few notes on the cloning process

With the command above we tell rsync to copy the root (/) filesystem. On the resulting image there is no information about the hard disk and the dimension of the partitions. We may restore the image on a completely different partition scheme provided that the size of each partition is great enough to hold the data stored in the image. To take note of the partition scheme of the cloned system we just need the output of the fdisk command:

Code:
 # fdisk -l /dev/sda

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1          63      506016   82  Linux swap / Solaris
/dev/sda2              64        1401    10747485    5  Extended
/dev/sda3            1402       19457   145034820   8e  Linux LVM
/dev/sda5              64          74       88326   83  Linux
/dev/sda6              75         707     5084541   83  Linux
/dev/sda7             708         717       80293+  83  Linux
/dev/sda8             718        1401     5494198+  83  Linux

substitute 'sda' with the correct device used on your system

If you use the LVM as I do, be sure to store the proper information on the volum group and logical volumes.

If you intend to restore the image on an identical hard disk, you may copy the MBR:

Code:
dd if=/dev/sda of=/tmp/MBR_backup.bin bs=512 count=1

Related Articles


Retrieved from "http://www.gentoo-wiki.info/HOWTO_Clone_a_Gentoo_system"

Last modified: Mon, 08 Sep 2008 06:30:00 +0000 Hits: 9,674