There is strong tendency to move towards virtualized environments that offer greater flexibility and economy of scale. Windows 7 VHDs are especially attractive due to their Native Boot support, almost eliminating performance and/or PC resources hit and "virtual hardware" use instead of real, associated with using VMs. For some ideas on using Base and Differencing VHDs see for example How to use Differencing Disks for your Advantage.

One can create a Fixed and Dynamic (expandable) Base VHD file, attach, initialize, partition and format it in Win 7 Disk Management Console, and create an expandable Differencing VHD (which contains only changes from the Base) with Diskpart. Then backup a system partition or hard drive with Windows Backup or another drive backup package to that VHD, or use Sysinternals Disk2VHD - to make full or incremental Backup depending on VHD type the easy way. There is a more involving manual way as well that also works in legacy Windows versions and equips you with relevant knowledge:

1. Generalize and Backup your Windows 7 or Server 2008 R2 hard drive to WIM image:Boot to your Win 7 HD, download and install Windows 7 WAIK, or extract ImageX and other tools & images from WAIK remotely by using HTTPdisk. Prepare Win 7 PE with WAIK or WinBuilder, copy ImageX and other tools of your choice onto it. Open as Administrator and run in WAIK Deployment Tools Command Prompt:

sysprep /oobe /generalize /shutdown

If your OS was upgraded from a previous Windows release, you may need to delete Registry key "hkey_local_machinesystemsetup dword: upgrade" to allow sysprep to run. Reboot from Win 7 PE CD or ISO, run from its Command Prompt:

Use other Sysprep and ImageX command options if required. You can then create a Base VHD in Win 7 PE or after rebooting to Win 7 HD and opening Command Prompt as Administrator, and apply (restore) your Backup WIM to it, then make the VHD bootable on its own or add its entry to your host's Boot Menu.2. Create a Base VHD Disk:

This sequence allows to create a fixed or dynamic Base (i.e. parent) VHD file, then attach it as disk, initialize, partition, format, label and mount its volume(s) for easy access. Read more about Initializingdisks with Diskpart. VHD can only be initialized as basic disk with basic volumes regardless of its file type, with min fixed empty VHD disk size 3 MB, dynamic and diff. 5 MB, max 2 TB for any disk type (127 Gb for use in Windows VPC). You might need to wait "a few minutes" when creating a large fixed VHD, while its sectors on underlying physical disk are zeroed. If deleted from the disk files data security is not an issue, one can instantly create any size fixed VHD with VHDTool. Dynamic VHDs are created small, and their sectors are zeroed as the disk grows overtime, thus slowing write access. Differencing VHDs are also dynamic with no max set size.3. Apply Windows 7 Backup WIM to the Base VHD:

imagex /apply C:WIMW2KR2X64.WIM 1 V:

You can also use WIM2VHD tool instead of ImageX to sysprep and convert your system WIM image to VHD instead of sysprepping your main OS volume. Another option is to create and/or attach the VHD from within a Win 7 Setup ISO or DVD Command Prompt, and then install OS to it like to any other hard drive - it will reboot to the VHD to finish install. Or use GImageX (ImageX GUI) to apply Install.wim from the Setup disk to your VHD. One more way: connect a VHD as IDE drive to a virtual machine, and install Win7 to it inside the VM - then use OS migration techniques to enable the VHD to run on a real PC. You can install different OSs on several volumes of the same VHD, but only one partition can be marked active and booted from at a time.4. Add Boot Environment & Configuration files to the Base VHD:To boot the VHD in a virtual machine or via a bootmanager like Grub4DOS, you need to add MBR, required boot environment files and the boot menu entry to it (using /store option - see example), unless these files, including Boot folder, were added to the VHD root during Windows install or transfer to it. If you only want to boot the VHD natively from a host Win7 system via its Boot Menu, just add its boot entry to the BCD Store on the host drive. You can copy bootsect.exe suitable for OS type on the VHD or host respectively (32 or 64-bit) from Win 7 PE, Installation ISO or Win 7 WAIK.

You can also run bcdboot v:windows /s c: to add the VHD entry to your host's Boot Menu instead of the above bcdedit commands, if the host and VHD OS versions are the same. Or use the bcdedit commands to add boot entries for each bootable volume on a multi-volume VHD, then make a desired partition active from WinPE or your system HD before booting to it.6. Add a legacy OS entry to Win7 Boot Menu (needed to run WinXP):

