Update Sep 22, 2007: This article was written when I had purchased a Thinkpad (refurbished T40) for the first time. The article had later been upgraded when my friends purchased T41 and T43. The backup solutions described here in this article are mainly using open source tools. Though I have tested them on Thinkpads, they should work equally well on other laptops which do not come with recovery media.
But after working with Thinkpad for more than a year and with my recent purchase of a T61, I have realized that an excellent software known as Rescue and Recovery is now being provided by Lenovo. This software not only helps in the creation of recovery media but also helps in taking a backup of your Windows OS. This is something which I strongly recommend you look at if you own a Thinkpad rather than going through this entire article.
Also be sure to have a look at the "Linux Installation Notes" section in the end as it has some very useful tips.
Creating Backup Images
Refurbished thinkpads come pre-installed with Windows XP. Initially IBM used to provide Recovery CDs so that if anything went wrong with the hard disk, the recovery cds could be used to restore it to the factory state. Hence there was not much a need of taking backup of the hard disk. But of late, IBM has changed its policy. All refurbished PCs (and new ones as well) come with something known as "Predesktop area". This predesktop area is a reserved 4 GB space (or a separate partition) in the hard disk and contains all the data necessary for performing recovery. In other words, instead of the recovery CDs, their content is now contained in this predesktop area.
This article is about backing up a Thinkpad and partitioning it so that other OSes (such as linux) can be installed. You must be familiar with linux in order to carry out the steps mentioned here. It is assumed that you have just received a new Thinkpad and all that exists on it is the installed Windows XP (a single big partition) and Predesktop area (hidden area/another partition in some thinkpads). Please note that generally predesktop area is not contained within a partition and hence your hard disk has only one primary partition (for Windows XP) and about 4 GB unpartitioned space at the end which is the Predesktop area. But I have observed that in some later thinkpads the Predesktop Area is generally contained in a fat32 / ntfs partition
We shall be covering the following topics in this section.
Following are the detailed steps:
We shall initially be creating a clone of the entire hard disk. This is absolutely mandatory so that if the hard disk / partitioning fails in one of the following steps, the entire hard disk can be restored to its original state. Once the partitioning is over and an image of Windows XP partition is taken, then this may not be that useful anymore.
We shall be using g4u for this purpose. g4u is a hard disk cloning utility which is very mature, well tested and proved. What I have recently found out is that g4u uses "dd" internally to make the hard disk image. This will be especially useful if you have a second hard disk to which you want to write the image as "dd" is an excellent tool for making hard drive images. You can find more infomration about dd in Wikipedia.
First, clean up as much space as possible from the drive. This is possible by booting into Windows XP and
- Running windows "Disk Cleanup"
- Removing old system restore points
- Clearing C:\Documents And Settings\user\Local Settings\Temp
Next defragment the disk using the Windows "Disk Defragmenter".
Next fill the free space with zeros so that the hard disk image will compress properly using gzip. There are many methods of doing this as discussed in the g4u homepage. I tried the cipher method for Windows XP but the problem was that killing the program in the middle had made some of the unsused space to be occupied. Hence I decided to use nullfile.exe.
Now reboot the PC and go to BIOS and disable the predesktop area (it should by default be in "Normal" mode). This is necessary because if it is not disabled g4u will not be able to back this space.
Download the g4u iso, burn it to a CD, boot the laptop using it and take backup. The backup took about 1.5 hours for me. My entire 33.86 GB was compressed to about 6 GB (3 GB for the windows partition and 3 GB for the predesktop area). The command I had used was:
g4u> uploaddisk your.ftp.server.com thinkpad.img.gz
where your.ftp.server.com is the ftp server with user account "install" setup. Refer g4u documentation for further info.
As an alternative to using g4u, if you have a second hard disk or a shared mount point, you can directly create an image using the "dd" command. But for using dd you may have to use a live linux cd such as "SystemRescueCD" (refer below). Assuming you are in the directory where you want to create the backup image, the command will be similar to below:
# dd if=/dev/hda | gzip -c9 > thinkpad.img.gz
where /dev/hda is the hard disk to be backed up. The image created using "dd" should be the same as the one created using g4u because from what I know g4u uses "dd" internally to create images.
Now reboot the laptop and the first thing you should do is enable the predesktop area and set it to "Secure". We shall later change the security back to "Normal". The reason why we are setting it to "Secure" rather than "Normal" is because now we are gonna create new partitions and we do not want this partition to be corrupted.
Our next task is to resize the windows ntfs partition and create extra partitions for linux and windows. For this you will have to use the tool gparted found on the SystemRescueCd. SystemRescueCD is a live bootable rescue CD with all the necessary tools to perform partitioning, backup and recovery. SystemRescueCD is perhaps one of the best works of how open source software can be combined to create one great open source product.
Download SystemRescueCD iso, burn to cd and boot laptop with it. Once booted, start the gparted partitioning utility. As we have set the predesktop area to "Secure" you will not be able to see this space / it will not have access (which will generally be seen as upartitioned/another partition if Predesktop security is disabled or set to Normal mode).
If you have Windows Vista, then I'd highly recommend that you resize the windows ntfs partition using the "Shrink Volume" feature of Windows Vista. Refer "Linux Installation Notes" at the end for furthur details.
After creating and resizing the partitions (in the previous step), reboot the system to Windows XP to check if everything is running properly.
Now reboot back using SystemRescueCd as we will now be taking backup of the ntfs partition using ntfsclone.
The command I had used for taking backup to the special image file is:
# ntfsclone --save-image -o - /dev/hda1 | gzip -c9 > backup.img.gz
The manpage of ntfsclone mentions that the spcial image format files cannot be mounted. But there is a workaround using which this compressed special image file can be accessed. For this first we will have to write the compressed image to a file. Please note this may require quite a lot of space (not more than the size of the partition of which the back was taken).
# gunzip -c backup.img.gz | ntfsclone --restore-image --overwrite backup.img -
After that we can mount it and access it.
# mount -o loop backup.img /mnt/windows
To enable read/write access, use ntfs-3g and mount it as below.
# ntfs-3g backup.img /mnt/windows
Now don't you think linux rocks ? :).
Next we shall backup the MBR using dd and the extended partition table using sfdisk (refer http://www.inference.phy.cam.ac.uk/saw27/notes/backup-hard-disk-partitions.html). We shall also take a snapshot of the current partition table using fdisk.
Taking a snapshot of the partition table:
# fdisk -l /dev/hda > partition-table.txt
# cat partition-table.txt
Backing up the MBR:
# dd if=/dev/hda of=mbr-backup count=1 bs=512
Backing up the extended partition table:
# sfdisk -d /dev/hda > hda-backup.sfdisk
This will be useful in the eventuality of MBR/partition table getting corrupted.
The final step we will be performing is to backup the Predesktop Area. In the thinkpad I saw, the predesktop area was a fat32 partition with size 4.3 GB. In the later thinkpads it is ntfs. I decided to keep it simple and use dd to create the image. So here is the command for taking backup of the partition (you may want to read the manual page of dd to find out the command syntax):
# dd if=/dev/hda2 | gzip -c9 > predesktop-area.img.gz
To mount the image, extract it first and then mount the file:
# gunzip -c predesktop-area.img.gz | dd of=predesktop-area.img
# mount -o loop predesktop-area.img /mnt/predesktop-area
where "predesktop-area" is an empty directory in /mnt.
Congratulations. Your backup images are now ready.
Writing the Backup Images to DVDs
K ... now you might be wondering - What's the big deal in writing images to a DVD? Any Tom, Dick n Harry can do it. Well now here is my question to you - Can any Tom, Dick n Harry write a bootable live cd which has all the tools in it to restore the image from the DVD. And the answer is "yes" :). Not because it is something very common but because it is something which I am gonna explain to you here and make it a trivial task.
The whole idea is to have the backup image we have taken earlier added to a LiveCD. This would help us to boot from the DVD in case of an OS crash and restore the image from the DVD itself rather than fetching the image from some other source such as a network. I shall create a DVD for the image taken using ntfsclone.
Initially I thought of taking a LiveCD ISO, remastering it to add the backup image and then creating a new ISO. I considered many live CDs and possibilities of customizing them to get this task done. Some of them being:
- Ubuntu Customization Kit
- Knoppix customization
- BusyBox and OpenSSH
But I wasn't happy with any of these for two reasons - 1. The process was not simple and 2. Knoppix and Ubuntu live CD themselves are about 700 MB each and I did not see any point in having so much space wasted on the DVD for the OS.
Brooding over the issue and further googling about it, I realized that the SystemResuceCD I had download earlier could be used for this purpose. SystemRescueCD is a liveCD (based on gentoo) which is extremely small in size and has all the necessary tools for performing partitioning, backups and restores. Initially I tried the steps outlined in How to burn a DVD with SystemRescue and 4 GB more files
to get the image written to the DVD containing SystemRescueCD. But then it did not always work properly and I was not completely satisfied with the process.
Then while further thinking about it, I came across this excellent idea. All I wanted to do was to add the ntfsclone backup image to a DVD which has a LiveOS. I was not really looking at remastering the liveCD iso. And thus I embarked upon a search for an ISO editor using which I could edit the SystemRescueCD iso, add the ntfsclone backup image to it and burn the new ISO to a DVD.
While searching for an ISO editor, I stumbled across the wikipedia page http://en.wikipedia.org/wiki/ISO_image from where I got to know of ISO Master, an open-source really good iso editor.
Assuming that you have already download the SystemRescueCD iso, open it using ISO Master, create a folder "ntfsclone-image", add the ntfsclone backup image to this folder and save the file as an ISO image (isomaster-image.iso). Certain things to keep in mind are:
- You should not overwrite the SystemRescueCD iso which you have downloaded. But you should save the ISO to a new file.
- Because you will be saving the ISO to a new file, you will be needing an extra space of (image size + SystemRescueCd size). That is to say if your image size is 4 GB and SystemRescueCD iso size is 120 MB (~0.12 GB) you will be needing a free space of 4.12 GB to create the new ISO file.
Having created the new ISO image in the previous step, now we will be testing if the iso was created properly and it is is working properly. First we shall be mounting it to check if the ntfsclone image was copied succesfully.
# mount -t iso9660 -o loop isomaster-image.iso /mnt/iso
# ls /mnt/iso/
# umount /mnt/iso
Next we are going to emulate the newly created ISO using qemu. Run the below command to check if the newly created ISO works properly.
# qemu --cdrom isomaster-image.iso
You should be able to see the exact simulation of booting a computer using a DVD on which this ISO is burnt.
Now we come to the final stage of writing the ISO to a DVD. Well, I am not going to mention anything about this here because as I already said any Tom, Dick n Harry can bun an ISO to a DVD :D. But yeah, if you are buring the ISO using K3b, then I'd suggest to write the DVD in "DAO" (Disk-at once) mode. This is because DVDs written in this mode have the maximum compatibility across all DVD-drives.
The same procedure can be used for backing up the g4u and dd images to DVDs. But for g4u image, you will have to download and use the g4u iso instead of SystemRescueCD as it does not contain the g4u utility. Also for backing up g4u image the normal single layer DVD may not be an option, as the size of the g4u image would be more than 6 GB (because it contains the installed windows xp parition + predesktop area) and you might have to buy a dual layer/double layer DVD for backing up the image.
Restoring Images
Restoring ntfs volume from compressed image file:
# gunzip -c backup.img.gz | ntfsclone --restore-image --overwrite /dev/hda1 -
Restoring the whole hard disk:
using g4u
# slurpdisk your.ftp.server.com thinkpad.img.gz
or dd (if image is accessible via a mount point)
# gunzip -c thinkpad.img.gz | dd of=/dev/hda
Restoring predesktop area image:
# gunzip -c predesktop-area.img.gz | dd of=/dev/hda2
Restoring MBR:
# dd if=mbr-backup of=/dev/hda
Restoring the extended partition table:
# sfdisk /dev/hda < hda-backup.sfdisk
Linux Instalaltion Notes
In order to accommodate space for installation of Linux it will be necessary to reduce the windows partition size. GParted is an excellent tool which can perform this operation. Bot Windows Vista now comes with "Shrink Volume" feature which I think is much more safe than using GParted. The exact procedure on how to do this can be found on the page How to Shrink and Extend NTFS Volumes in Windows Vista. Also note that you might have to perform the "Shrink Volume" operation several times to achieve the desired size.
While installing linux, you might be prompted whether to install the bootloader (GRUB/Lilo) in MBR or in the root partition. While installing GRUB in MBR is the easiest way to immediately access linux, DO NOT DO IT because this will overwrite the default MBR which might make the Linux Rescue and Recovery Environment unavailable.
Instead install the grub bootloader to the root partition. Next you can find the instructions for booting Linux from Windows bootloader at Booting Linux from Windows Boot Manager.
If you have windows Vista installed, then you can follow the instructions mentioned in How to use Windows Vista’s Boot Manager to boot Linux. Be sure to back up your current bootloader using the command "bcdedit /export filename" before making changes (run "bcdedit /?" for help).
Refer section "Proper MBR" in Rescue and Recovery - ThinkWiki on how the MBR can be restored. You might have to run the command prompt with administrator privilges (in Vista, this is done by right clicking on "C:\Windows\cmd.exe" and selecting "Run as Administrator").
The same page also has notes on how to access the Rescue and Recovery Application from grub. But I have not tested it.
Add new comment