In this video from ITFreeTraining I will be look at how to create, use and convert
virtual hard disks on Windows Server 2012 R2. By the end of this video, you will have
an understanding of how to create and use and convert virtual hard disks in Windows
Server; however, the same principles also apply to Windows clients such as Windows 8.
I will now change to my server running Windows Server 2012 R2 to perform the demonstration.
First I will look at creating a virtual disk. To do this, I will right click on the start
menu and select the option “Disk Management”. Once Disk Management has opened, I will next
select the action menu and select the option “Create VHD”.
It is now just a matter of entering in some details about the virtual drive that I want
to create. In this case, I will enter in a filename, saving the virtual hard disk to
the root of the c drive. Next I will enter in 2 for the size and select the option for
2 Terabytes.
Under this, you have the options for the virtual hard disk format. The VHD format is the old
format that allows virtual disks of up to 2 Terabytes. The second option is the VHDX
format which allows for creating larger virtual hard disks and has transaction logging to
help protect against power failures as well as some other performance features. VHDX is
only available on Windows Server 2012 R2 or Windows 8.1; however, as we will see later
in this video, it is a fairly simple process to convert a virtual drive from one format
to another.
By default, the virtual drive will be created using the fixed option. This will pre-allocate
the drive space so, in this case, would create a 2 Terabyte virtual disk file. In this case,
I will select the second option “Dynamically expanding”. This option will expand the
size of the virtual disk as data is added to it.
You will notice that when I create the virtual drive I will get an error message saying “The
parameter is incorrect”. This error message does not give you any indication of what the
problem is, but I do, however, know what caused it. I will now once again select the option
“Create VHD” under the action menu.
Once again I will enter in the file name but this time I will enter in the size of 1.9
Terabytes. The trick here is that the virtual hard disk file is limited to 2 Terrabytes.
This includes data and structures like configuration required for the virtual hard disk. For this
reason you will not be able to create virtual hard disks using the VHD format of 2 Terrabytes,
only up to 2040 Gigabytes, if you want to be precise.
I will once again select the option for “Dynamically expanding” and press o.k to create the virtual
hard disk. You will notice that the new virtual hard disk has been attached and appears as
disk 1 and will be blue in disk management.
The operating system will see the virtual hard disk as it would a normal hard disk or
solid state drive. Just like a brand new physical drive, I first need to right click it and
select the option “Initialize Disk”. When prompted, I will leave the default option
of MBR selected and press o.k. to initialize the disk.
Now that the disk has been initialized I can right click it and select the option “New
Simple Volume” to create a volume on the drive just like what I would do with a physical
disk. Once the wizard appears, I will next my way to the end accepting all the defaults
and complete the wizard. As you can see, besides the hard disk being stored in a file, the
operating system appears as a D Drive and can be used just like you would the C Drive.
Later in the video I will look at how to use the Hyper-V management tool with virtual disks,
including how to convert the virtual hard disk to different formats. Before I do this,
I will first look at how to do this using PowerShell.
To open PowerShell, I will select the icon for PowerShell in the Quick Launch. In PowerShell,
I will enter in the command “Convert-VHD”. You will notice that when I run the command,
I will get an error message saying the command could not be found. In order to run this command,
I first need to install the Hyper-V role.
To install Hyper-V, I will open Server Manager from quick launch and, once open, on the welcome
screen select the option “Add roles and features”. In this case I will be installing
the role on this server so I can accept the default option on the first few screens.
On the role selection screen, I need to select the role “Hyper-V”. Once selected, I will
be prompted to add additional features. One of these features is the “Hyper-V module
for Windows PowerShell”. You may be asking yourself, could you install these features
by themselves and just run the required commands in Windows PowerShell? The answer is no. Unfortunately
the PowerShell commands will not work unless the complete Hyper-V role is installed. Hyper-V
does require a physical computer that supports virtualization, which means you cannot run
it inside a virtual machine. This makes it difficult for some administrators who may
not have a Hyper-V server set up. It should be remembered that Windows 8 supports Hyper-V
so the administrator could install Hyper-V on their workstation or use Windows 8.1 if
they are required to use VHDX files.
Once I press the “Add Features” button, I can press next to move on to the next screen
of the wizard. On the next screen, I can select additional features to add. In this case,
I do not need to add any additional features other than the ones that were already selected,
so I will press next to move on.
The next part is the configuration of the Hyper-V role. In this case, I will accept
all the default options as, at this stage, I only want to access the virtual disk options.
If you want to learn more about Hyper-V, we have another course coming out on Hyper-V.
Now that all the configuration has been made, I can press the install button to start the
install of the Hyper-V role. The installation only took around a minute or so to complete
on this computer, but, so we do not have to wait, I will pause the video and I will be
right back.
Now that the role has been installed, I next need to restart the server so the changes
will take effect. Even though at this stage I only want to access the commands in PowerShell,
they will not be available in PowerShell until a restart has been performed. For the administrator
that only wants to do some maintenance on a virtual disk file and does not use Hyper-V,
this unfortunately does add a lot of steps to the process. Hopefully, Microsoft will
remove the requirement to have Hyper-V installed in order to use PowerShell commands, making
the process easier.
Once the server has restarted and I am logged back in, I will right click on the start menu
and select the option “Disk Management”. You will notice that the virtual disk that
I created earlier is no longer present in Disk Management. Unfortunately, virtual disks
will be un-mounted during a reboot and not remounted when the computer starts up. To
get around this you would need to create a startup script that will mount the virtual
disk during start up.
I will now close Disk Management and open PowerShell. Like before I will run the command
Convert-VHD. The first parameter that I will enter in is “-Path” followed by the filename
of the virtual hard disk that I created earlier, which was in VHD format. Following this I
will enter in the second parameter of “-DestinationPath” followed by the filename that I want to use
to write the virtual disk to. Notice that, in this case, I have used the same filename
but have changed the extension to VHDX. So essentially this command is reading the original
virtual disk in VHD format and writing it out in VHDX format.
Once I run the command, it does not take too long to complete. This is because the original
virtual disk was dynamic and does not have any data in it.
The next command I will run is New-VHD with the “-Path” parameter followed by the
filename. The filename is the name of virtual disk that I want to create. In this case,
I will create a differencing virtual disk. This is a virtual drive that is combined with
another virtual disk to form a parent child relationship. Changes for the parent are saved
in the child virtual disk.
The next parameter that I will enter in is “-ParentPath” followed by the filename.
This is the filename of the virtual hard disk that will be used as the master of the parent
virtual disk. The last parameter that I will enter in is “-Differencing”. This indicates
that the type of virtual disk that I want to create is a differencing virtual disk.
I could also use the parameters Fixed or Dynamic if I wanted to create virtual disks of these
types.
Once I run the command, it does not take too long to complete. The CmdLets in PowerShell
offer a lot of control for virtual disks and, if you plan to use them, it is worth your
time to have a look at the other parameters that are available. A lot of the functionality
is available in the Hyper-V manager, so I will next have a look at this to see what
can be achieved with virtual disks using this tool.
To open Hyper-V Manager, I will first open Server Manager from the quick launch menu.
Next I will select “Hyper-V Manager”. Once Hyper-V Manager has opened, I will next
select the option “Edit Disk” on the right which will start the wizard.
Once I am past the welcome screen of the wizard, on the next screen, I need to enter in the
location of the virtual disk that I want to make changes to. In this case, I will press
the browse button and select the child virtual disk that I created earlier using PowerShell.
This is a differencing disk that requires its parent disk in order to operate. So let’s
have a look at how I can convert this to a standard virtual disk that does not require
another virtual disk in order to operate.
Once I press next, I will be given 4 options that I can perform on the virtual disk. The
first option, “Compact”, will reduce the size of the virtual disk. It does this by
removing data from the virtual disk that is no longer required. For example data that
has been erased.
The next option “Convert” allows the administrator to convert a virtual disk from one format
to another. For example, you could convert a VHD file to a VHDX file or VHDX file to
a VHD file. The process is quite simple and, for this reason, I would personally use VHDX
where possible to take advantage of the new features of VHDX and then convert them to
VHD when required. Since the process is so simple, it does not require the administrator
to make decisions based on compatibly issues that may arise later on.
The next option “Expand” allows the administrator to increase the size of an existing virtual
disk. A useful feature if the virtual disk was originally created too small.
The last option “Merge” allows a differencing virtual disk to be merged together to create
a single new virtual disk that does not require the parent virtual disk. In this case, this
is the option that I will select and then I will move on to the next screen of the wizard.
The next screen of the wizard will ask where you want to merge the changes to. The default
option will merge the changes to the parent virtual disk. If this option is selected then
any changes on the child disk will be moved to the parent disk. This is basically copying
the changes from the child disk to the parent disk and then erasing the child disk, giving
you a fresh start. In this case I will create a new virtual disk eliminating the need for
the parent child relationship. To do this, I will select the second option “To a new
virtual disk” and then enter in the filename of the virtual disk that I want to use. Notice
that I also need to enter in the extension of VHDX.
The two options below this allow the type of virtual disk to be selected. By default,
the option “Dynamic virtual hard disk” will be selected. This will create a dynamic
virtual hard disk that will increase in size as data is added to it. The second option
“Fixed virtual hard disk” will create a fixed size virtual hard disk. This will
give better performance; however, will take longer to create and takes up drive space
immediately, whereas dynamic uses drive space only as required. In this case I will leave
it on the default option of “Dynamic virtual hard disk” and move on to the next screen
of the wizard.
The next screen provides a summary of the options. Once I press finish, a virtual hard
disk will be created that no longer requires the master virtual hard disk.
If I select the new option, there is an option for Hard disk. This will launch a wizard which
allows you to create a new virtual disk. The options are much the same as the options that
are available in disk management when creating a new virtual disk. The only real difference
is that it gives you the option to create a differencing disk, which disk management
does not allow you to do.
To show you how virtual disks are used with Hyper-V I will create a new virtual machine
using the top “Virtual Machine” option. In the Hyper-V course I go into more detail
about virtual machines. In this case I only want to look at virtual hard disk options
so I will press finish, and complete the wizard.
Once the virtual machine has been created, I can right click it and select the option
“Settings” to bring up the settings of the virtual machine. Once open, the next step
is to select the “Hard Drive” option on the left. You will notice the option “Virtual
hard disk” and the filename of the current virtual hard disk that is being used with
this virtual machine. To change it, it is just a matter of pressing the browse button.
Notice that if I browse to the c drive, there are the 4 virtual hard disks that I created
earlier. If I want to use any of these virtual hard disks, it is just a matter of selecting
one of them. In this case, I will select the virtual hard disk DataDrive and press open.
Now this virtual machine is using that virtual hard disk. It is that simple.
Well I hope you have enjoyed this video from ITFreeTraining and found it useful. For more
free videos from us from this course and others, please see our Web Site or YouTube channel.
Until next time, thanks for watching.