Updated June 7, 2012

I have already blogged several times about how to create a Boot from VHD installation for the Developer and Beta versions of Windows 8 and Windows Server 8 Beta.

Now that the Release Preview version of Windows 8 and the Release Candidate version of Windows Server 2012 have been released, it is a good occasion to revisit this very flexible boot method.

My first assumption this time is that you already have a system running PowerShell 3.0 which is the case if your machine runs an earlier version of Windows (Server) 8. This blog you will learn how to configure Native VHD without touching diskpart for preparing the VHD file.  In fact we are going to create a VHDX file which is recognized by Windows 8 and Windows Server 2012 machines.

A second assumption is that you have the Hyper-V role installed. This is required because we need the Hyper-V PowerShell module which comes with the Hyper-V role.

To fully understand what is going on, I suggest you first run the classical route and then be surprised by the simplest of deployment methods which has much less requirements [See update and comments Mike Kolitz below) compared to the Classical Route. More on this later on in the blog!

The Classical Route

Let’s start creating a 60GB dynamic VHDX file named ws2012rc.vhdx in a directory we shall name D:\VHDX. A downloaded ISO image file of Windows Server 2012 should be copied to D:\Download.

BOOTVHD-0002

New-VHD -Path d:\vhdx\ws2012rc.vhdx -Dynamic -SizeBytes 60GB

Once the VHDX file is created, it can be mounted as follows:
Mount-VHD -Path D:\vhdx\ws2012rc.vhdx –verbose

As you can see in the next screen, the newly mounted VHDX has a RAW partition style, so we need to find a way to only initialize the mounted virtual hard disk.

BOOTVHD-0004

This is really easy in PowerShell. Instead of just requesting the list of online disks, we can do a conditional Get-Disk for all disks that still have a RAW partition style.

Get-Disk | where PartitionStyle -eq "RAW" | Initialize-Disk

This command initializes the RAW disk and produces a disk with a GUID Partition Table (GPT) layout.

BOOTVHD-0005

You can then partition the new disk up to its full length and assign it drive letter W:

BOOTVHD-0008

New-Partition -UseMaximumSize -Disknumber 2 -DriveLetter W –Verbose

Just after typing –Filesystem PowerShell Integrated Scripting Environment (ISE) offers you all valid options. Not only NTFS but also the new ReFS shows up as an optional new file system in Windows Server 2012. Because ReFS is primarily intended for testing purposes, we stay with NTFS for this Boot from VHD procedure.

BOOTVHD-0011

You can complete the Format-Volume command as follows

BOOTVHD-0012

You can optionally add the –NewFileSystemLabel parameter and provide a label name.

Format-Volume W -FileSystem NTFS -Confirm:$false -NewFileSystemLabel WS2012RC

In this stage it is important to mount the downloaded Windows Server 2012 ISO file. In PowerShell 3.0 you can issue the Mount-DiskImage command and again ISE helps you to find the correct file.

BOOTVHD-0013

Mount-DiskImage D:\Download\8400.0.WINMAIN_WIN8RC.120518-1423_X64FRE_SERVER_EN-US-
HRC_SSS_X64FRE_EN-US_DV5.ISO -StorageType ISO

The ISO is then automatically mounted to the next available drive letter (Drive E: in this case).

BOOTVHD-0014

Get-Volume

BOOTVHD-0000

In the next step you will use the Install-WindowsImage.ps1 cmdlet. Because this cmdlet is not digitally signed, you need to set the Execution Policy to Unrestricted. If you add the –Force parameter you can stay honest as nobody will ask you any questions. You can check the current setting by issuing the Get-ExecutionPolicy command.

Set-ExecutionPolicy -ExecutionPolicy Unrestricted –Force

First we will query the install.wim file for available Windows Server 2012 images. In our example we will use Windows Server 2012 Release Candidate Datacenter (Server with a GUI).

BOOTVHD-0020

To apply this 4th image to the mounted VHDX in drive W: issue use this command:

