Yesterday I have used PowerShell to build a VHD of Windows 8.1 from ISO file. My home laptop is having Windows 8.1 home edition and features set is limited. To explore the features in Windows 8.1 enterprise edition, I decided to make my laptop multi boot.
When I decided to make multi boot, I have two options. Install Windows 8.1 from ISO on my laptop or prepare a VHD windows 8.1 pre-installed and make my laptop via the VHD file (this is called native boot from VHD). Since the latter option is easy and not much changes are required for my laptop, I searched for evaluation Windows 8.1 VHD from Microsoft. But unfortunately, there is only ISO download for evaluation and no VHD available.
So I thought I need to create a VM in Hyper-V, install windows 8.1 via ISO and then use that VHD to boot my laptop. But wait, that a long process. After searching for a while I landed on a PowerShell script in TechNet Script gallery that can take ISO file as input and prepare VHD with OS installed. I felt it amazing and started downloading the script. I tried the script and in hardly 30 minutes I had my VHD ready. I added this VHD to my boot options and I have Windows 8.1 enterprise evaluation edition running on my laptop via VHD boot.
Since this is very useful, I thought I will share this with every. Using this procedure, you can built servers in lab/production environment very fast using ISO file and not relying on newsid.exe/sysprep like utilities.
Download the Windows 8.1 evaluation ISO from Microsoft site
Download Convert-WindowsImage.ps1 from TechNet Library
After downloading, run the script as shown below from a Windows 8 or Windows server 2012 machine. The script is expected to work from either of these operating systems only as per the support matrix in TechNet gallery.
C:\local\Convert-WindowsImage.ps1 -SourcePath "D:\local\Windows8.1.ISO" ` -VHDFormat VHDX ` -Edition ServerDataCenterCore ` -VHDPartitionStyle GPT ` -Verbose
This will start the VHDX creation process and approximately 20-30 minutes, you will have the VHDX file ready.
Once the VHDX file is ready, you need to add the file to boot menu on your existing OS installation, so that you can choose to boot from it when are the boot OS selection menu.
To achieve this, you follow the below instructions.
- Backup your existing boot menu(BCD store) using /export switch of bcdedit.exe utility. Example,
bcdedit /export c:\bcdbackup
- Execute the below command and note the GUID along with braces retuned from the command.
bcdedit /copy {default} /d “VHD BOOT”
- In my case it returned {d15fb411-28c6-11e3-be8c-1c3e847f665e} so the next commands will look like below. Make sure to replace my GUID with yours.
bcdedit /set {d15fb411-28c6-11e3-be8c-1c3e847f665e} device vhd=[D:]\local\windows.vhdx
bcdedit /set {d15fb411-28c6-11e3-be8c-1c3e847f665e} osdevice vhd=[D:]\local\windows.vhdx
- This completes the process for adding entries for boot menu.
- Now restart your laptop and you should see the VHD BOOT in your boot menu and choose it to boot through the VHD you just created.
If you receive errors messages from Mount-DiskImage (like “Mount-DiskImage : The version does not support this version of the file format”) while using the Convert-WindowsImage.PS1, then you can extract the ISO contents to a folder (I used 7-zip) and pass the WIM file to –SourcePath parameter of the script as shown below. Basically, the problem here is, Mount-DiskImage is failing to mount the ISO files to read the installation media.
Finally, a BIG thanks to this script author and you can read more about this script at http://gallery.technet.microsoft.com/scriptcenter/Convert-WindowsImageps1-0fe23a8f
Happy learning