Last updated $Date: 2008-09-06 05:57:01 $
Martti Kuparinen <martti.kuparinen@iki.fi>
http://www.iki.fi/kuparine/comp/windows/backup.html
This article describes how I created a backup image of my Microsoft Windows partition on my laptop after installing Microsoft Windows. With this method reinstalling Microsoft Windows is a simple and fast task.
We all know that one needs to reinstall Microsoft Windows from time to time, there are too many reasons to list here why a clean reinstallation is the best and maybe the only cure to your PC. And we all know that installing Microsoft Windows, the missing device drivers, all the updates and your other applications takes a long time, typically several hours.
I decided to tackle this problem by taking a snapshot of the whole Microsoft Windows partition right after clean installation on my USB disk. In order to follow this document you need to have:
This document was tested with Microsoft Windows Vista but it should work with other Microsoft Windows versions as well.
We need to perform a clean installation once. This will take several hours to complete so be prepared. First we install Microsoft Windows, next we install all the updates and all the missing device drivers. Finally we install other applications needed on this PC. Remember security while doing the initial installation, this must be done in a safe network behind a firewall or at least some NAT box. There's no point of installing Windows XP without SP2 while directly connected to a xDSL line and then later discover your PC is full of malware.
Things I usually install on every Microsoft Windows PC I use:
Once everything is ready, run Disk Cleanup (Start > Accessories > System Tools > Disk Cleanup > Files from all users on this computer), select everything from the Disk Cleanup tab and ask all system restore points to be removed (More Options > System Restore and Shadow Copies > Cleanup).
Next run CCleaner to remove some remaining garbage. Let it also find and fix all registry problems. Next run Auslogics Registry Defrag and finally Auslogics Disk Defrag. Now everything should be ready for the backup.
Before taking the actual backup we boot the PC with a Linux Live CD (or we could of course use the already-installed Linux on the same PC). The main thing is that we can NOT run Microsoft Windows while taking the backup. The backup disk is not used yet so there's no need to plug it in yet.
Open a terminal (Applications > Accessories > Terminal if you are using Ubuntu) and follow the next steps to first erase some files not needed on the backup image. Next we fill the unused disk space on your Microsoft Windows partition with zeros to make the compressed backup image as small as possible. Text shown in bold are commands which should be executed on the terminal.
# Check the partition table sudo fdisk -l /dev/sda Device Boot Start End Blocks Id System /dev/sda1 * 1 4864 39070048+ 7 HPFS/NTFS /dev/sda2 4865 6080 9767520 83 Linux /dev/sda3 6081 6202 979965 82 Linux swap / Solaris /dev/sda4 6203 19457 106470787+ 83 Linux # Set WIN to match your Microsoft Windows partition and then mount it export WIN="/dev/sda1" export MNT="/tmp/windows" # Mount the Microsoft Windows partition mkdir -p ${MNT} sudo mount -t ntfs-3g ${WIN} ${MNT} # Check the disk usage df -h ${MNT} Filesystem Size Used Avail Use% Mounted on /dev/sda1 38G 13G 25G 34% /tmp/windows # Remove files not wanted on the backup image cd ${MNT} sudo rm -rf \ hiberfil.sys \ pagefile.sys \ Users/*/AppData/Local/Temp/* \ Windows/Temp/* \ Windows/SoftwareDistribution/Download/* # Zero all unused disk space sudo dd if=/dev/zero of=REMOVE bs=32k sudo rm -f REMOVE # All done cd sudo umount ${MNT}
In order to take a backup of the Microsoft Windows partition, we boot to Linux (we either use Linux already installed on the same PC or a Live CD). Next we need to connect the backup disk and then we simply copy everything from the Microsoft Windows partition, compress it on-the-fly and store the compressed image on the backup disk.
# Where to store the backup image? df | grep /media /dev/sdb1 230G 163G 55G 75% /media/backup # Set DST to your backup disk (this could also be NFS-mounted) export DST="/media/backup" # Take a backup and compress it sudo dd if=${WIN} | bzip2 -9 -c > ${DST}/windows.bz2 ls -lh ${DST}/windows.bz2
Next we save the current partition table information so it's possible to re-create the Microsoft Windows partition with right size.
sudo fdisk -l /dev/sda > windows.txt echo >> windows.txt sudo cfdisk -Ps /dev/sda >> windows.txt echo >> windows.txt sudo cfdisk -Pt /dev/sda >> windows.txtRestoring Microsoft Windows from the backup image simple, we boot to Linux (again we either use Linux already installed on the same PC or a Live CD), connect the backup disk, decompress the backup image on-the-fly and copy everything to the Microsoft Windows partition.
# Set WIN (see chapter 3) and DST (see chapter 4) bzcat ${DST}/windows.bz2 | sudo dd of=${WIN}
The previous assumes we are restoring Microsoft Windows on a partition which is exactly the same size as the original partition. If there's need to have different size for the new partition, we might try this: