Manual

From Partimage-ng

Contents

Building partimage-ng

Partimage-ng consists of two components: a shared library and a CLI utility. The library actually implements all the operations while the utility's main purpose is to parse and run commands. It's also possible to write a GUI application.

Partimage-ng (the library) uses several external libraries to handle different disk layouts and filesystems:

  • libparted - to handle partition tables, could be installed with the libparted package or downloaded at

[1]. Tested with libparted versions 1.7 and 1.8.7. NOTE that you cannot use libparted >= 1.8.8 since it's licensed under the GPLv3. GPLv2 and GPLv3 are not compatible and you cannot link partimage-ng against GPLv3 code (because the ext2fs libraries are GPLv2). See [2].

  • libext2fs - to handle ext2/ext3 filesystems, could be installed with the e2fslibs package or downloaded at [3]. No particular version is required, tested with 1.40.2
  • libntfs-3g or libntfs from ntfsprogs - to handle NTFS filesystems. Either will suffice but libtnfs-3g is preferred since ntfsprogs doesn't seem to be under active development. libntfs could be installed with the ntfsprogs-2.0 package or downloaded at [4]. libntfs-3g could be installed with the ntfs-3g package or downloaded at [www.ntfs-3g.org].
  • boost - partimage-ng requires various boost components. All of them are header-only except signals-mt. Download at [5].

Partimage-ng uses cmake as a build system which you can download at [6] or use distribution's package.

To build partimage-ng in a separate directory (out of source build) do the following:

cd partimage-ng
mkdir build
cd build
cmake ..
make
make install

To install partimage-ng run:

make install

Background info

Lets first define some technical terms to make the docs more clear. Usually a hard disk (a hard drive hereafter) has some kind of partition table on it which tells the operating system how the disk is split into small chunks: partitions. In partimage-ng we call this partition table a label. There are lots of label types, for instance, MSDOS, BSD, GPT. A well-designed label allows you to create an unlimited number of partitions but the most widely used label type MSDOS can host only up to 4 primary partitions. To work around this limitation MSDOS introduces an extended partition. This is basically one of those primary partitions further divided into logical partitions which allows you to have more that 4 partitions on an MSDOS-labeled hard drive.

That was a regular disk layout. Sometimes people (accidentally or intentionally) don't put any label on a hard drive and simply use the entire drive as a single partition. This kind of disk layout is also referred to as single-drive partition. Partimage-ng can detect and even create such a layout. But things get more complicated when it comes logical volume manager (LVM) (todo: explain).

Using partimage-ng is as simple as:

partimage-ng [options] command [arguments]

The command is usually either save or restore. As you may have guessed save means create an image file, restore means restore an image file.

Creating an image file

In this case the arguments specify what to save and to what file. For example,

partimage-ng save /dev/sdb to sdb.img

will create an image file of a label (ie, the entire hard drive including all partitions and the label structure) and save it to file sdb.img. As partimage-ng supports selective backup you can exclude any partitions you want from the image file:

partimage-ng save /dev/sdb excluding /dev/sdb1 to sdb.img

or

partimage-ng save /dev/sdb excluding /dev/sdb1 and /dev/sdb3 to sdb.img

if you want to exclude a set of partitions.

The example shown above explains one type of image files partimage-ng can create: an image of a label. The other type is an image of a partition set. You can specify a set of partitions to backup (even from different hard drives):

partimage-ng save /dev/sdb1 and /dev/sdb3 and /dev/sda1 to parts.img

Please note that a path to a single-drive partition looks exactly like a path to a label, i.e. /dev/sdb could point to a label (most likely) or to a partition that spans the entire drive. Partimage-ng will automatically detect the type of the device and handle it correctly:

partimage-ng save /dev/sdb to sdb.img 

will create an image of a label or a single-drive partition.

Viewing info about an image file

Before we move on to restoring image files we need to talk about how partimage-ng stores data in image files. As said above there are two types of image files: an image of a label and an image of a partition set.

An image of a label contains some data specific to the label and all partitions from that label which are numbered one after another starting from 1. A partition set image contains only saved partitions numbered in the same way. You can use those numbers (or IDs) to specify which particular partitions you want to restore. To view the information about an image just type:

partimage-ng imageinfo sdb.img

The output should look like this:

