Jump to content











Photo
- - - - -

Native Boot VHD


  • Please log in to reply
12 replies to this topic

#1 diddy

diddy

    Member

  • Tutorial Writer
  • 78 posts

Posted 17 March 2009 - 08:31 AM

The following is a collection of notes I made whilst doing some experiments with installing and running Windows 7 in a "native-boot" Virtual Hard Disk environment - native-boot is the term MS uses in the WAIK documentation. This is not a walkthrough and should not be treated as one as following it could result in losing existing data and boot entries if windows is already installed on your system. If you want to follow it then ensure you understand the risks and back up any important data (and consider imaging your hard disk) before proceeding. Also ensure that you know how to restore any back ups made.

A few notes about my system setup before proceeding. My hard disk was split into two primary partitions using XP's disk management console (executed from a Windows XP based PE). The first partition (referred to as (hd0,0) throughout this post) was set as ACTIVE. The second partition (referred to as (hd0,1)) was used for the vhd files. I decided to create (hd0,0) as a 10GB partition as this would also contain Windows 7 setup/install files and OS image backups.

Installing to a .vhd

1] Created a bootable Windows PE disc – this must be built using the Windows 7 beta version of the Windows Automated Installation Kit (download here).


2] Copied Windows 7 files from DVD source to "(hd0,0)\Win7" directory (beta build 7000 used)


3] Booted into WinPE and identified (hd0,0) as c: drive and (hd0,1) as d: drive


4] Started diskpart and entered the following commands to create a 10GB .vhd file -

Windows Boot Manager--------------------identifier              {9dea862c-5cdd-4e70-acc1-f32b344d4795}device                  partition=C:description             Windows Boot Managerlocale                  en-USinherit                 {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}default                 {f4b899d5-0f9a-11de-bffa-bb5aec14052c}resumeobject            {f4b899d4-0f9a-11de-bffa-bb5aec14052c}displayorder            {f4b899d5-0f9a-11de-bffa-bb5aec14052c}toolsdisplayorder       {b2721d73-1db4-4c62-bf78-c548a880142d}timeout                 30Windows Boot Loader-------------------identifier              {f4b899d5-0f9a-11de-bffa-bb5aec14052c}device                  file=[D:]\win7.vhdpath                    \Windows\system32\winload.exedescription             Windows 7locale                  en-USinherit                 {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}recoverysequence        {f4b899d6-0f9a-11de-bffa-bb5aec14052c}recoveryenabled         Yesosdevice                file=[D:]\win7.vhdsystemroot              \Windowsresumeobject            {f4b899d4-0f9a-11de-bffa-bb5aec14052c}nx                      OptIn


#2 diddy

diddy

    Member

  • Tutorial Writer
  • 78 posts

Posted 23 March 2009 - 07:51 PM

Differencing Disks

A very poorly documented feature of a native-boot vhd installation is the ability to create a 'differencing' disk. Creating a differencing disk and booting from it will result in any changes made to the Operating System being written to the new disk - the “parent” disk (the original .vhd file from which the differencing disk was created) will not be altered in any way. This allows software to be installed and tested without fear of damaging the “parent” image. The changes can be written back to the parent disk if required, or the differencing disk can be deleted and a new one created.

A differencing disk cannot be created if the parent disk is in use (e.g. Windows is currently booted from the image).

1] Rebooted into WinPE and ran diskpart. Entered the following commands -

