What is Left?
When we initially created the virtual machine, we allocated 2048 MB of memory to it. After that, we created a virtual hard disk file and told the virtual machine to use it. Finally, we provided the virtual machine with a virtual network adapter. Technically the virtual machine could stand on its own right now. Even so, I want to walk you through the process of allocating a bit more hardware. For the purposes of this article, we will add an extra virtual CPU to the virtual machine and we will add a secondary virtual hard drive.
Virtual CPUs
Even though we already know that the virtual machine that we created was automatically provisioned with a single virtual CPU core, let's pretend that we don't know how many virtual CPUs have been allocated. The easiest way to determine virtual CPU allocation is to enter the Get-VMCPUCount command.
If you look at Figure A, you can see that I have used this command in two different ways. First, I entered the command by itself, which caused Hyper-V to return virtual CPU allocation information for every virtual machine on the host. Next, I entered the command again, but this time I specified the name of one specific virtual machine. This caused Hyper-V to return virtual CPU allocation information solely for that one virtual machine.
Figure A: The Get-VMCPUCount command returns information about virtual CPU allocation.
Regardless of whether we specify one virtual machine or look at all of the virtual machines, several key pieces of information are returned. First, take a look at the Quantity column. This column reflects the number of virtual CPUs that have been allocated to each virtual machine. Another column worth paying attention to is the Cores / Socket column. This column tells you how many physical CPU cores the server has for each CPU socket. Finally, the Socket Count column tells you the number of physical CPU sockets that the server is equipped with.
So now that we have determined the current virtual CPU count, let's go ahead and set the number of virtual CPUs that are assigned to the virtual machine to two. You can allocate up to four virtual CPUs to a virtual machine, but the virtual machine's operating system must support using the number of virtual CPUs that you provide it with. Furthermore, you cannot exceed the total number of physical cores that are installed in the server.
You can modify a virtual machine's CPU allocation by simply specifying the name of the virtual machine and the number of CPU cores that you want to assign. For example, if you wanted to assign two virtual CPU cores to a virtual machine named Windows Server 8 Beta then you would use the following command:
Set-VMCPUCount "Windows Server 8 Beta" 2
If you look at Figure B, you can see that when I enter this command, the Quantity count changes from one to two.
Figure B: The virtual CPU quantity changes from one to two.
Technically this achieves the objective of increasing the number of virtual CPUs that are allocated to our new virtual machine. Even so, there are a few extra parameters that can be used along with this command that I want to mention. I won't go into all of the parameters because they are listed in the documentation and some of them don't really do anything too exciting. However, a few of the more useful parameters that you might want to use are:
Limit – The Limit parameter lets you specify the maximum amount of time that a virtual machine is allowed to use a physical CPU. The default limit is 100% usage.
Reservation – The Reservation parameter lets you reserve a percentage of CPU time solely for a specific virtual machine. By default the reservation is set at 0%.
Weight – The weight parameter lets you set a relative weight that affects how much CPU time a virtual machine will receive. The default weight is 100.
Adding an Additional Virtual Hard Disk
The last thing that I want to do to the newly created virtual machine is to provide it with an additional virtual hard disk. The procedure for doing so is very similar to the procedure that we already used to create the virtual machine's primary virtual hard disk.
The first step in the process is to actually create the virtual hard disk file. This can be done through the now familiar New-VHD command. You can see an example of the command below:
New-VHD –VHDPath "F:\Windows Server 8 Beta\SecondVHD.vhd" –Size 16106127360
Next, we have to assign the virtual machine to a variable name ($VM in this case), and then attach the virtual hard disk to a virtual disk controller on the virtual machine. The two commands that will be required to complete this operation are:
$VM=Get-VM "Windows Server 8 Beta" –Server Hyper-V
Add-VMDisk –VM $VM –ControllerID 0 –LUN 0 –VHDPath "F:\Windows Server 8 Beta\SecondVHD.vhd"
You can see these commands and their result in Figure C. If you need any help understanding what these commands are doing then be sure to either check out Part 6 of this series or the documentation for the PowerShell module for Hyper-V.
Figure C: You can create and attach a new virtual hard disk file from the command line.
Now that we are done, take a look at Figure D. This is the virtual machine's Settings page, as seen through the Hyper-V Manager. You will notice that the newly created virtual machine now has two virtual processors, a VM-Bus network adapter (which we created in Part 6), and two virtual hard drives.
Figure D: The virtual machine is now fully provisioned.
No comments:
Post a Comment