8. Re-specialize the Base VHD:To boot a Win7 VHD natively or via Grub4DOS from a USB drive, you might need to enable Windows 7 native USB/VHD boot registry settings in offline OS on the VHD. Run in Command Prompt from a dir with the unpacked cdob's patch:

Reboot to the Base VHD on a selected Win 7 PC to auto install all required device drivers. Clean up and defragment the Base VHD system volume with your favorite tools if required, redirect its Paging file to a physical HD in Windows System Properties - Advanced - Settings to keep size low. Consider installing EasyBCD to it for editing Boot Menu via GUI. If planning to add its Diff VHDs, reboot again to Win 7 HD, attach the Base VHD, deselect Contents Indexing in its Disk Properties and Set the parent disk ReadOnly (valid until detached), since its content can't be changed, defragmented or booted from once Diff VHDs are created to avoid mismatch. You can also set the parent VHD file Read Only in its File Properties, thus making it non-attachable and non-bootable. If you want to boot from the parent VHD later or Merge it with its Diff VHDs, Clear attribute ReadOnly from its file.

9. Create a Differencing VHD (if needed):You can create multiple Diff VHDs to the same Base, and they can be chained. Detach a parent (Base or another Diff) VHD before creating or attaching its Diff (child) VHDs. Don't format or defrag volume(s) on an attached Diff VHD - it may take a long time and increase their size with little performance boost. Diff VHDs by default display Label and Drive Letter of their parent if assigned that you can change, and have auto adjusted size. Diff will transparently use its parent's BCD Store and original volume content, but it saves all changes to disk sectors' content to the Diff's volume. You may want to defrag the Diff and Base VHD files to keep them contiguous, but for native boot VHDs its not mandatory.

10. Add Differencing VHD and delete Base VHD boot entry from BCD store:Change dir to the Diff VHD's system root, list all boot entries, copy the Base VHD entry and link its new GUID (device ID) to the Diff VHD, then add it to the host's BCD Store to boot natively from Windows Boot Menu. Or add the entry to the VHD's own BCD Store to boot via Grub4DOS or another bootmanager like VBoot.

Consider creating chained or direct Diff VHDs to the same Base to establish baselines in software testing, deployment, or run specific apps or drivers, and add their entries to your host's Boot Menu. When booting from a Diff VHD, its (chained) parent(s) must be detached and located in original folders on accessible at boot time drives. If moved, its possible to Repair relationship paths.11. Merge Differencing and Base VHDs (if needed):When enough updates are accumulated on your Diff VHD, it can be merged with its parent (uncheck Read Only in File Properties) after you uninstall unwanted apps from it and select merge depth - a number of chained Diffs to merge to the Base. Once merged, the Diff VHD can be deleted and replaced with a new empty one, or you can keep using it. You must "wait a few minutes" until Diskpart completes the task and shows the input prompt again - do not close Console before that! If several Diff VHDs exist from the same Base, merge all one by one to the Base and delete, since updating the Base will invalidate its multiple Diffs. Once finished, don't forget to set Base VHD file Read Only. The resulting Base file size increase can be a lot smaller than total size of merged to it Diffs. If you don't want to merge all Diffs to the Base, copy the Base VHD before merging it, then merge it with selected Diffs, rename the updated Base, and restore name of the original Base VHD copy thus leaving unmerged Diffs linked to it.

Fixed VHD types are preferred for work, while dynamic and differencing - for testing to save time and disk space. If something goes wrong - just delete the Diff VHD and create a new one. At boot a dynamic VHD will try to reserve disk space up to its max set size (and a Diff VHD - to its parent size), so enough (preferably contiguous) disk space should be available on the underlying physical disk volume to avoid BSOD, unless you activate Thin Provisioning. Since a Diff VHD's parent disk must be set ReadOnly, using a Dynamic VHD as a parent instead of a larger Fixed VHD can save disk space. Don't attach a bootable non-generalized VHD on the same system, unless you switched Offline the source OS drive or modified the VHD disk signature and its OS BCD & Mounted Devices registry hives (manually or with a tool like Paragon Adjust OS or IMG_XP), as it may cause VHD signature change, blocking its future boot. Note, hibernation isn't possible when booting from a VHD. If your PC is BitLockered, place the VHDs on a non-BitLockered partition and suspend BitLocker during OS install onto VHD, remember the recovery key.

