Backing up a step

In the Windows (dual-boot) world, I have been a huge fan of the free edition of Macrium Reflect for creating disk images of whole disks or disk partitions. Under Linux, I have restricted my backups to either file and folder synchronization using FreeFileSync, or real-time backup of my data partition using inosync. Now, it’s time to move on and find a Linux solution that will allow me to create backups of entire partitions using disk imaging.

“There are two kinds of people…. those who have lost
data due to a system crash, and those who will.”

Mike Epstein

As with most problems in the Linux world, there are multiple solutions to this task. Many of the available options are described in the Ask Ubuntu posting Comparison of backup tools.

However, one program that I have tried in the distant past, but that doesn’t appear in the Ask Ubuntu listings is partimage. Not remembering very well how partimage functioned, I decided to revisit the software. But, firstly one caveat. The reason that partimage is not included in the aforementioned post is probably because it is an old program and, while it supports the ext2 and ext3 file systems, it has no support for the more modern ext4 file system.

Partimage is available for downloading and installation through the Ubuntu Software Centre. Once installed, running the program in Terminal is as easy as typing its name. But, here’s (possibly) the first surprise. Partimage wants to have root access to function properly so, in order to avoid access denied errors, the program should be run with the “sudo partimage” command.

In my view, partimage runs as a quasi-graphical interface, much like old DOS programs. Navigation through the various dialogue screens is generally a combination of hitting the tab key to move between fields, pressing the space bar to select a specific option, and using the odd function key to, for example, move to the next screen. It sounds cumbersome but, once you understand how the screens work, they are actually pretty easy to manage.

For my particular application (see above screen shot), the source partition is selected as sda2. Given the somewhat cryptic nomenclature/descriptions, you had better be familiar with how your disk partitions are configured under Linux!

For my disk, sda1 is the Windows c: drive, sda2 is my data partition (drive d: in Windows and /media/Data_Disk in Linux). The extended partition is sda3, with sda5 and sda6 being the Linux root and swap file areas. The other two partitions are external drives – sdb1 is an external USB drive (/media/MYBOOK1) that I use for multiple backups, while mmcblkop1 is an SDcard used by inosync for backing up the data partition in real time. In this case, I have opted to create an image file named datadisk_22feb12 in the z_images/test0 folder of the external USB disk.

This all sounds fine but, once again, there is a surprise! Partimage complains that the partition is mounted and that “Partition Image can’t work on mounted partitions”. Hmmh… But, no real problem. Call up a second terminal window, and issue the command “sudo umount /dev/sda2”.

Re-running partimage now takes us to the next screen where we find that Gzip compression is set by default, and the image split mode is set to split the image “Into files whose size is… 2037 MiB”. Since we are using a large external hard drive, we can change this latter option to “Automatic split (when no space left)” in order to create a single image file.

Subsequent dialogue screens let us add a description for the image to be created, and provide a summary of the image format (e.g. block size, used space, etc.). Finally, pressing “OK” starts the imaging process. On my system, backup of an approximately 1 GB partition produced a disk image file (with a .gz.000 extension) of 767 MB in 1 minute, 40 seconds.

Now, if all these antics sound like way too much of a good thing, perhaps we should consider how to automate the process. We can easily do this with a bash script file. The script that I came up with is as follows:


# Unmount DataDisk
sudo umount /dev/sda2

# Check that the MYBOOK1 disk is available
if grep '/media/MYBOOK1' /etc/mtab > /dev/null 2>&1; then
# Run partimage
# Note that the -B switch seems to take any text, but must be
# present to stop the partimage GUI kicking in
sudo partimage -z1 -o -d -b -B=alan save /dev/sda2
echo " "
echo "Mount MYBOOK1 and try again"
echo " "

# Mount DataDisk
sudo mount /media/Data_Disk/

Essentially, this file unmounts the data partition, checks that the external USB drive is plugged in, runs partimage in “batch mode”, creates an image file named “datadisk_ddmmm12.gz” and, finally, remounts the data partition.

The switches used for the partimage command are:

-z1 use Gzip compression
-o overwrite any existing image file
-d no description
-b run in batch mode (GUI doesn’t wait for input)

The -B switch is a little strange. The partimage manual (man partimage) states:

-B ‘pattern response string’, –fully-batch ‘pattern response string’
full batch mode: the GUI is not being displayed. Rather status
messages are displayed as normal text. The pattern response
string has the following format: {glob-pattern}={response-value}…

This isn’t particularly intuitive; however, “Steve”, on the The Partimage/G4U Backup Page, says: “I don’t think that the value for the -B option does anything, but it does need to be there. In other words you need to use -B=something , but partimage does not seem to care what ‘something’ is.” In consequence, I opted to use the switch as “-B=alan” which seems to work just fine.

Running the bash script does indeed launch partimage which, as the manual suggests, provides a series of statements indicating the progress of the backup to completion.

So, the bottom line seems to be that partimage is a viable method of creating images of disk partitions (except for ext4), albeit with a somewhat cumbersome user interface, and a non-trivial batch file alternative. But, perhaps, there are other, more user-friendly solutions available? You guessed it – fodder for another blog entry or two…


About partimage

Comparison of backup tools

This entry was posted in Backup. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s