Posted on February 20, 2014 · Posted in Windows 7

Installation of Windows 7 or Windows 8 on a Virtual Hard Disk

General Information About Installation of Windows on a Virtual Hard Disk

From time to time you have to install Windows 7 or Windows 8. It’s ok, but you’re not always able and willing to provide a whole partition for it and then fiddle around with different loaders.

Fortunately, Windows 7 and Windows 8 support installation on a virtual hard disk (VHD). Generally speaking, a virtual hard disk is quite a large file which can be mounted to the system as another hard disk. All the disk contains is stored in that file.

The advantages of this approach are:

  1. A system works faster on a physical equipment, than on a virtual machine. This is one of the main advantages of installing a system on a VHD compared to the installation on a virtual machine.
  2. A VHD works as a physical disk. In other words, you can easily get access to any data on your hard disk.
  3. A VHD is stored in a single file and you can clone your system by simply copying your VHD file.
  4. You can test new programs, games, etc. not worrying for your host system.
  5. You can use new versions of Windows without deinstalling the host system.So let’s start the installation of Windows 7 or Windows 8 on a virtual hard disk.

Installation of Windows on a Virtual Hard Disk

To install Windows, we need

  1. A preinstalled copy of Windows 7 or 8. It should be your host OS.
  2. A startup DVD or a USB flash drive with Windows 7 or 8 (depending on what you are going to install).

There are two ways of creating a VHD:

  1. in a running Windows;
  2. from the command line during installation of Windows.

Let’s consider the first way together with the system installation process.

How to Create a VHD File in Windows

Right-click Computer in the Start menu and choose Manage. If you did everything right, the following window appears:

disk managment console windows 7

Click Disk Management on the left, then choose Create VHD on the Action menu. This dialog box appears:

windows 7 create vhd disk

Specify the name and location of your VHD file as well as its size. You’d better choose Dynamically expanding for the VHD to take as much space as the amount of data stored on the virtual hard disk. In my example I created a virtual hard disk file with the size 25 GB and the name win7.vhd on the disk D:\.

Done, the file was created. Now insert a startup disk or a USB flash drive with Windows and reboot the system.

Start Windows installation:

start windows 7 installation

To install Windows on a virtual hard disk, you have to mount it. To do it, press Shift+F10 to run Command Prompt:

install windows 7 on vhd with diskpart

Enter the following commands:

select vdisk file="D:\win7.vhd"
attach vdisk

In quotes specify the path to your VHD file. Then close the Command Line and continue installation.

While choosing a disk for the installation, ignore this warning:

install windows 8 on vhd

Then the installation goes as usual.

Now let’s consider how to create a VHD during Windows setup.

How to Create a VHD During Windows Setup

Boot from a installation USB flash disk or a DVD with Windows and run setup. In the beginning of the installation the following window should appear:

start windows 7 installation

Now we have to somehow create a virtual hard disk to install a system on it. To do it, press Shift+F10 and enter:

create vdisk file="D:\win7.vhd" type=expandable maximum=25000

This command allows to create a VHD file wind7.vhd in the root folder of the D:\ directory with the max size of 25 000 megabytes or about 25 GB.

The VHD file has been created, but Windows Installer doesn’t know anything about it. To make the VHD appear in the list of partitions, it should be mounted. To do it, enter the following command:

select vdisk file="D:\win7.vhd"
attach vdisk

Then the installation goes as usual. When you come to choosing a partition to install a system on, select your VHD. If the virtual hard disk did not appear after you entered the commands, press the Refresh button.

refresh partitions list and choose vhd

When the installation is completed, you can choose which system to boot: the host OS or Windows on your VHD.

Let’s consider how to rename the new system in the boot list so it is easily distinguished from the host system.

How to Edit Windows Loader

To edit the loader, it is convenient to use a standard utility bcdedit.exe. Run the Command Prompt as Administrator. To do it, find the app in the Start menu, right-click it and choose the corresponding option.

If you are currently using a system installed on the VHD, enter:

bcdedit /set {current} /d "Windows 7 SP1 Test VHD"

Here “Windows 7 SP1 Test VHD” is the name of the system on your VHD that you want to see in the boot list, and {current} is the loader ID which name is being changed. You can look through the whole list of IDs by entering bcdedit without parameters.

You are likely to have your ID as default, otherwise you have to replace the default ID with your own one in the code. You can do it as follows:

bcdedit /set {default} description "Windows 7 SP1 Test VHD"
bcdedit /default {current}

Here the system {default} is given the name “Windows 7 VHD”. Specify that the current OS should be loaded by default. I had Windows 7 running from a physical media, the host one.

How to Delete Windows Installed on the VHD

You can do it in a number of ways, but we will use the easiest of them in my opinion.

To do it, we have to go to the System configuration window. On the Start menu, choose Control Panel, find Administrative Tools and then System Configuration in it (or enter msconfig). In this window click Boot. The whole path is shown in the snapshot below:

msconfig win 7

Thus, you get this window:

msconfig boot properties

Now you can see that there are such controls as Delete and Set as default. So with bcdedit you can rename your new system, and in this window you can make any system the host one.

Related Articles