You just learned how to backup your sysprepped system drive to a Base VHD, then create its Differencing VHD and add its entry to the host's or VHD own Boot Menu, so you can natively boot it on your PC. Finally install to it and start testing new apps without risking to blow your system away. The system on a VHD is running almost as fast (on average 3% performance hit) as on a physical HD - a lot faster than inside any VM. And its running on your native PC hardware, not on fictional VM hardware! Note, all code in this and my other VHD Tutorials is given as "example" ONLY, a user might need to modify based on his system config and feedback.

You may want to try VHD Loader. The author reported on his program forum to boot even DOS based VHDs !?.... And he wants to keep development going, so needs encouragement and bug reports & feature requests. You can place them right here, in VHD Loader thread.

As to booting Win XP based VHDs, Sara-Pmedia posted somewhat complex, but said to work well method of making a Universal XP VHD, which boots via Grub4DOS on multiple HW configs. Wimb also offered a comprehensive IMG_XP tool for similar purpose that also works with Win7. As to "Junior Win 7" based VHDs, there may be a way to correct VHD placed OS Registry a bit to show the right system version.

Another alternative for booting various type virtual disks is VBoot, but its not free. Grub4DOS can also map and boot as rowa images fixed Base VHDs with some OS versions installed. Another way to create a bootable via Grub4DOS WinXP VHD is to create and attach a VHD in Win 7, then start a VMWare VM and install WinXP to that VHD inside it, and then add the VHD entry to Grub4DOS menu on a host drive - one may need to integrate extra drivers like FiraDisk or WinVBlock to make it bootable.

If you want to boot a Win 7 VHD from an existing Win XP partition, just add Win 7 Bootloader and boot environment & VHD boot entry to that partition, plus the legacy WinXP boot entry as described in the Tutorials above. Its impossible to directly boot WinXP with Win 7 BOOTMGR, hence no native boot for WinXP VHDs, since NTLDR doesn't support boot from VHD.

One can't 'correct' the registry setting, which specifies the version or the serial number will no longer be valid.
Also, it takes a few files exchanged or hexedited to convert one version of Windows into another.

The above 1st link might be helpful, when directly installing Win 7 from Install DVD to a blank VHD disk, instead of applying to the VHD a sysprepped backup image of a Win 7 system hard drive. Since boot environment files are added by Win installer to the VHD automatically, that method may be useful for a novice, who has several versions of Windows (i.e. Light and Full), and wants to use a familiar process to install them on VHDs, then copy to HDD or USB Thumb to boot via Grub4DOS (static Base VHD only) or VBoot (Base and Dif VHDs) by adding a Grub4DOS Menu.lst section like:

This method allows to boot with Grub4DOS both Win7 and WinXP based VHDs by installing a virtual disk driver like FiraDisk or WinVBlock into OS on the VHD. The Menu section below can also be used to boot OS from VHD via Grub4DOS & Winvblock:

I don't suggest to integrate ALL listed tools , but only selected features and free open source small tools under a well organized GUI sufficient to automate the process of creating, resizing, converting and making VHDs universally bootable.

As I understand, virtualization and further Hyper-V integration based on VHDs usage is strategic MS direction for Win 8 and future OSs, so this topic might need a bit more attention from Reboot developers.

If your Win 7 version on VHD is not "high end" Enterprise, Ultimate or Win Server 2008R2 , and can't boot natively from Boot Menu, you can boot it with Grub4DOS bootloader and Win7VBlock virtual disk driver. In addition to steps described described in the above Tutorial, add the following:

Notes:- WinVBlock 32-bit driver doesn't require digital signing, but 64-bit version is signed with a test certificate, so you need to switch ON the Test Mode in Win7 64-bit placed on the attached VHD by running from Command Prompt:to activate: bcdedit /set testsigning on , to deactivate: bcdedit /set testsigning off- The VHD file must be of fixed type and contiguous to boot OS with Grub4DOS. Check it with Contig utility and defrag if needed, also attach and defrag the system volume inside the VHD