D:\Download\Install-WindowsImage.ps1 -WIM E:\Sources\install.wim -Apply -Index 4 -Destination W:

After 15 minutes or so the Windows Server 2012 image is copied to drive W:

BOOTVHD-0023

In the next figure you can see the contents of drive W: after the previous command.

BOOTVHD-0018

The only command left is to add an entry to the Windows Server 2012 boot file.

BOOTVHD-0024

bcdboot W:\Windows

You can check the boot configuration with bcdedit /v

BOOTVHD-0025

If it is safe to reboot, run this command:

Shutdown /r /t 0

After your computer restarts, the new image is the first OS in the boot order.

________________________________________________________________________________________________________________________________

THE WONDERFUL ALTERNATIVE

While looking for the correct download location for Install-WindowsImage.ps1 I noticed that the cmdlet had been replaced on June 1st by a much and much more efficient cmdlet called Convert-WindowsImage.ps1 which is written by Mike Kolitz. I was only #86 to download the file.

BOOTVHD-0021

Let’s see how we can improve the boot from VHD script using the new cmdlet. Download Convert-WindowsImage.ps1 and save it in D:\Download. If you have tried out the previous cmdlets and both ISO and VHDX are still mounted, be sure to dismount them first:

Dismount-DiskImage D:\Download\8400.0.WINMAIN_WIN8RC.120518-1423_X64FRE_SERVER_EN-US-HRC_SSS_X64FRE_EN-US_DV5.ISO

Dismount-VHD D:\vhdx\ws2012rc.vhdx

Convert-WindowsImage is described as follows:

Description

Convert-WindowsImage is the new version of WIM2VHD designed specifically for Windows 8. Completely rewritten in PowerShell, the Convert-WindowsImage command-line tool allows you to create sysprepped VHD and VHDX images from any official build of Windows 7, Windows Server 2008 R2, Windows 8, and Windows Server 8.

Images created by Convert-WindowsImage will boot directly to the Out Of Box Experience, ready for your first-use customizations. You can also use these images for automation by supplying your own unattend.xml file, making the possibilities limitless. Fresh squeezed, organically grown, free-range VHDs – just like Mom used to make – that work with Virtual PC (Windows 7 only), Virtual Server (Windows 7 only), Microsoft Hyper-V, or Windows’ Native VHD-Boot functionality!

Let’s first check out the graphical form of Convert-WindowsImage.ps1:

D:\Download\Convert-WindowsImage –ShowUI

BOOTVHD-0027

Just hit Make my VHD and run!

Meanwhile this appears in the PowerShell ISE Window:

BOOTVHD-0028

If you have tried the ‘old-style’ cmdlets you will recognize a number of steps which are fully automated.

BOOTVHD-0037

You can check the destination directory and see the VHDX being created.

BOOTVHD-0034

And when Convert-WindowsImage.ps1 has finished

BOOTVHD-0036

Using a PowerShell cmdlet to build a Windows 8 VHDX

We can use POSH as well of course.

UPDATE:

As Mike Kolitz pointed out in the comments below:

  • Convert-WindowsImage.ps1 is not dependent on Hyper-V
  • You don’t have to mount the Windows ISO to get access to the install.wim because you can add the ISO location to the –SourcePath parameter. In example below there is a copy of install.wim online on drive E:\

Essentially the cmdlet is reduced to this single line:

D:\Download\Convert-WindowsImage.ps1 -SourcePath E:\sources\install.wim -VHDFormat VHDX -VHDType Dynamic -VHDPath D:\vhdx\win8profRP2.vhdx -SizeBytes 50GB -Edition Professional –Verbose

The result:

BOOTVHD-0038

To make the VHDX bootable, use the commands you learnt in the Classical Route (above).

I want to conclude with applauding Mike Kolitz with this superduper Windows 8 deployment cmdlet!

Avatar of Mike Kolitz
Thanks Mike!!!