I needed a way of backing up my girlfriends Windows Vista laptop as it looked like it had a hardware fault. There are a few live CD’s that will automatically create backup images for you but the techie in me needed to know how to do it manually. (gotta do it the hard way!)
For backing up I used Knoppix 6.4.4 Live CD as it’s a good all round Linux live CD with great driver and software support including an xdesktop. Knoppix can be downloaded from here: http://www.knoppix.org/The software to do the actual backing up is DD which does an exact bit copy of the source disk. To compress the image the process used Gunzip. In this instance the destination disk is a 2TB external disk drive formatted as NTFS. If you’re using FAT32 or another file system, section 5 will need to be adjusted accordingly.
hda represented the source disk. hdb represents the destination disk. Substitute these for the disk names found in section 3.
- Boot into knoppix
- To gain access to root type:
su
- To verify source and destination disks,type:
fdisk -l
- Make sure no partitions are mounted from the hard disk your about to image. To do this open a terminal window and type mount. This will list all mounted partitions. Verify that your source disk (found in step 2) isn’t in the mount list.
- Mount your destination disk by typing :
mkdir /media/windows
mount /dev/hdb /media/windows/ -t ntfs -o nls=utf8,umask=0222
- To verify you can view the ntfs partition type:
cd /media/windows
- Then to list the files (if any) type:
ls
- To image the source disk and place the compressed image on your destination disk use the following command:
dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c > /media/windows/hda.img.gz
dd is the command to do the bit copy of the drive. If is the ‘input file’ which in our case is the hard disk we want to image. ‘conv=sync,noerror’ means that if dd finds any sectors of the disk it cannot read it will replace that part of image with 0′s. bs=64K is the block size used in the copy.
- Go make a coffee as it may take quite a while to image. You can use ls -lh on the directory that has the image file in to monitor its size progress.
- Its also a good idea to save a copy of the source disk details as you may need them to access partition information within the disk image. To do this type the following command:
fdisk -l /dev/hda > /media/windows/hda_fdisk.info
- As a sanity check you can view the file structure from within using the fdisk. You will need the number of cylinders from the document saved in step 10.
fdisk -l -u -C 592 /media/windows/hda.img
Hopefully you should see a list of files!
- Thats it, you should now have a complete image of the destination disk. The last thing we want to do is to unmount our destination disk before turning it off. To do this type the following command:
Umount /media/windows
I had trouble getting the disk to unmount. If you do you can use:
umount -l /media/windows
which means ‘lazy’ unmount and will force an unmount of the disk.
Restoring data from an image
So now you have a lovely new image of your machine, what can we do with it?
You have two options:
- Copy the data from the image back to another disk
- Decompress the image and mount the partitions to allow you to access the file system within linux
a) Copy the data from the image back to another disk
This can simply be done by using the command below.
gunzip -c /mnt/sda1/hda.img.gz | dd of=/dev/hda conv=sync,noerror bs=64K
b) Decompress the image and mount he partition
gunzip -c sda.img.gz > sda.img
create two directories
mkdir /media/windows/
mkdir /media/image/
Mount the disk that holds the image by using the command:
mount /dev/hdb /media/windows/ -t ntfs -o nls=utf8,umask=0222
Need a bit in here about how to get the offset.
Then Mount the image:
mount -o loop,offset=32256 -t ntfs /media/windows/sda.img /media/image/
You should then be able to browse the files on the image by typing:
cd /media/image/
ls -lh
To copy the data out of the image you can use the command:
mkdir /media/windows/backup
cp -r /media/image/files/* /media/windows/backup