@echo offfor /f "tokens=7" %%A in ('bcdedit.exe /copy {default} /d "windows 7 (differencing image)"') do set guid=%%ASET guid2=%guid:.=%SET guid=%guid2%ECHO guid=%guid2%echo.bcdedit.exe /set %guid% device vhd=[locate]\win7dif.vhdbcdedit.exe /set %guid% osdevice vhd=[locate]\win7dif.vhdbcdedit.exe /default %guid%echo.pause
if using the batch remember to replace {default} with the guid entry for your parent disk if required. Sample output from running the script –
Windows Boot Manager--------------------identifier              {9dea862c-5cdd-4e70-acc1-f32b344d4795}device                  partition=C:description             Windows Boot Managerlocale                  en-USinherit                 {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}default                 {f4b899d8-0f9a-11de-bffa-bb5aec14052c}resumeobject            {f4b899d4-0f9a-11de-bffa-bb5aec14052c}displayorder            {f4b899d5-0f9a-11de-bffa-bb5aec14052c}                        {f4b899d8-0f9a-11de-bffa-bb5aec14052c}toolsdisplayorder       {b2721d73-1db4-4c62-bf78-c548a880142d}timeout                 30Windows Boot Loader-------------------identifier              {f4b899d5-0f9a-11de-bffa-bb5aec14052c}device                  file=[D:]\win7.vhdpath                    \Windows\system32\winload.exedescription             Windows 7locale                  en-USinherit                 {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}recoverysequence        {f4b899d6-0f9a-11de-bffa-bb5aec14052c}recoveryenabled         Yesosdevice                file=[D:]\win7.vhdsystemroot              \Windowsresumeobject            {f4b899d4-0f9a-11de-bffa-bb5aec14052c}nx                      OptInWindows Boot Loader-------------------identifier              {f4b899d8-0f9a-11de-bffa-bb5aec14052c}device                  vhd=[locate]\win7_dif.vhd,locate=custom:12000002path                    \Windows\system32\winload.exedescription             windows 7 (differential image)locale                  en-USinherit                 {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}recoverysequence        {f4b899d6-0f9a-11de-bffa-bb5aec14052c}recoveryenabled         Yesosdevice                vhd=[locate]\win7_dif.vhd,locate=custom:22000002systemroot              \Windowsresumeobject            {f4b899d4-0f9a-11de-bffa-bb5aec14052c}nx                      OptIn

See http://www.buit.org/tag/windows-7/ for further information on differencing disks.

#3 diddy

diddy

    Member

  • Tutorial Writer
  • 78 posts

Posted 23 March 2009 - 07:54 PM

Resize vhd

Note - this post has been edited following allanf's suggestion (see post #5) to use diskpart's expand command to increase the disk size.

What happens if the vhd you created is no longer large enough to contain all of the additions/changes you have made. Although it is possible to complete a fresh install to a larger image this would result in the loss of any added settings/programs/files etc, and would also cause activation problems. I was able to get around this by doing the following.

Method 1 (can also be used to create a smaller vhd file)

1] Booted into WinPE (which has the imagex.exe tool added) and mounted win7.vhd using diskpart -
[codebox]@echo offfor /f "tokens=7" %%A in ('bcdedit.exe /copy {win7.vhd-guid} /d "Windows 7 (new.vhd)"') do set guid=%%ASET guid2=%guid:.=%SET guid=%guid2%ECHO guid=%guid2%echo.bcdedit.exe /set %guid% device file=[d:]\new.vhdbcdedit.exe /set %guid% osdevice file=[d:]\new.vhdbcdedit.exe /default %guid%echo.pause[/codebox]Where {win7.vhd-guid} is the guid for the original win7.vhd entry. [/indent][u]Method 2[/u] (can only be used to create a larger vhd file)[indent]1] Booted into WinPE (which has the imagex.exe tool added) and used following diskpart commands to increase the vhd size to 15GB - [code]select vdisk file=d:\win7.vhdexpand vdisk maximum=15360exit[/code][/indent][indent]2] When mounted (using diskpart [b]attach vdisk[/b] command) the Windows 7 OS partition remained 10GB in size however there was 5GB of free space within the VHD. Used the following diskpart commands to increase Windows 7 OS partition to use all available space within the VHD - [code]select vdisk file=d:\win7.vhdattach vdiskselect partition 1extendexit[/code]


When I booted from win7.vhd, Windows 7 booted without any problems and the mounted OS partition was 15GB in size.

Conclusion

I personally recommend method 1. Although the procedure is more complicated the benefit is a working backup which can be used to create new vhd's in the event of any problems. The backup I created was only 2.1GB in size and easily copies to a DVD.

#4 diddy

diddy

    Member

  • Tutorial Writer
  • 78 posts

Posted 23 March 2009 - 07:58 PM

Create a VHD entry in an empty BCD store

If you have deleted your BCD store and need to create a new store with an entry for an existing vhd file (e.g. d:\win7.vhd) the procedure is as follows -

Method 1

This is a slightly adapted version of the instructions included in the WAIK.

1] Boot into WinPE



