partimage for back up/restore
Consider the following scenario. You have installed a Linux distribution that comes with minimal packages. Additional packages have been installed from the Internet using a package manager. So, patiently, you’ve updated and customised the OS according to your needs. Now your friend does not have an Internet connection and needs all these additional packages on his system. Or, all of a sudden, the OS has crashed, and you don’t have enough time or resources to repeat all the steps. Under the circumstances, back up your partitions every time you update your system—this back-up can be shared with any other system or used to restore the OS when it crashes.
partimage helps you with these kinds of back-ups. It can be installed on many distros via package managers or, preferably, you can run it off a live CD. It is a part of the System Rescue CD.
Here’s how you back up a partition:
- Run the partimage command from a terminal.
- Select partitions for which a back-up needs to be taken.
- Specify the image name along with a suitable path. Another partition/removable disk has to be mounted in order to store the image in it. (In case of single partitions, or if none of the additional partitions have enough free space, you can use NFS- and Samba-shared mounts to save images on a remote computer.)
- Opt for ‘Save partition…’ and go to the next screen (short cut: F5).
- In the next screen, select the compression level, split mode and finish with other default options (Figure 5). Split mode (auto) means that when a volume in which the image is being stored is full, the image is split into multiple parts. Otherwise, fixed size parts can also be created for the convenience of storing on CDs/DVDs.
- You’ll be prompted to give a description of the image for later use, and one more confirmation screen before copying starts.
- The copying process will start now. Options are available to cancel, pause and resume the operation.
- A confirmation screen appears after the completion of the process.
The following are the steps for restoring a partition:
- Run partimage and choose the partition that needs to be restored.
- Give a path to the image (from a mounted partition/removable disk).
- Opt for ‘Restore Partition…’ and go to the next screen (shortcut: F5).
- Opt for defaults and hit ‘Continue’ (F5).
- Now, the image description should appear, which is given at the time of backup, and one more confirmation screen before restore starts. Figure 6 shows a typical restoration in progress.
- A confirmation screen appears after completion of the process.
Note: When restoring an image, the size of the partition that’s being restored should be greater or equal to the size of the original partition on which the backup is taken. However, the target partition is accessible up to the size of the original partition only, in case it is larger. Even though the image size is smaller with only used blocks, the target partition can’t be smaller than the original one.
Tip: When an image is created for a partition holding the MBR, only MBR can be restored to the system from that image at a later time, by choosing the option “Restore an MBR…” from the initial screen (refer to Figure 7).
Some machines may come with a single partition or not enough space on any of the existing partitions. One solution that was mentioned earlier is to use NFS/Samba to store images on a remote machine. Another simple solution is to use the partimage-server. A remote machine running partimage-server can be used to store images whose IP address and port can be specified during backup/restore of a partition.
partimage-server on any distribution and run it using the command
partimaged. By default, images are stored in
/var/lib/partimaged/. You can use the
--dest options to specify any other directory to store images on the server. Similarly, you can change the default port number 4025 with the
In order to connect to partimage-server during back-up/restore operations, simply opt for ‘Connect to Server’ in the initial screen (refer to Figure 5) and enter the IP address of the server and the encryption mode. Also change the port number to connect to if the server is using a port other than the default one.
System Rescue CD
A good utility that combines many of the tools discussed here in one CD is the System Rescue CD distro. It comes with many additional utilities like:
- An SSH server to allow other systems to log in remotely and copy files
- Filesystem checkers, scanners, mount and view contents of other partitions
- mkfs to create a new filesystem and sfdisk to set up partitions
- parted and GParted for partition manipulation
- Firefox/Dillo for instant browsing
- PXE server capability
Tips and tricks
- To set up a network manually on any live CD, use the following code:
ifconfig eth0 192.168.1.1 ifconfig eth0 up
Use a different device number other than eth0, if required. On the System Rescue CD you can use the
net-setup eth0command instead.
- While running g4u, make sure of your disk IDs by running the
partscommand first. For example, if the original disk is detected as wd1, and the second one as wd0, running
copydisk wd0 wd1will mean losing all your data in the original disk. Or a safer method is erasing all partitions in the target disk before cloning, by using GParted or any similar utility. Now parts on the target disk will not show any partitions, whereas on the original disk, partitions will be listed.
- In the System Rescue CD, if your partimage is already running, go to another virtual console (using Ctrl+Alt+F2, Ctrl+Alt+F3, etc) for mounting, checking image paths, etc. Use Ctrl+Alt+F1 to come back to the first console.
- Don’t try to save an image in the same partition you’re backing up.
- As Linux distros are compatible with many configurations, cloned disks or partitions work fine in systems with different configurations also— with the exception of one or two features. For example, an image taken for a Linux distro on a Core 2 Duo system works well with PIII or AMD machines also, only requiring you to tweak
/etc/X11/xorg.confaccording to new display settings, if you have a problem with starting the GUI.