Playing with VHDs under Windows 7 (2)

July 11th, 2009

We’ve already talked about how do make a VHD, install Windows 7 on it, and boot from the VHD. The next step is to do snapshotting. Again, you’ll need to boot from Windows 7 DVD, and press Shift-F10 for Command Prompt. We are going to create a differential VHD. Unfortunately drive letters change when we reboot into Windows 7 setup, so you’ll need to find out where the original VHD is located. In our example, it’s D drive. Here are the commands to create a differential VHD:

create vdisk file=d:\win7-diff.vhd parent=d:\win7.vhd

Now we’ll need to use bcdedit to point the booting device to the newly created win7-diff.vhd:

bcdedit /set {default} device vhd=[locate]\win7-diff.vhd
bcdedit /set {default} osdevice vhd=[locate]\win7-diff.vhd

After these commands, all new changes will be written into win7-diff.vhd and leave the original win7.vhd untouched. This is very useful when your system is damaged by malware and you need to revert it back to a working condition in, hmm, 5 minutes 🙂 When bad things happen, all you need to do is to boot via Windows 7 DVD, delete the win7-diff.vhd, and repeat the commands above. You do need to redo the bcdedit part because the GUID inside the VHD changes and the boot loader will fail to recognize your new diff VHD, if bcdedit were not run again.

Chances are we might need to merge changes for a new snapshot (e.g. installing of important system updates, like Windows 7 SP1). In that case, you can use the commands:

select vdisk file=d:\win7-diff.vhd
merge vdisk depth=1

All contents within win7-diff.vhd will be merged into win7.vhd. You can now safely delete win7-diff.vhd, and repeat the steps w.r.t. diff VHD creation and bcdedit to start from a fresh snapshot.

Technical, Windows | Comments Jump to the top of this page

Comments are closed.

Chef Peon's Melange



Social Links