Next Previous Contents

## 3. Usage

There are two ways to use Partition Image:

- The command line You must type a command. For example: partimage -od -f1 -z1 save /dev/hda12 /mnt/backup/hda12.partimg.gz
- The GUI (Graphical User Interface) This is an easy way: you just have to fill in the boxes in the GUI window.

You can obtain the list of all commands, by typing partimage --help, so they won't be explained here.

## 3.1 How to save a partition into an image file

When saving a partition, you must specify two important things. First, the partition you want to save. You must give the Linux name of the partition, then a file of the /dev/ directory. For example, if the partition to save is the first of your first IDE hard disk, it might be /dev/hda1. The second important thing is the file where to save this partition. This file is called the image file. To see what partitions your have on your hard disk, you can run fdisk or, you can type cat /proc/partitions. Then, you will have to type this information on the first window of Partition Image. In the screenshot, we are saving the /dev/hda12 partition to redhat-6.2.partimg.gz. The extension of the image file should fit with the compression mode which will be used (.gz for gzip, and .bz2 for bzip2). When ready, click on Next >

On the next window, you can choose many options. The most important one is the compression level. The size of your image, and the time which will be used to save the image depend on the compression level you use. The split options allow you to split the image file into several small files. It can be useful to save your partition into removable media, such ZIP drives. For example, you can split into files of 95 MB to fit on multiple Zip disks.

When all options are set, you can click on the save button to run the operation.

## 3.2 How to restore a partition from an image file

Restoring data will copy the data which were saved into an image file, into a partition. Data already on the partition you are restoring to will be lost! The partition to restore data to must already exist before you proceed. If it doesn't exist, you must create it before with a tool, such as fdisk, GNU parted, or other tools. You won't be able to restore information if it won't fit in the new partition, so make sure you create one with enough space.

Restoring an image into a partition is an easy operation. You must specify the image file to use (it will only be read), and the partition to restore (it will be overwritten). The only extra option you can choose is Erase free blocks with zero values. If this option is enabled, all blocks which are not used are erased with zero bytes. This may be useful if you want to be sure that the data which were on the partition before this operation are fully erased. If this option is disabled, old data which was on currently unused blocks can be accessed (with some difficulty), because nothing is written on these blocks. These old data can be read with tools such as dd (GNU convert and copy).

When all options are set, you can click on the restore button to run the operation.

The partition to restore must have the same size as the saved partition. If the partition is smaller than the original one, the operation will fail. If it is bigger, space can be lost. You can read the FAQ of this handbook, for more details about this.

## 3.3 What compression level to use ?

When you save a partition into an image file, you can choose one of four compression levels:

- none There is no compression
- gzip Image will be compressed with gzip (default)
- bzip2 Image will be compressed with bzip2
- lzo Image will be compressed with lzo

With No compression you will have a very big image file, which will have the same size of the used data of your saved partition. This is really interesting only if you have a lot of space. But this is very fast, and useful if you are dealing with small images (your /boot partition perhaps)

With Gzip compression you will have a small image file. This is the most useful mode, and the default setting. This operation takes more time due to the compression, but it creates a much smaller file.

With Bzip2 compression you will have a very small image file: Bzip2 has a better compression ratio than gzip on big files (though in some rare cases, it can actually create a bigger archive files). This will be very very slow to compress. This option is useful only if you really can't waste any space, or if you have a lot of time (you can run it before going to bed).

With Lzo compression this is a very fast compression algorithm. It's a lot faster than gzip, but a little less efficient. Choose this option if you have enough space to save a big image, and you want to save time. This compression level is available for version 0.7.0 of partimage and later.

You can compress and uncompress image files, after creation. For example, if the image redhat-6.2.partimg.gz was made with the gzip compression level, you can type gzip -d redhat-6.2.partimg.gz to uncompress the image file. You can also compress an image which was not compressed. For example, you can type bzip2 debian-2.2.partimg. This may be usful if you wish to experiment with other compression utilities. Partition Image will be able to read uncompressed files, or those created using a supported compression routine even though the software itself was not used for the compression.