2] Mount your .vhd file via Diskpart using the following commands (where "d:\win7.vhd" is your .vhd file)
[codebox]Windows Boot Manager--------------------identifier {9dea862c-5cdd-4e70-acc1-f32b344d4795}device partition=C:description Windows Boot Managerlocale en-usinherit {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}default {b24aef85-1530-11de-98be-fa21bc1d2c2c}resumeobject {b24aef84-1530-11de-98be-fa21bc1d2c2c}displayorder {b24aef85-1530-11de-98be-fa21bc1d2c2c}toolsdisplayorder {b2721d73-1db4-4c62-bf78-c548a880142d}timeout 30Windows Boot Loader-------------------identifier {b24aef85-1530-11de-98be-fa21bc1d2c2c}device file=[D:]\win7.vhdpath \windows\system32\winload.exedescription Windows 7locale en-usinherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}osdevice file=[D:]\win7.vhdsystemroot \windowsresumeobject {b24aef84-1530-11de-98be-fa21bc1d2c2c}nx OptIndetecthal Yes[/codebox][u]Method 2[/u]Alternatively you could try the following script - [codebox]@echo offfor /f "tokens=3" %%A in ('bcdedit.exe /create /d "Windows 7" /application osloader') do set guid=%%Aecho guid=%guid%echo.bcdedit.exe /set %guid% device vhd=[D:]\win7.vhdbcdedit.exe /set %guid% path \Windows\system32\winload.exebcdedit.exe /set %guid% osdevice vhd=[D:]\win7.vhdbcdedit.exe /set %guid% systemroot \Windowsbcdedit.exe /displayorder %guid% /addlastbcdedit.exe /default %guid%echo.echo.echo.pause[/codebox]BCD entry from running the above script - [codebox]Windows Boot Loader-------------------identifier {86a26084-17e1-11de-8b46-001837004759}device vhd=[D:]\win7.vhd,locate=custom:12000002path \Windows\system32\winload.exedescription Windows 7osdevice vhd=[D:]\win7.vhd,locate=custom:22000002systemroot \Windows[/codebox]Note the use of [b]vhd=[C:]\win7.vhd[/b] [u]not[/u] [b]file=[C:]\win7.vhd[/b] - I have no idea why, however using file= resulted in an error (error 0xc000000f - The boot selection failed because a required device is inaccessible) whilst using vhd= booted fine. Examining entries from other BCD stores I noticed that when the vhd entry is created as part of the Windows 7 installation (with file= entries) [b]recoverysequence[/b] and [b]resumeobject[/b] values were also created (identifier for the entry was {f4b899d5-0f9a-11de-bffa-bb5aec14052c}) - [code]recoverysequence {f4b899d6-0f9a-11de-bffa-bb5aec14052c}resumeobject {f4b899d4-0f9a-11de-bffa-bb5aec14052c}[/code]Using Method 1 (see above) and creating the vhd entry by running bcdboot.exe a [b]resumeobject[/b] value was created (identifier for the entry was {b24aef85-1530-11de-98be-fa21bc1d2c2c}) -[code]resumeobject {b24aef84-1530-11de-98be-fa21bc1d2c2c}[/code]

#5 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 23 March 2009 - 11:32 PM

Increase vhd size

As far as I am aware it is not possible to increase the size of the vhd image after it has been created. ..


Have you tried:

DISKPART EXPAND VDISK

I'm having the opposite problem. My VDISK was created too large, and

DISKPART COMPACT VDISK

is crashing.

Regards

#6 diddy

diddy

    Member

  • Tutorial Writer
  • 78 posts

Posted 24 March 2009 - 06:03 AM

@allanf
I have not actually tried -
DISKPART

EXPAND VDISK

Thanks for pointing this out - I'll give it a go later.

The steps in Post#3 should also work for decreasing a vdisk's size.

#7 allanf

allanf

    Gold Member

  • .script developer
  • 1256 posts

Posted 24 March 2009 - 06:12 AM

... I'll give it a go later.

The steps in Post#3 should also work for decreasing a vdisk's size.


Thanks. I have learned a great deal from your extremely well-written Tutorials and Postings. ... :good: ...

If you manage to EXPAND, I would be very interested if you could test the new COMPACT as well. I think there's a bug in it.

Regards ^_^

#8 diddy

diddy

    Member

  • Tutorial Writer
  • 78 posts

Posted 24 March 2009 - 05:28 PM

If you manage to EXPAND, I would be very interested if you could test the new COMPACT as well. I think there's a bug in it.