=== Label ===                                                                                                               
Label type: 1                                                                                                               
Number of partitions: 4                                                                                                     
Label size: 246016                                                                                                          
Rawdata count: 2                                                                                                            
=== Rawdata ===                                                                                                             
Offset: 0                                                                                                                   
Size: 446                                                                                                                   
Skipping 446 bytes                                                                                                          
=== Rawdata ===                                                                                                             
Offset: 512                                                                                                                 
Size: 31744                                                                                                                 
Skipping 31744 bytes                                                                                                        
=== Partition ===                                                                                                           
Partition id: 1                                                                                                             
Is standalone: 0                                                                                                            
Master partition id: 0                                                                                                      
Has snapshot: yes                                                                                                           
Type: 1                                                                                                                     
Filesystem type: 3                                                                                                          
Flags: 0                                                                                                                    
Start sector: 63                                                                                                            
End sector: 112454                                                                                                          
=== Partition ===                                                                                                           
Partition id: 2                                                                                                             
Is standalone: 0                                                                                                            
Master partition id: 0                                                                                                      
Has snapshot: no                                                                                                            
Type: 2                                                                                                                     
Filesystem type: 0                                                                                                          
Flags: 0                                                                                                                    
Start sector: 112455                                                                                                        
End sector: 240974                                                                                                          
=== Partition ===                                                                                                           
Partition id: 3                                                                                                             
Is standalone: 0                                                                                                            
Master partition id: 2                                                                                                      
Has snapshot: yes                                                                                                           
Type: 3                                                                                                                     
Filesystem type: 2                                                                                                          
Flags: 8
Start sector: 112518
End sector: 192779
=== Partition ===
Partition id: 4
Is standalone: 0
Master partition id: 2
Has snapshot: yes
Type: 3
Filesystem type: 3
Flags: 1
Start sector: 192843
End sector: 240974
Expected number of snapshots: 3
=== Snapshot ===
Parent partition id: 1
Block size: 1024
Total blocks: 56196
Used blocks: 2670
Bitmap size: 7026
Bitmap offset: 7
Skipping 2741106 bytes
=== Snapshot ===
Parent partition id: 3
Block size: 512
Total blocks: 80262
Used blocks: 1327
Bitmap size: 10034
Bitmap offset: 4
Skipping 689458 bytes
=== Snapshot ===
Parent partition id: 4
Block size: 1024
Total blocks: 24064
Used blocks: 996
Bitmap size: 3009
Bitmap offset: 7
Skipping 1022913 bytes

As you can see this is an image of a label containing 4 partitions. Partition with ID 1 is a primary partition, partition with ID 2 is an extended partition. Partitions 3 and 4 are logical partitions (master partition ID = 2). You can either restore the whole label or only selected partitions.

Restoring the image

When restoring an image of a label you have two options:

  • restore the whole label to a drive. In this case the target drive will be repartitioned according to the partition table (label) in the image.
  • restore only some partitions from the image. In this case the layout of the target device won't change and you get to specify which partitions and where to restore.

When restoring an image of a partition set you have only one option:

  • restore specific partitions from the image.

Restoring the whole label to a drive is easy:

partimage-ng restore sdb.img to /dev/sdb

To restore specific partitions from the image you have to know their IDs beforehand (partimage-ng imageinfo will show them). For instance, to restore partition #1 and partition #3 to /dev/sdb1 and /dev/sdb5 respectively from the image file sdb.img type:

partimage-ng restore sdb.img 1 to /dev/sdb1 and 3 to /dev/sdb5

Also, partimage-ng is able to restore an extended partition with all its logical partitions to another extended partition. For example, sdb.img contains an image of an extended partition (#2) with logical partitions (#3 and #5) and the target device has an extended partition on /dev/sdb2. To restore the extended partition type:

partimage-ng restore sdb.img 2 to /dev/sdb2

First, partimage-ng will delete all logical partitions on the target extended partition and then restore the logical partitions from the image file.

Special case: single-drive partitions

Saving a single-drive partition results in an image of a partition set with only one partition in it. For example, if /dev/sdb is a partition, not a label then type the following to create an image:

partimage-ng save /dev/sdb sdb.img

You can either restore it back to some drive as single-drive partition (to /dev/sdc for instance)

partimage-ng restore sdb.img 1 to /dev/sdc

or to a regular partition on some partitioned drive:

partimage-ng restore sdb.img 1 to /dev/sda1

In both cases you have to specify its ID (will always be #1) because it is an image of a partition set.

As you may have guessed you can create a single-drive partition out of a regular partition:

partimage-ng save /dev/sda5 to sda5.img
partimage-ng restore sda5.img 1 to /dev/sdc

Special case: LVM volumes

TODO

Other options

  • -b, --blocks number

Read/write the 'number' of adjacent filesystem data blocks at once. This improves performance.

  • -m, --exclude-mbr

Don't save the MBR boot code.

  • -g, --exclude-grub

Don't save the GRUB boot code.

  • -s, --save-swap

Save the entire swap partition, not just the filesystem structures.

  • -t, --description text

Add 'text' as description to the image file (max 65536 bytes).

  • -f, --force

Force the operation even if the device is mounted or busy in some other way.

  • -i, --ignore-bad-sectors

Skip bad sectors when creating an image of the device.

  • -c, --clear-bbmap

Clear the bad blocks map after restoring the image.