## 3.4 The splitting option

Image files created by Partition Image are very big, and can reach a size of several Gigabytes sometimes. This can be inconvenient if you want to copy the files onto removeable Media, or burn CD-R discs from them for storage.

Splitting is an option to use when creating an image. It makes it possible to create a number of smaller files containing the partition image rather than one large one. Two splitting modes are available

- Automatic: when no space left A new volume will be created when there is no space left on the currently selected device. Then you will be asked for a new location to save the next part of the image.
- Into files of a fixed size Several files of this size will be created instead of one big file.

You can use the fixed size mode if you want to copy your files onto removable media, or CD-R. For example, to burn your image onto CD, you might want to split it into files of 600 MB. Then, you can specify a fixed size to use, in Kilobytes (in this example, it would be 614400 KB).

You can choose the automatic mode if you are not sure if there is enough space on a device for the destination image file. Then, if you run out of space, you will be asked for a new location, and the next part of the image will be written in this new location. This can be useful if you directly create your partition into a removable media.

## 3.5 The network support

Since version 0.5/0.6, Partition Image provides network support: it allows you to save the image from one computer (the client) onto another computer (the server)over a standard network. You can also restore a partition to a computer (the client) from the image stored on another computer (the server). This method provides SSL encryption support if the partition you save/restore contains data which needs to be kept secure. The server can work with several clients connected at the same time.

The network support is very useful in several cases:

- If there is only one partition on the computer whose disk is to be backed up. In this case ther is no spare artition to save the image to.
- If you don't have enough space to save the image file on the same computer.
- To increase the security: if the image file is stored on another computer, a disk crash or a virus on the client cannot damage the image file.
- It you have the same image file for several computers, which have the same partitions and the same software installed.

If the shared version of OpenSSL is installed on your computer (it must have been compiled with ./config --prefix=/usr -shared), then the SSL encryption is enabled by default.

There are two versions of partition image to use, and two kinds of computers: All the computers used in network operations must have a valid network configuration. You can use netcfg to do it.

### The server

The server is the computer which contains the image files. No partition is directly saved/restored on this computer.

First, you have to add a user partimag because the server will lose root capabilities as soon as possible (for security) and will continue to run under uid partimag. Don't make partimaged SUID, run it as root. Make a note of the IP address of the server, as you will need this for configuring the clients. If you are unsure of the address, you can run ifconfig . usually you will find the IP details listed under eth0. If you have several ethernet connections, you may have to check what the address is on the network you will be using. Note: If you are using DHCP on your network, you cannot rely on the fact that the server will always have the same IP address. In these cases it is better to assign a static IP address to the server.

By default the server software uses a login as a security measure to avoid giving read/write access to the image files to any user. This check can be disabled at compilation time, by typing ./configure --disable-login, if the security is not important. The first time you use partimaged, you will have to create accounts to allow clients to connect to the server. You must create a file which contains the list of the users which will be allowed to connect. This file is stored as /usr/etc/partimaged/partimagedusers by default. And its access mode must be 600, this file must belong to user 'partimag'. For example, if you want to allow linus to use the server, type: mkdir /usr/etc/partimaged && echo linus > /usr/etc/partimaged/partimagedusers && chmod 600 /usr/etc/partimaged/partimagedusers. The users added to this file must be existing users of the system (it must have an entry in /etc/passwd). When logging in, the passord must match the password of the user in the system. For the moment, only DES or MD5 passwords are supported, but it's now a standard.

Then run the partimage server version, by typing partimaged. If you want to change some settings, the best option is to specify these on the command line: Type partimaged --help for more information on these. The most important option is -p port which allows you to choose the port which will be used by the server. 4025 is the default port number. If you change this value, make a note of it so you can configure the clients accordingly. For ease of use, you should run partimaged from the directory where the image files are to be saved - then this will be the current directory when no path is chosen by the client. If you intend setting up a permanent server, it may be useful to setup a startup script to initialise the server automatically. The server is now ready to accept up to 10 client connections.

### SSL mode