@Allanf
Thanks for the positive feedback. Post #3 has been edited following your suggestion(s).

Although I was able to run diskpart's compact command without errors (on a dynamically expanding VHD file) I had no success in reducing the VHD's maximum size, but did stumble upon the following (from here), which might explain why -

Compacting a dynamically expanding virtual hard disk reduces the size of the virtual hard disk (.vhd) file as much as possible. Typically you would compact a virtual hard disk in situations such as the following:

* After you install the guest operating system (which uses many temporary files)
* After you delete large amounts of data
* When you are preparing the virtual hard disk for archiving, for deployment to another computer or CD-ROM, or for distribution.

You can compact a dynamically expanding virtual hard disk. You cannot compact any other type of virtual hard disk. However, you can convert a fixed-size virtual hard disk to a dynamically expanding virtual hard disk and then compact the disk. If you want to compact a differencing virtual hard disk or an undo disk, you must merge the changes to the parent disk and then compact the parent disk, if it is a dynamically expanding virtual hard disk. For instructions on converting disks, see Convert a virtual hard disk. For instructions on merging disks, see Merge a virtual hard disk.

To ensure that you get the smallest possible file size when you compact the virtual hard disk, you need to do some file system maintenance before you compact the disk. In the guest operating system of the virtual machine that is using the disk you want to compact, do the following:

* Remove any temporary folders or unwanted folders or files.
* Empty the Recycle Bin.
* Defragment the disk.
* Use a non-Microsoft disk utility program to "zero out" deleted data, which overwrites the data with zeros. When you delete files from a virtual hard disk, the data associated with the files is not actually removed until it is overwritten. Instead, the sector that stored the data is marked as available for use by the operating system. Zeroing out the data overwrites it with zeros, which enables the compact option to make the .vhd file smaller. When you compact a virtual hard disk, sectors that contain only zeros are removed from the virtual hard disk to reduce the file size.

After you complete the tasks described above, open the Administration Website to compact the virtual hard disk. For instructions, see Compact a dynamically expanding virtual hard disk.


I interpret this as meaning that a vhd image created with (for example) the command create vdisk file=d:\win7.vhd maximum=10240 cannot be shrunk from 10GB, however the compact command can be used to basically clean up the crap that accumulates within the image, as any deleted files still take up disk space and the image can soon fill.

#9 was_jaclaz

was_jaclaz

    Finder

  • Advanced user
  • 7101 posts
  • Location:Gone in the mist
  •  
    Italy

Posted 24 March 2009 - 11:38 PM

Wouldn't this do? :good:

http://vmtoolkit.com...rs/entry87.aspx

jaclaz

#10 srazi

srazi
  • Members
  • 2 posts
  • Location:Iran

Posted 23 April 2010 - 09:27 PM

Thanks for your great post.

Resize vhd

Method 1 (can also be used to create a smaller vhd file)

1] Booted into WinPE (which has the imagex.exe tool added) and mounted win7.vhd using diskpart -

...


It seems, the "SOURCE" option of "CREATE VDISK" command does the same job without imaging process.(but can't create smaller vhd)
DISKPART> help create vdisk

...

	&#91;SOURCE=<&#34;filename&#34;>&#93;

				Path to an existing virtual disk file to be used to

				pre-populate the new virtual disk file. When SOURCE is

				specified, data from the input virtual disk file is copied

				block for block from the input virtual disk file to the

				created virtual disk file. There is no parent-child

				relationship established however.


#11 JonnyHotkeys

JonnyHotkeys

    Newbie

  • Members
  • 10 posts
  •  
    United Kingdom

Posted 14 February 2014 - 04:14 PM

why would you create vdisk source = another vhd ? (a copy?)

why wouldn't you just copy the vhd file?

 

is there a performance benefit either way (richcopy vhd is slick, and it works, i've tested it)



#12 JonnyHotkeys

JonnyHotkeys

    Newbie

  • Members
  • 10 posts
  •  
    United Kingdom

Posted 27 September 2015 - 11:41 PM

^^ answer inferred: 'No good reason'



#13 crashnburn

crashnburn

    Frequent Member

  • Advanced user
  • 136 posts

Posted 29 September 2015 - 11:31 AM

Maybe we should do a compare/ performance run of all these methods. 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users