Creating backup image from your Microsoft Windows partition

Last updated $Date: 2009-11-06 12:50:42 $

Martti Kuparinen <martti.kuparinen@iki.fi>

http://www.iki.fi/kuparine/comp/windows/backup.html

Abstract

This article describes how I created a backup image of my Microsoft Windows partition on my home PC after clean installation. With this method reinstalling Microsoft Windows is a simple and fast task.


Table of Contents

1. Introduction
2. Installing Microsoft Windows
5. Taking a backup
4. Restoring from a backup
5. Refreshing backup images
6. Useful links

1. Introduction

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.

I assume you have some Linux distribution already installed on the PC where you also have Microsoft Windows but if you don't, fetch some Live CD (e.g. fetch the latest Ubuntu Desktop Edition and burn it on a CD/DVD disk). Regardless of the Linux version, you need to install ntfsprogs. In Ubuntu, type

# Install ntfsclone
sudo aptitude install ntfsprogs

I created two scripts to do everything, win2bak create backup images from NTFS partitions and bak2win to restore NTFS partitions from backup images. You can install these scripts by typing

cd /usr/bin
sudo wget http://www.iki.fi/kuparine/comp/windows/win2bak
sudo wget http://www.iki.fi/kuparine/comp/windows/bak2win
sudo chmod 755 win2bak bak2win

# See the usage information by executing
win2bak -h
bak2win -h

This document was tested with 32-bit Microsoft Windows 7 Enterprise but it should work with other Microsoft Windows versions as well.

2. Installing Microsoft Windows

You need to perform a clean installation of Microsoft Windows only once. This will take several hours to complete so be prepared. First install Microsoft Windows, next install all the updates and all the missing device drivers. Finally install other applications needed on this PC. Remember security while doing the initial installation, it must be done in a safe network behind a firewall or at least behind a simple NAT box.

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 Disk Defrag. Now everything should be ready for the backup.

3. Taking a backup

First check where Microsoft Windows is installed on your PC. In my case it's in /dev/sda1 (first partition of the first disk).

# Check the partition tables
sudo fdisk -l /dev/sd?

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        9726    78123008    7  HPFS/NTFS
/dev/sda2            9727       10212     3903795   82  Linux swap / Solaris
/dev/sda3           10213      121601   894732142+  fd  Linux raid autodetect

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        9726    78124063+  83  Linux
/dev/sdb2            9727       10212     3903795   82  Linux swap / Solaris
/dev/sdb3           10213      121601   894732142+  fd  Linux raid autodetect

So I have Microsoft Windows in /dev/sda1. As I keep all my backups in /home/backup, I execute

win2bak -c -p /dev/sda1 /home/backup/windows.bz2

I also backup the MBR in case it gets corrupted or if I need to replace a broken hard disk.

# Backup the master boot records (MBR)
cd /dev
for i in sd?
do
  sudo dd if=${i} of=/home/backup/MBR_${i} bs=512 count=1
done

4. Restoring from a backup

First check where your Microsoft Windows is installed. Please remember that restoring to wrong partition will destroy data! Also note that this assumes you are restoring to the same partition (size, location etc.) as the original Microsoft Windows installation.

bak2win -c /home/backup/windows.bz2 /dev/sda1 

5. Refreshing backup images

Sometimes I refresh my backup image to contain more up-to-date versions of all applications. The procedure is

  1. Copy all important data from Microsoft Windows to USB stick/disk
  2. Restore the latest backup
  3. Copy the important data back to Microsoft Windows
  4. Install all updates from Microsoft Update
  5. Update all 3rd party applications
  6. Clean and defrag the C: drive (see chapter 2 for details)
  7. Create a new backup image
  8. Optionally remove the previous backup image

6. Useful links