Partition images with Partimage and Partimaged

This is a guide to create or restore images of your partitions using the great open source tool Partimage. It provides information on how to do this locally or across the network, by setting up a Partimaged Server. I guess this info is non distribution specific, since we will work from a Rescue environment.

This is a guide to create or restore images of your partitions using the great open source tool Partimage. It provides information on how to do this locally or across the network, by setting up a Partimaged Server. I guess this info is non distribution specific, since we will work from a Rescue environment.

The same operations can be performed using the dd utility, but the usage of Partimage is recommended as it does not include the partition’s free space in the image, resulting in images smaller in size and less required time to complete the operation. Partimage is a command line tool with a basic ncurses user interface. For information about the supported filesystems, you can check its homepage.

Prerequisites

The most important thing when saving/restoring your partitions to/from image files is that they are not mounted, so to keep away from trouble. It is also highly recommended that these operations are done from a Rescue environment. Most distributions’ installation media provide such an option in their welcome screen or else one of the various Live CDs can be used.

We will use the statically built Partimage, so download this package from its homepage. This version does not have any dependencies, since everything has been built inside it and it can be run from anywhere. I suggest you save the package to a diskette.

Act professionally and keep detailed notes of the partitions you want to save or restore. A simple mistake in the partition names could lead to loss of data. Also read carefully the partition information presented by Partimage. For a list of your partitions, issue the following command:

# fdisk -l

Save/Restore Partitions Locally

The developers of Partimage have tried to keep the command line options pretty straight forward and provide some usage examples in the utility’s help message. Change to the directory where you have extracted the partimage package and have a look by typing:

# ./partimage --help

You do not have to provide any command line options, as almost all of them are accessible through the program’s user interface. You can access it by typing:

# ./partimage

Some of the keyboard shortcuts are:
F5 – Continue
F6 – Exit

To quickly SAVE a partition to an image file issue the command:

# ./partimage -z1 -o -d save /dev/hdb7 /mnt/storage/test_hdb7.partimg.gz

Make sure you substitute the device node (/dev/hdb7) with your partition and the path to the image file (/mnt/storage/test_hdb7.partimg.gz) with your own.
A little explanation of the options:
-z1: Use the gzip algorithm to compress the image. z0 means no compression and z2 means usage of the bzip2 algorithm, but it’s slower.
-o: Overwrite image files without confirmation.
-d: Do not ask for a description for the image. You can exclude this one if you want to save some notes about the image file you are going to create.
save: This is not an option, but the action that Partimage will perform.

To quickly RESTORE an image to a partition, type:

# ./partimage restore /dev/hdb7 /mnt/storage/test_hdb7.partimg.gz.000

Partimage adds a numeric extension to the images. This has a meaning only if you had set Partimage to automatically split the image into multiple volumes when you had saved the partition.

To see some information about an image file, issue the command:

# ./partimage imginfo /mnt/storage/test_hdb7.partimg.gz.000

Partimage saves the MBR of your disks together with your partition. You can avoid this by using the -M option when saving a partition, but I guess it does not hurt having backups of the MBR. The MBR is not automatically restored when you restore a partition.

To restore the MBR from an image file issue the command:

# ./partimage restmbr /mnt/storage/test_hdb7.partimg.gz.000

That will be it. One thing to keep in mind is to unmount the partitions before saving or restoring them.

Save/Restore Partitions Remotely

You can use Partimage to save/restore partitions remotely. To use this feature, you have to setup the Partimaged Server. The machine on which Partimaged is running will be the place where the partition images are saved to or read from. You run Partimage on the client machines and connect to the server in order to save or read the image files you want.

Configuring the Partimaged Server

The following operations must be performed on the server machine by root.

First of all, you need to create a new user, named partimag. When Partimaged is run as root, it soon drops priviledges and the partimag user is used to run the server for security. So, this user must exist. Create the user with the following command:

# useradd -c "Partimaged User" -s /sbin/nologin -r -M partimag

This creates a system account (-r) for the partimag user and does not create a home directory for it (-M). Also the user cannot login to a shell (-s /sbin/nologin). These useradd options should be the same among the various Linux distributions, but you should check the useradd man page to confirm that.

Next, you have to decide which will be the directory from where the Partimaged Server will run. This directory will also be used as a depot for the image files which will be saved or read by the client machines. For this article, a /var/partimaged_storage/ directory will be used. Create this directory:

# mkdir /var/partimaged_storage

Copy the partimaged executable file from the package you have downloaded to this directory and set ownership and strict permissions on this directory and its contents:

# chown -R partimag:partimag /var/partimaged_storage
# chmod -R 0700 /var/partimaged_storage

That’s it. Change to the /var/partimaged_storage/ directory. The server can be started with the following command:

# ./partimaged --debug=1

You can use the --dest and --port options if you intend to use another directory for image file storage or if you want the daemon to listen on a port other than the default 4025 for connections. The debug level is also set to "1", so that log information is written to the default logfile /var/log/partimaged.log. This option can be safely omitted, but this way no log file will be created. The server can accept multiple connections.

The above command starts the Partimaged Server and a monitor screen will be displayed, so you can watch which clients connect and monitor the progress of their operations. If you want to run the server in the background, then you should start the server with the --daemon option.

Finally, make sure you open the tcp port you have used (the default is 4025) in your firewall configuration.

Here follow some notes about security. The version of partimaged that comes in the package you have downloaded is not compiled with SSL or user logins support (at the moment of writing). This is probably for ease of use. This means that if security matters, you should compile the package yourself enabling all the needed options.

Because security does matter, I provide some info on how to connect to the Partimaged Server through encrypted SSH tunnels when you save/restore sensitive data. This way you can control which users can connect to the Partimaged Server by using SSH for access control and you can be sure that data does not travel in the clear across the network. Keep in mind that this is not the recommended way because SSH usually uses very strong encryption, so the whole operation could take a lot of time to complete and it will certainly devour your system resources. I suggest you compile partimaged with SSL and user logins support and make use of these features for security.

Save/Restore Partitions across the Network

Now that the Partimaged Server is up and running, you can use Partimage on the client machines and save the partition images to the server or read the partition images from the server and restore them on the client machines.

All the options that are used when you perform these operations locally can be used in this case, but you also have to supply the Partimaged Server’s IP address and the port it listens on. Furthermore, you do not have to supply a path for the image file, since the directory from where partimaged runs will be used to write the image files to or read them from.

So, to SAVE a partition from a client machine to the Partimaged Server issue the command (from the client machine):

./partimage --server=192.168.0.1 --port=4025 -z1 -o -d save /dev/hdb7 test_hdb7.partimg.gz

A path for the image file has not been specified. The above command also assumes that the server is bound on the 192.168.0.1 IP address.

To RESTORE an image file to the client machine issue the command:

./partimage --server=192.168.0.1 --port=4025 restore /dev/hdb7 test_hdb7.partimg.gz.000

Again, a path to the image file does not need to be specified.

The following information about connecting to the Partimaged Server through SSH tunnels is provided, but it’s not really recommended (see previous notes). It assumes that an SSH server is running on the machine where the partimaged daemon runs. Using this way, port 4025 does not need to be open in the server’s firewall.

To create the SSH tunnel and connect through it to the Partimaged Server to SAVE a partition from a client machine, issue the following command (from the client):

ssh -f -L 24025:127.0.0.1:4025 user@remote sleep 10; ./partimage --server=127.0.0.1 --port=24025 -z1 -o -d save /dev/hdb7 test_hdb7.partimg.gz

The same goes when you RESTORE partitions to client machines:

ssh -f -L 24025:127.0.0.1:4025 user@remote sleep 10; ./partimage --server=127.0.0.1 --port=24025 restore /dev/hdb7 test_hdb7.partimg.gz.000

For more information about this way of starting SSH tunnels, you can read a comment of mine on another page.

Final Notes

I have used Partimage numerous times to save and restore ext3 partitions and it has worked just fine. I also have some xfs partitions, but I never had the need to save or restore them, so I cannot tell. Partimage supports xfs. For information about NTFS or other filesystem support see the Partimage homepage and also have a look at linux-ntfs.org.

Further Reading

I consider that the following pages should be read for more information.

  1. Partimage Homepage
  2. The PartImage Handbook

Partition images with Partimage and Partimaged by George Notaras, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Copyright © 2006 - Some Rights Reserved

10 responses on “Partition images with Partimage and Partimaged

  1. Damien Permalink →

    Unfortunately it seems that the project has gone silent, their CVS has several forks of the code – the “stable” v0.6 branch was updated seven months ago for the release of v0.6.5, while the “development” v0.7 branch hasn’t been touched in almost two years. This sounds like an awesome project that just needs a bit more support, with a bit of work it’ll have the Symantec Ghost guys running scared :)

  2. George Notaras Post authorPermalink →

    I also believe that this project deserves more support, although I think it already provides most of the necessary features. The important thing is that I had no issues when using it and it seems that I like it much.
    Thanks for your comment.

  3. Michael Setzer II Permalink →

    I haven’t used partimage, but two other projects that use the dd approach are active, and with the clearing of the free space before imaging, it is not a big issue, and handles multiple partition types.

    G4U is a netbsd project that does images from a boot floppy or cd image.
    http://www.feyrer.de/g4u/

    G4L is a linux based CD project that has a gui to the creation using dialog and busybox.
    http://freshmeat.net/projects/g4l/
    http://sourceforge.net/projects/g4l

    I’m currently working on the next version with a working copy that adds some new options.
    ftp://fedoragcc.dyndns.org/g4l-v0.15.iso

    Totally free by the way…

  4. George Notaras Post authorPermalink →

    I was just reading about G4U. I’ll also try G4L. Both seem very nice.
    Before partimage I was using dd with gzip to save partitions. Now I see that besides partimage there are also some other nice projects. Thanks for posting this info.
    I also suggest that you give partimage a shot.

  5. Jacob Permalink →

    All three projects seem very interesting. At the same time I wish they could all work together to bring us one kickass product! Heck I’d even pay for it as the ghosts within Ghost can be a bit pissy at times. I would support this OSS with donations hehe.

    Here’s to dreams though and here to all three projects continuing and thriving. This is a much needed area for development.

  6. Jack Strangio Permalink →

    Just a small note of caution with partimage. I used to use partimage quite a lot to backup my NTFS partition. It worked well. However, one day I wanted to restore a partition which I had reduced in size. The size was still quite a bit larger than the amount of data which partimage had saved, but it was smaller than the partition had originally been. Partimage refused to restore the data. Oops!

  7. Korger Permalink →

    I’m sorry if this question sounds stupid, but what is the advantage of partimage over basic command-line tools? For example, in what way is

    # ./partimage -z1 -o -d save /dev/hdb7 /mnt/storage/test_hdb7.partimg.gz

    better than

    # dd if=/dev/hdb7 | gzip >/mnt/storage/test_hdb7.partimg.gz

    ?

  8. Claus Permalink →

    dd is working on a block base. partimage is working on a filesystem base.

  9. George Notaras Post authorPermalink →

    Furthermore, partimage does not include the free space in the image file. Contrariwise, dd does, but, as it has been mentioned in the previous comments, it can be cleared out. Links to the relevant projects, (G4U, G4L) can be found in the previous comments.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>