The first step to installing Windows 8 to a VHD file is to create the VHD file. This can be accomplished with the diskpart utility but I think it is much easier to use the graphical disk management utility. Open the Start Menu and type in diskmgmt.msc and hit enter.
Then click on Action and select Create VHD.
Enter a location and name for your vhd. I typically use c:vhdwin8.vhd.
Microsoft recommends a minimum of 20 GB for Windows 8 64-bit. I suggest setting the VHD disk size to at least 40 GB so you have room for apps.
For best performance select a fixed size disk but I typically use dynamically expanding disks to save on disk space. The difference is a fixed size disk of 40 GB will create a 40 GB VHD file on your file system right away. Where a dynamically expanding disk grows only as space is used. For example, a 40 GB dynamic VHD after installing Windows 8 could take up only 14 GB of actual disk space.
When you have your settings selected, click OK.
Next, reboot your computer and boot up with a Windows 8 DVD or USB Flash drive. Proceed through the custom install until you get to the Where do you want to install Windows? screen. At that point hit Shift and F10 to bring up a command prompt.
The VHD file that you created earlier needs to be attached so you can select the VHD as the install destination. Once the command prompt is open, run the following:
select vdisk file=d:vhdwin8.vhd
Replace d:vhdwin8.vhd with the full path to the VHD file you created. The drive letter may be different for you. In fact, on my Windows 7 installs there is a hidden boot partition which makes the C drive in Windows 7 actually get assigned the D drive letter when booting up with the Windows 8 installer or any Windows PE disc. That is why in the example above I created the VHD in c:vhd on Windows 7 but in the Windows 8 installer I had to use d:vhd.
At this point return to the Where do you want to install Windows? screen and click the refresh icon or hit F5. You should see a new partition, which is actually the attached VHD, displayed. Select it and continue installing Windows 8 as usual.