Surprisingly, Win7 Embedded Standard is supported for native boot from VHD - the spec confirms that. Created a VHD in Win7 Disk Management, started Win7 Emb (WES7) install in a virtual machine, interrupted as soon as the VHD get formatted, rebooted the PC and continued setup from the Emb7 ISO. It went like a champ, a new entry was added to my HD Windows Boot Menu (the HD from which Grub4DOS started and mapped the Setup ISO). Click on that entry - and here we go... Win7 Embedded Standard screen appeared, and it booted natively without 3-rd party virtual drivers installed to it.

WES7 version Win7 ThinPC is also supported for native boot from VHD after some fixes, though not in spec. Both are light, fast and very popular among old PC owners... And now boot natively from VHD, so you can try WES7 without affecting current OS! Just remember, WES7 can't change activation status from eval to full once installed, but Thin Client can. Also, when you enter Thin Client's key at initial OS setup, you get Thin Client instead of WES after installing from the same Setup ISO. Trial keys 180-days are available free from MS, and 30-day trial key is included.

Hi, having some problems (newbie at vhds, running a single native vhd on barebone metal) performance issues and messages make me think I need to defrag the partition that the vhd resides on.. but I'm inside the vhd on that drive. Tried to find a tool to run from outside the OS, but none work from command prompt when booting from windows 7 install cd (shift+f10).

My partitions are a mess and not backed up. this is my 2nd native-VHD attempt, having suffered a BSOD on my new SSD (MBR missing or corrupt? corrupt sector 0 maybe).

Windows says nothing, unable to defrag-analyse the drive via tools from the OS (the VHD).

You're new to reboot.pro, so why not create a post introducing yourself?

The "differencing" VHDs work something like this, given GrandParent.vhd -> Parent.vhd -> Child.vhd:

Read request for sector 42

Is sector 42 in Child.vhd?

Yes: Read it from Child.vhd

No: Is sector 42 in Parent.vhd?

Yes: Read it from Parent.vhd

No: Sector 42 must be in GrandParent.vhd. Read it from GrandParent.vhd

Write request for sector 13

Sector 13 might have been in either GrandParent.vhd or Parent.vhd, but now it will be in Child.vhd. Note that fact in Child.vhd

Write the sector to Child.vhd

As you can see, GrandParent.vhd and Parent.vhd are read-only, while all write operations are performed with Child.vhd.

If you defragment a filesystem inside this virtual disk, all of your efforts will happen inside Child.vhd. However, you seem to be talking about defragmenting the filesystem containing your .VHD files. Simply do not attach any VHDs and you will be able to defragment that filesystem. Is there not a defrag.exe command available from the installation environment? Maybe not, but you could copy that somewhere along with its dependencies and use it, perhaps.

Thanks for the info, I'm not doing anything with children or grandparents yet, my setup's a mess

The native VHD (win7ult x64) on bare-metal (SSD!!) was working perfectly.. then just after a month after purchase, down went the drive. THANKFULLY, after much persistence, I was able to force mount the VHD on the disk (bad bootsector 0, a friend guesstimated) and xcopy lots of data, recovering documents and images and downloads, re-installing Windows for... the zillionth time.

It's been two months, and the SSD replacement is due in any day!!

The 700Gb original HD is heavily fragmented, and I think I need to shrink the VHD to provide free space on the disk.

The VHD has 30% free space within. Will this 'help' in the shrink, and is it *safe*?

(I will have to: boot from win CD, or go to sys recovery console)

then: diskpart

sel vdisk file

shrink....

anything to do with mounting or activating?

do I have to worry about anything important being shrunk?! How does it work?!

Running out of space, no room to backup my 'backups' (if anyone has an idiot-proof backup plan, boy am I in need).

So back to looking for defrag outside OS options, and the closest I've found is defraggler, which I'm hoping will run from a UB'CD' (boot-USB) - I see peeps booting from images (ISO) in bcd, converting VHDs to ... RAW? And I wonder ... how, and whaaa?

How portable is the VHD? If the only hardware change is the drive (and partition) it's stored on (>>> SSD, from std-IDE), can it be 'migrated'? I've heard not, and sadly... this is all a bit over my head still.