Steps to Create Bootable VHD on Hyper-V
In this blog, we will show you the steps to create bootable VHD on Hyper-V which contains a windows image.
REQUIREMENTS
- Hyper-V Physical Host
- Windows 2016 ISO image
- DISM (Deployment Image Servicing and Management)
CREATING VIRTUAL HARD DISK
- Open the elevated command prompt window.
- Type the command diskpart and press Enter.
- Type the below command to create a VHD file with disk space. In this demo, we are creating a VHD file named winboot.vhd with 25 GB of disk space.
create vdisk file=e:\vhd\winboot.vhd maximum=25000 type=expandable
- Select the virtual disk.
select vdisk file=e:\vhd\winboot.vhd
- Attach the newly created disk.
attach vdisk
- Create a primary Partition in the virtual disk.
create partition primary
- Assign a Drive Letter. In this demo, we are assigning the driver letter as V.
assign letter=v
- Make the partition as ACTIVE
- Format the VHD.
format quick FS=NTFS Label=VHD
- Type exit command to quit diskpart.
APPLY WINDOWS IMAGE TO VHD THROUGH DISM
Note: We are using Windows Server 2016 image in this demo
- We have mounted the windows 2016 image in D:\ drive.
- Open the elevated command prompt window.
- Execute the below command to view the OS version and edition from install.wim file.
dism /Get-WimInfo /wimfile:d:\sources\install.wim
- We are applying Windows Server 2016 Datacenter Evaluation edition-Desktop Experience (Index 4). Run the Apply-Image command through DISM Management.
dism /apply-image /imagefile:d:\sources\install.wim /index:4 /applydir:v:\
- We have already mounted the VHD in V:\ drive. It will take several minutes to complete the action.
PREPARING VHD TO BOOT AS VIRTUAL MACHINE
- Open the elevated command prompt window.
- To create the BCD entry for native VHD boot, type the below command.
V:\windows\system32\bcdboot V:\windows /s V:
- BCDboot creates boot configuration entry so that windows bootloader can boot from the VHD.
- Run the bcdedit command to view the system boot configuration information
- Type exit command to close the command prompt window.
- Eject the VHD through windows explorer
ADDING THE VHD TO A VM IN HYPER-V
- Open the Hyper-V Snap-in. Right Click on the server name and select New – Virtual Machine.
- From the new virtual machine wizard welcome screen, Click Next.
- Provide a name for the virtual machine and click Next.
- Select the Generation type and click Next.
- Specify the memory size and Click Next.
- Specify the Network adapter from the drop-down list and click Next.
- Select the Use an existing Virtual Hard disk option and click on browse.
- Select the winboot.vhd file from E:\VHD folder and click Open.
- Once the VHD name is shown in the location path. Click Next.
- Click on Finish button to complete the wizard.
TESTING THE VM
- Now spin up the VM through Hyper-V manager. If the VM is properly configured, it will boot and prompt for Region & Language Selection. Provide the required information and click Next.
- Click on Accept button to accept the Windows license agreement.
- Provide the password for the administrator account and click finish to complete the configuration window.
- You will able to view the windows login screen.
VIDEO:
Thanks for reading this blog. We hope it was useful for you to learn the steps to create bootable VHD Image for Hyper-V VM’s.