Partimage Backups

Whatever you’re doing, stop! Have you backed up your systems today? If so, great! If not, try Partimage to make copies of entire partitions.
Backups are easy to neglect, but that has great potential to cause problems. After all, it’s too late to create a backup once your hard disk crashes. At that point, you can only say “D’oh! ” in your best Homer Simpson voice or bang your head against a wall. Thus, you should create backups now — or at least as quickly as you can.
Of course, the first step in creating backups is planning your backup procedure. A plethora of backup hardware and software exist, and this column is too short to cover them all. Instead, let’s delve into just one backup tool: Partimage (http://www.partimage.org), an x86 and PowerPC tool that’s often used to create backups of critical system partitions. These backups can be copied to CD-Rs, recordable DVDs, tapes, or network servers with big hard disks. Partimage’s format is great for restoring an entire working system with minimal fuss.
Better yet, Partimage is an effective choice to create a standard Linux installation: just install Linux on one system, configure it the way you want it, back up its partitions using Partimage, and restore those backups on as many systems as you like, thus creating virtual clones of the first system.

Partimage’s Purpose and Features

Unlike backup programs such as tar and cpio, Partimage is a partition-based backup program — it backs up an entire partition at a time. In some respects, Partimage works much like using dd. For instance, you could back up a partition (say, /dev/hda2) using dd with:
# dd if=/dev/hda2 of=/tmp/hda2-back.img
You can then save that image file on some convenient medium or server and use it to restore the original partition.
Using dd in this way has several drawbacks, though:
*The backups are big. Even if the partition is mostly empty, the size of the backup file can be huge. Compression can help, of course, but if space on the disk has been used and then files deleted, data will remain in the place of the deleted files, as the filesystem just marks the sectors as unused.
*The backups are single files. Because dd backups can be so large, they may not fit on a single medium, particularly if you’re using small media such as CD-Rs. You can use additional tools to split them up, of course, but this increases the hassle of using dd for backup.
*The restore size is inflexible. You can’t restore a dd backup to a smaller partition than the original, even if the original was far from full. You can restore the backup to a larger partition, but then you’re unable to access some of the new space on the restored partition, because the restored filesystem appears to be the same size as the original. A filesystem-resizing tool, such as resize2fs, can expand the filesystem into the new space.
*Restoring individual files can be difficult. A dd backup can make restoring individual files tricky, particularly if the backup is compressed. (An uncompressed backup can be mounted using a loopback interface, but this trick won’t work with a compressed backup.)
Partimage fixes the first of these problems, since it’s smart enough to read the filesystem’s data structures and back up only the sectors that are actually in use. Partimage also automatically applies compression (if you choose that option). The result is a much smaller backup than dd would create.
Partimage also includes options to automatically split the backup into multiple files, simplifying storage on multiple backup disks. Unfortunately, Partimage does not yet permit restoration to a partition smaller than the source, nor does it automatically grow a filesystem to fit a target partition that’s larger than the original. Partimage also doesn’t make restores of individual files any easier than dd. In fact, if anything, it’s harder, because Partimage backups can’t be mounted using the Linux loopback driver. Thus, Partimage still suffers from the third and fourth problems of dd backups.
One advantage of Partimage is that it tends to be quick. The program reads the free space bitmap or its equivalent and then reads only those sectors that are in use. This means that the program doesn’t waste time reading unused sectors or seeking repeatedly between various filesystem data structures.
Overall, Partimage is best applied to creating system backups intended for full emergency restores or as template systems for subsequent installation on many computers. The fact that it reads low-level filesystem data to back up only those sectors that are in use means that Partimage is filesystem-sensitive — it needs support for the filesystem in use. As of Partimage 0.6.4, filesystems classified as having “stable” support are ext2fs, ext3fs, ReiserFS, JFS, XFS, FAT-16, FAT-32, and HPFS. In addition, UFS and HFS are supported in “beta” state, while “experimental” support for NTFS is available. (The main Partimage page reports that the primary problem with NTFS support relates to filesystems that use compression or that are heavily fragmented. Running a Windows defragmenter may enable Partimage to back up an NTFS partition that fails on the first attempt.)
Because Partimage is a low-level disk utility, it’s best used on partitions that are not currently mounted. Thus, if you want to use Partimage to back up your Linux root (/) filesystem, you should boot and run Partimage from an emergency disk, such as a Knoppix CD (http://www.knoppix.org).

Using Partimage to Back Up a Partition Interactively

Partimage provides two methods of control: an interactive text mode in which you use various keys to move about and select options, and a command-line mode in which you enter all the options you want to use on the shell command-line. The former mode is simpler to use if you’re unfamiliar with the program. However, if you want to create scripts to perform backups on a regular basis, or if you prefer using command-line options, you should look into the latter method.
Figure One shows the main Partimage screen, which you can obtain by
typing partimage.
Figure One: The Partimage interactive menu lets you select the partition to be backed up and other options



To back up a partition, follow these steps:
1.Highlight the partition you want to backup in the list at the top of the screen by using your keyboard’s Up Arrow and Down Arrow keys.
2.Press the Tab key to move the cursor to the “Image File to Create/Use” line and enter a filename for the Partimage backup file. Note that Partimage will add a volume number as a filename extension, beginning with .000. If you later select options to create a multi-file backup, subsequent files will have extensions of .001,.002, and so on.
3.Verify that the “Action to Be Done” selection is “Save Partition Into a New Image File.” If it’s set to restore the image or restore a master boot record (MBR), tab into that field, move to the “Save” option, and press the Space Bar to select it.
4.Assuming you want to back up to a local disk or to a conventional network mount (via Samba or NFS, for instance), ensure that the “Connect to Server” option is not selected. (Partimage includes a server to facilitate network backups, but its use is beyond the scope of this column.)
5) Press the F5 key to continue the operation. The screen changes to the one shown in Figure Two.
Figure Two: Partimage provides options to compress and split images



6.Select the options you want to use. The default compression level uses gzip, but you can improve it by using bzip2 instead, at the cost of slower operation. You may also want to check the image split options.
7.Press the F5 key to move on to the next screen.
8.Depending on the options you selected, you may be asked to enter a description of the backup. When you’ve done this, Partimage displays a summary of the partition, such as its used space percentage, label, and so on.
9.When you’ve accepted all these options, Partimage begins to work, displaying a summary screen like the one shown in Figure 3.
Figure Three: Partimage summarizes its activities as it backs up a partition



If you want to back up multiple partitions, you must do them one at a time; Partimage doesn’t support batch operations. Alternatively, you could write a bash script to do the job, using Partimage’s command-line mode rather than its interactive mode.

Using Partimage to Back Up a Partition from the Command Line

The second way to use Partimage is through its command-line options. You can type partimage–help to obtain a complete list of options.
The general syntax for using the command is: partimage[options]action device image_file
The action is the name of the action to be taken (equivalent to the” Action to Be Done” field in Figure One). The most common actions are save and restore, to save or restore an image, respectively. Partimage also accepts restmbr to restore an MBR and imageinfo to display image information.
The device is the device filename, such as /dev/hda2, and the image_file is the filename of the image file to be used.
The options are, as the name suggests, optional. Options you’re most likely to use are:
*–z# or ––compress=#. Set # to 0, 1, or 2 to use no compression, gzip compression, or bzip2 compression, respectively. The default is –z1.
*–d or ––nodesc prevents Partimage from asking for a description of the backup. It’s particularly handy when using the program in a script that should execute automatically.
*–V# or ––volume=#. Set # to the size of the backup image, in kilobytes. If you use –V but omit the value, Partimage creates volumes to fill the destination (which is handy if you’re using removable disks for the backup medium).
*–b or ––batch enables batch mode, which doesn’t prompt you for anything. This is most useful for scripts.
*–S or ––simulate simulates a restore, without actually writing data to the disk.
*–f# or ––finish=#. Set # to 0, 1, 2, or 3 to determine what to do when the operation completes: wait, shut down the computer, reboot the computer, or exit from the program. For scripting use, –f3 is appropriate if you want another command to follow the call to Partimage. The default is –f0.
A basic example of Partimage command-line use employs no options:
# partimage save /dev/hda2 /mnt/orb/hda2.img
This command backs up /dev/hda2 to the file /mnt/orb/hda2.img.000. (As with interactive use, Partimage adds the .000 extension automatically and increments that number for each volume in case of a multi-volume backup.) Using this command results in a display of the same screens that Partimage displays in interactive mode, including a prompt for a description. If your goal is to avoid such interactions entirely, you should use the –b, –d, and –f3 options:
# partimage –bdf3 save /dev/hda1 /mnt/orb/hda1.img
If you type this command, Partimage runs through the backup without further prompting, although it does still display its output on the console.

Restoring a Partimage Backup

Restoring a Partimage backup can be done in much the same way as creating the backup, but you must select the “Restore Partition From an Image File” option on the first screen (Figure One) rather than “Save Partition Into a New Image File.” When you do so, Partimage restores the image file you specify to the partition you specify. You must provide the complete and correct backup filename, including the volume number extension (.000 for a single-volume backup); Partimage won’t automatically add this extension if you don’t provide it. Once you’ve provided this information, Partimage proceeds to restore the data. The display looks much like that for a backup, but the operation goes in reverse.
You can also restore data using the command line options. Specifically, you pass the restore keyword as the action:
# partimage restore /dev/hda1 /mnt/orb/hda1.img
You can add the –b option to avoid having to interact with the program. If you omit this option, Partimage asks you to verify the operation you’ve just specified using its full text-mode interface. The –f# and some other options also apply to restores, although some, such as –d and –z#, have no effect on restores.

Partimage Caveats

Partimage is a very useful tool, but it’s not without its problems. The biggest disadvantage may be its limitations on restoration partition sizes. By itself, Partimage won’t enable you to restore a filesystem to a partition that’s smaller than the original, and if you restore to a larger partition, the extra space goes unused. You can use partition resizing tools, such as resize2fs, to resize the filesystem to fit the new partition.
As with dd, Partimage isn’t the best tool to use if you may need to restore individual files. Partimage is an all-or-none backup tool for an entire partition.
Partimage’s low-level access to partitions means that it shouldn’t be used on partitions that are mounted. (The program warns you if you try to back up a mounted partition.) This feature also means that the program must be run as root. As with most backup tools, you can easily wipe out the wrong data when restoring a backup, so be cautious when specifying a target partition for restores.

Roderick W. Smith is the author or co-author of over a dozen books, including Linux in a Windows World and Linux Power Tools. He can be reached at class="emailaddress">rodsmith@rodsbooks.com.

Fatal error: Call to undefined function aa_author_bios() in /opt/apache/dms/b2b/linux-mag.com/site/www/htdocs/wp-content/themes/linuxmag/single.php on line 62