If you haven’t already, it’s time to make Partition Image your new best friend. Why? Because Partition Image is an extremely helpful Linux utility that can restore entire disk partitions and save an entire Linux/Windows dual-boot installation.
This Daily Drill Down explains the steps you’ll need to take to install Partition Image, create a backup of an entire disk partition, and restore the partition to its original condition.
What you need
The latest version of Partition Image is available from the Partition Image Web site. Partition Image may be downloaded in either source code or binary format. To build Partition Image from source, several libraries must be pre-installed on your system. To avoid any problems with these libraries, download one of the statically linked binary packages. For this article, the static binary package for Red Hat 7.2 (the latest compatible package available at the time of this writing) was installed and used on a system running Red Hat 7.3.
To install the RPM package, use the rpm ivh partimage-static-0.6.1-1-rh72.i386.rpm command.
Partition Image is capable of backing up and restoring partitions using the following file systems:
- · ReiserFS
A new journalized and powerful file system
- · ext2fs/ext3fs
The Linux standard file systems
- · FAT16/32
DOS and Windows file systems
- · NTFS
Windows NT and 2000 File System (experimental support)
- · JFS
Journalized File System, from IBM, used on Aix (beta support)
- · XFS
Another journalized and efficient File System, from sgi, used on Irix (beta support)
- · HPFS
IBM OS/2 File System
- · HFS
Hierarchical File System: MacOS file systems (beta support)
- · UFS
UNIX File System (Berkeley Fast File System: FFS and Solaris File System are supported)
Using Partition Image
To start partition Image, run the /usr/sbin/partimage command as root and the screen shown in Figure A will appear.
|The opening screen in Partition Image|
Figure A illustrates the typical Partition Image screen, which is made up of selection areas, text areas, check boxes, radio buttons, and legends. Of course, I’m not talking about Web-based windows, but curses-based windows, so there is no pointing and clicking. To navigate around Partition Image, use the Tab key (to move from section to section), the space bar (to select a radio button or check box), the keyboard (to enter text), and the function keys (to save and exit).
The first step in backing up a partition is to unmount the partition using the umount command. To unmount a /home directory mounted to /dev/hda8, run the umount /dev/hda8 command as root. Once the partition is unmounted, it can safely be backed up.
Don't attempt to back up a mounted partition. Doing so could cause irreparable drive damage or data loss.
To back up a partition, the following steps are required:
- · Select the partition to be backed up from the list of available partitions.
- · Provide the name for the image file, such as /mnt/pc/homedir-backup.gz.
- · Select the action to be taken. In this case, Save Partition To A New Image File.
The partition selection section will list all partitions without the /dev directory, which is fine because /dev is implied. When naming the file, it would be wise to consider a date-stamp name. That way, it will be easier to archive your backups (or restore the latest version). Once the correct options are selected, press [F5] to go to the next screen, shown in Figure B.
|The most important option in this section is the compression level.|
This screen allows you to specify the type of compression you’ll use. The compression level determines both the size of the image file and the time spent creating that image. Higher compression creates a smaller file, but requires more time to perform the backup.In the example shown in Figure B, the Gzipped format is used, providing a larger file size than the Bzip2 format, which will allow the back up to perform more quickly.
Under the compression options, you can dictate how Partition Image is to act and then react during and after the process. On the left side, you can dictate that Partition Image is to check the partition before saving. This is a good idea because it's possible to create a backup of a bad partition. Another option is to add a description of the backup, which, again, would be a wise choice. By entering a description, you, or any administrator, will know exactly what the partition is.
On the right-hand side of this section, you can instruct Partition Image on how to behave once the backup is complete. I typically instruct it to wait so there's no possibility of rebooting or shutting down (halting) if there are problems.
The Image Split mode is used when you want to divide the image into several smaller files. This option is useful when the backup file created is stored on Zip disks or if the image file will be copied to a CD-ROM. For this example, the image file will be split into 700-MB pieces, which will be later copied to a CD.
Once the desired compression options have been selected, press [F5] to go to the next screen. This window prompts you for a description of the image file. Provide any descriptive name you like; in this case, I’ve used a description of the original partition and the date. Press OK to go to the next screen, which is shown in Figure C. This screen provides information on the partition that is about to be backed up. Press OK to begin the backup process.
|The Partition information screen|
The final screen appears once the backup is completed. This screen shows the time it took to create the image, the data transfer rate during the process, and the amount of data copied. Press OK to exit Partition Image.
Restoring a partition
To restore a partition, run Partition Image. Once the first screen appears, provide the following information:
- · The partition to be recovered.
- · The image to be used for the recovery.
- · In the Action To Be Taken window, select Restore Partition Image From An Image File.
Figure Dshows the Action To Be Done window with the options selected to restore a partition.
|The options selected in this screen will restore a partition.|
One important aspect to note is that Partition Image must be run on the machine that is to be repaired/restored. If only specific partitions are being restored (other than /root or /boot), it's a simple matter of running Partition Image as described below. If the machine has been rendered unbootable (or the entire machine has to be restored to a previous image), then a Partition Image boot floppy must be made. To create a boot floppy, follow the steps shown in Listing A.
In the Action To Be Taken window, look for the Image File To Create/Use entry. Here, you'll enter the complete path to the file to be restored. Note that in Figure D the image is located on the /mnt directory. This is because I'm pulling this file from an NFS server. This is not the only method of communicating to the backup server, but in the case of Linux to Linux, it is the best.
More on NFS
For information on configuring and using NFS, check out Bryan Pfaffenberger’s “Working with NFS.”
Once the correct options are selected, press [F5] to go to the next screen, which will present several options for the restore operation. The restoration may be simulated or actually performed
The list of options shown in Figure E allows you to select the action to be taken once the restoration is finished. For this example, the Wait option is selected. The next two screens will confirm the type of operation performed, and the successful completion of the restore process.
|If the Erase Free Blocks With Zero Values Option is enabled, all blocks that aren't used are erased with zero bytes.|
Using Partition Image across a network
Partition Image allows image files to be stored on servers and restored across a network. Network support allows several options not available on stand-alone systems:
- · SSL encryption is provided for security.
- · The image may be used for several computers.
- · Storing the image on a server may provide better security for the image file.
- · Computers with only one partition generally do not have enough disk space to save an image file.
Configuring the server
The server can essentially be any machine used to store image files. No partitions are actually saved or restored on this machine. (They are just stored for use by the various clients/servers on the network.)Use the following procedure to configure an image file server:
- · Add the user partimage to the server. The server will run under UID partimage.
- · Add the names of users allowed to use the server to the /usr/etc/partimaged/partimagedusers file.
- · Change the permissions of the /usr/etc/partimaged/partimagedusers file to 600.
To add the user vince to the /usr/etc/partimaged/partimagedusers file and change the permissions of the file to 600 at the same time, use the command shown in Listing B.
All users added to the partimagedusers file must already exist on the system and must have a valid password entry in /etc/passwd.
To activate the server, run the /usr/sbin/partimaged command.
One of the more important server options that you’ll need to set is which port will be used with Partition Image. The default port is 4025. To change the port, use the -p option with the partimaged command (shown above). To change the port to 4020, use the /usr/sbin/partimaged -p 4020 command.Make sure any users know when the default port is changed; otherwise, they won’t be able to reach the server.
The partimaged server should be run from the same directory where image files are stored. This directory will then become the current directory when the client specifies no path.
Once the steps are completed, the partimage server is ready for up to 10 simultaneous connections from clients.
Don’t be a victim of Murphy
Having a copy of disk partitions should be a default procedure for any Linux administrator. Without backups of partitions, Murphy’s Law will inevitably kick in and every piece of data on your server will be lost. Why take the chance when you can install such an easy-to-use tool and safeguard your livelihood?