Using SSL requires a certificate and a key file. Both files will be generated using "make certificates" when installing from sources. See FAQ if you don't have sources or you want to change certificate or key.

### chroot environnement

To improve security, you can run the server in chroot jail. Refer to FAQ for more details.

### The client

The client is the computer which contains the partition to be saved. The standard version of Partition Image will be used: don't use partimaged here. The first thing to do is to give partimage the IP address of the server. You can do it by using the -sIP option in the command line. Use -s192.168.10.2 for example. The second way is to check the network box, and to type the IP in the main window.

You can change the port to use with the -pPORT switch. Use -p4001 for example to use the port 4001. The default value is 4205.

All the other steps are the same as when there is no network. Then, the only important thing to change when you use the network is the IP address of the server. All the other steps are the same.

## 3.6 Using PartitionImage with Apple iMac

Thanks goes to Steffen Schwenke for all in this section.

Download the ISO partimage-0.6.0rc3-PPC-bootcd-1.img.bz2 and refer to next section to know howto to build the bootable cdrom. This is a bzippped ISO image, not a bootcd image. Type bzip2 -d *img.bz2 to decompress this image.

Insert cdrom and bootup your iMac and then

- press C on startup
- at the yaboot prompt type in -> cd
- pray that /dev/ram3 mounts ;)
- login as root (no passwd)
- start partimage

Note: the cdrom has to be on primary ide controller as slave (/dev/hdb) like on most iMac's. an nfs server is mounted automatically if you change the fstab on the ramimage

## 3.7 Making a backup of the partition table

### Introduction to partitions

Even if you have only one volume, your hard disk is divided into partitions. The standard MSDOS voulme label allows to have up to 4 primary partitions. The partition table is stored in the MBR (Master Boot Record). This area is the first 512 bytes of the physical hard drive. It also contain some code which will start the operating system, which can be the bootloader (LILO, grub, ...). If your hard disk is hda, parimary partitions are hda1, hda2, hda3 and hda4. It's easy to save to primary partitions table, by copying the MBR.

To get past this limitation of 4 primary partitions, you can create an extended partition. An extended partition is a primary partition which contains a lot of partitions. For example, if hda2 is an extended partition, its logicial partitions will lappear as hda5, hda6, hda7, ... even if you don't use 4 primary partitions. That's why you can have an hda5 device, with no hda4. The problem with extended partition is there is no table we can easily save. The extended partition contains a linked list. hda5 will point to hda6, hda6 will point to hda7 and so on. This makes it difficult to save the partition table of the extended partition.

Partimage can save the data of one partition, but it won't save your partition table. If you have a major problem with your hard drive, you may have to restore both the partition table and the data - having the images of the partitions won't be a lot of help on there own. Which is why we'll show you how to save the partition image now.

### Making a backup of the partition entries

We will save all the partitions entries (both primary and logicial ones which appear in the extended partition). In this example, we'll be assuming that hda (the first IDE hard disk) is to be backed up.

First, we will save the MBR with DD (GNU convert and copy)

- cd /root
- mkdir partition-backup
- cd partition-backup
- dd if=/dev/hda of=backup-hda.mbr count=1 bs=512

It will produce a very small, but very important file: 512 bytes of data. Now, we will save entries of the extended partitions:

- sfdisk -d /dev/hda > backup-hda.sf

sfdisk is a tool provided with the util-linux package.

IMPORTANT! You should now put these files somewhere safe - copy them to a floppy disk (and take a copy of it!), or burn them onto a CD. Keep these files safe. Do not leave them on your hard drive - if there is a problem with th drive, you may not be able to access these files, and while your partition images won't be wortheless, it will certainly be a lot harder to restore your data.

### Restoring partition entries from the backup

Be careful, restoring is a dangerous action - it can destroy data! First, we will restore the Master Boot Record:

- dd if=backup-hda.mbr of=/dev/hda

Then, here is how to restore extended partitions entries:

- sfdisk /dev/hda < backup-hda.sf

To finish, you will have to reboot your computer.

Next Previous Contents