Create and Restore Partition Images Using Partimage

Partimage is an opensource disk imaging software. Creating of image with this software is more faster than any other imaging software. You don’t have to wait for “dd if=/dev/zero” first. Coz during the copy, free blocks are not read. Then, if 20 % of the partition is used, partimage will avoid two access to 80 % of the free areas.

IMAGE CREATION
1. You need to run an fdisk to see what are the server partitions:

[root@server1 ~]# fdisk -l

Disk /dev/sda: 34.5 GB, 34527510528 bytes
255 heads, 63 sectors/track, 4197 cylinders, total 67436544 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001b9b7

Device Boot Start End Blocks Id System
/dev/sda1 2048 7999487 3998720 82 Linux swap / Solaris
/dev/sda2 * 7999488 28565503 10283008 83 Linux
/dev/sda3 28565504 67436543 19435520 83 Linux 

It is very important to run an fsck before doing partimage otherwise partimage will bomb out if its not clean from the first part.

[root@server1 ~]# fsck -y /dev/sda1
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/boot: recovering journal
/boot: clean, 35/28112 files, 16972/112420 blocks

[root@server1 ~]# fsck -y /dev/sda3
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/: recovering journal
Clearing orphaned inode 4325389 (uid=0, gid=0, mode=0100600, size=33554432)
/: clean, 125751/4980736 files, 2377162/4954044 bloc

2. There are few ways and options on creating an image;
OPTION 1: This will create one whole piece of disk image

[root@server1 ~]# partimage -B=0 -z0 -cod -V0 -M save /dev/sda1 part1.img
[root@server1 ~]# partimage -B=0 -z0 -cod -V0 -M save /dev/sda3 part3.img

# WHEREIN:
-B=0 = pattern response string
-z0  = compresslevel
 Set image file compression level:
    val=0: do not compress: very fast but very big image file
    val=1: compress using gzip: fast and small image file (default)
    val=2: compress using bzip2: very slow and very small image file

-cod = check the partition before saving, overwrite the existimg image file, description
-V0  = volumesize
-M   = create a backup of the MBR (Mast Boot Record) in the image file.
save = save the image
/dev/sda1 = is the source device to create an image
part1.img = is the output file of image

OPTION 2: This will create a multipart of image:

[root@server1 ~]# partimage -B=0 -cod -f3 save /dev/sda1 part1.img
[root@server1 ~]# partimage -B=0 -cod -f3 save /dev/sda2 part2.img

#WHEREIN:
-f3 = --finish action
Action to do if finished successfully:
    action=0: wait (do nothing)
    action=1: halt (power off the computer)
    action=2: reboot (restart the computer)
    action=3: quit

Created image should have the following when check:

[root@server1 ~]#  ls -l 
total 3069888
-rw------- 1 root root    7095846 Dec  3 02:25 part1.img.000
-rw------- 1 root root 2136738512 Dec  3 02:31 part3.img.000
-rw------- 1 root root  996641576 Dec  3 02:36 part3.img.001

Since you are done creating an image you will now need to copy the image somewhere else so you can restore it to another disk.

IMAGE RESTORATION
1. To restore from OPTION 1:

[root@server1 ~]# partimage restore -B=0 /dev/sda1 part1.img
[root@server1 ~]# partimage restore -B=0 /dev/sda3 part3.img

# WHEREIN
restore = is the command to restore the image
/dev/sda1 = is the target device to restore an image
part1.img = is the source file of image to restore

2. To restore from OPTION 2:

[root@server1 ~]# partimage restore -f3 -B=0 -cod /dev/sda1 part1.img.000
[root@server1 ~]# partimage restore -f3 -B=0 -cod /dev/sdb1 part3.img.000

# WHEREIN
restore = is the command to restore the image
/dev/sda1 = is the target device to restore an image
part1.img.000 = is the source file of image to restore

Spread the love

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.