Find out how to back up and restore your disk partitions in Linux
Last month we saw how it’s possible to make a complete copy of a partition using the standard Unix dd tool, and how this is useful to back up an entire filesystem, no matter which type it is.
This month we are going to look a little more into this area, at a couple of other tools that can come in handy and how to detect problems with your hard drive.
As we saw last month, the major benefit of using dd is that it duplicates every single raw byte of data on the partition (be it a traditional hard drive or USB stick), enabling you to restore it all again, preserving the original exactly. This also leads to a major drawback: when you duplicate a drive or partition in this way, the copy needs the same amount of space as the original. When the filesystem you wish to copy is full, this may be not be an issue. But if you have a 500GB partition that has only 10GB of data in use, having to duplicate 490GB of empty data seems wasteful in terms of the storage requirement and the time it takes to copy such an amount.
A tool that deals with this problem well is Partimage (www.partimage.org). This handles partitions superficially in a very similar way to dd, in that it can create an image file from a partition which can then be restored later. The advantage it has here is that Partimage copies only the data that is in use on the filesystem. With that 500GB partition, the resulting image will be 10GB (with perhaps a small overhead).
Naturally, since only used data is being copied from the partition, Partimage needs to understand the filesystem it is backing up. In that respect it is really nothing like the dd tool, which is completely ignorant of the filesystem, and deals only in raw data. Partimage supports the major filesystems used with Linux, however, such as ext2, ext3 and ReiserFS. FAT16/32 is also supported, which is commonly found on USB sticks and older Windows installations. Additi onally, the image that Partimage creates tends to be very suitable for compression with standard Linux methods, like gzip and bzip2, and this facility is built into the Partimage application.
Partimage is a menu-driven terminal-based application, and as such is run from the command line. Despite not having a modern graphical interface, it is very easy to use. Enter ‘partimage’ at the shell prompt to start it up. The tool needs direct access to storage, so you will almost certainly need to be logged in as root to use it.
The attached image shows a list of partitions found, in the usual /dev/sda, /dev/sdb style. Each entry lists the filesystem type and the size of that partition. Use the tab key to switch to different sections of the screen; Shift & Tab can be used to go the other way. All that needs doing first is to choose whether to back up a partition or to restore from an image file, and to enter the path of the image file to create or use. When backing up there are a few more options.
On the next screen, select the compression level to use: gzip is probably the best option; it is much faster than bzip2 and will compress almost as well, in most circumstances. Now proceed to the final screen where Partimage will present a summary of information about the filesystem, including the amount of space used on the partition. Next, Partimage will begin copying the data, giving a progress indicator, as well as the current size of the image file for backups.
Never try to back up or restore a partition which is in use, particularly the partition you are running your operating system from. For that reason, Partimage needs the partition you are working on to be unmounted. This presents a problem if you want to back up or restore your operating system partition. The way around this is to use an alternative boot method, the easiest of which is a live CD. Here, since you are running the operating system entirely from a CD, you can work on any hard drive partition without restriction. There are several Linux distributions dedicated to this kind of task, and one good one is Parted Magic (www.partedmagic.com). This very small (50MB) distribution contains Partimage together with several other recovery tools, and is designed to work on older computers just as well as newer ones.
Updating your subscription status