Play With Your Hard Disk Partitions

0
6395

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:

  1. Run the partimage command from a terminal.
  2. Select partitions for which a back-up needs to be taken.
  3. 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.)
  4. Opt for ‘Save partition…’ and go to the next screen (short cut: F5).
  5. 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.
  6. You’ll be prompted to give a description of the image for later use, and one more confirmation screen before copying starts.
  7. The copying process will start now. Options are available to cancel, pause and resume the operation.
  8. A confirmation screen appears after the completion of the process.
Figure 6: Options to save the partion
Figure 5: Options to save the partion

The following are the steps for restoring a partition:

  1. Run partimage and choose the partition that needs to be restored.
  2. Give a path to the image (from a mounted partition/removable disk).
  3. Opt for ‘Restore Partition…’ and go to the next screen (shortcut: F5).
  4. Opt for defaults and hit ‘Continue’ (F5).
  5. 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.
  6. A confirmation screen appears after completion of the process.
Figure 7: Restore in progress
Figure 6: Restore in progress

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).

Figure 5: Initial screen of partimage
Figure 7: Initial screen of partimage

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.

Install 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 -d or --dest options to specify any other directory to store images on the server. Similarly, you can change the default port number 4025 with the -p or --port option.

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
Figure 8: System Rescue CD
Figure 8: System Rescue CD

Tips and tricks

  1. 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 eth0 command instead.

  2. While running g4u, make sure of your disk IDs by running the parts command first. For example, if the original disk is detected as wd1, and the second one as wd0, running copydisk wd0 wd1 will 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.
  3. 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.
  4. Don’t try to save an image in the same partition you’re backing up.
  5. 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.conf according to new display settings, if you have a problem with starting the GUI.

References

LEAVE A REPLY

Please enter your comment!
Please enter your name here