How to create a virtual machine with Hyper-V and basic components of Hyper-v

Hi folks, With our previous article about Hyper-V I thought may be I could show you how to create a Virtual machine in Hyper-V. Along the way I will describe each component required for a basic virtual machine creation. This will give provide you some understanding of how a Hyper-V machine operates on top of a host OS.
For todays article, our host OS is going to be Windows 10 Pro 2004 version. It is the latest Windows 10 version offered by Microsoft at the time of writing. However if you are on older version of Windows 10 or running Windows server 2016 or Windows Server 2019 steps of creating a basic virtual machines are similar. Let's get started then shall we?
Components of a basic Hyper-V machine.
Hyper-V virtual machine is also like a physical machine. It has the same hardware requirements as a physical computer. Although because it is a virtual computer, Hyper-V services and software components in the host OS is presenting them to the Guest OS. Before going any further you folks might be wondering what is an host OS and what is a guest OS. It's easy to understand. Host OS is the OS which provides us resources to create and run a virtual machine. Guest OS is the Operating system resides inside the Virtual machine.
Now let's take a look at basic components of a Hyper-V Virtual machine.
Virtual HDD
All computers needs to store their data somewhere and that's where the HDDs come in. You see as the physical HDDs provide the data storing functionality to the physical computers, Virtual HDDs provides this functionality to Virtual computers. When working with Hyper-V you will encounter two major file types for virtual HDDs. They are .vhd and .vhdx. .vhdx file format is the latest one. We will also use that format since it offers great adaptability, versatility, compatibility and performance. How ever you can also use .vhd file type for your virtual HDD. It has several limitations such as 2TB maximum size, some new OSs don't support them, compatibility issues arising when migrating VMs between hosts etc. Following screenshot is from a Virtual HDD creation window within Hyper-V manager and it'll shed some light to what I've described.
Virtual HDD are also can be categorized as Dynamic and Fixed disks. Dynamic disks are Virtual HDDs that will expand it's size as you add more data to it. They are most useful when you are need to save your host computer's space and light workload scenarios which doesn't need higher data storage I/O. Fixed size disks are again as the name implies, have fixed size. When you create a fixed size disk, the Hyper-V manager will pre-allocate the size you have specified from your host computer's HDD to the Virtual HDD. These types of disks will offer a great I/O speeds which is great for frequent data storing and reading applications such as database servers, ERP servers etc. There are also differencing disks available in Hyper-V. They are associated with a parent Virtual HDD and used for rapid deployment of Virtual machines. Since our goal here is getting a basic Virtual machine up and running, we will not dive in to details of differencing disks in this article. Screen shot below will also will shed some light in to what these disk types are and their uses.
Virtual ODD (Optical Disk Drive)
Virtual Optical Disk drive is also like your physical disk drive. It acts as the optical disk drive for your VM. You have the options to create attach a .iso image file as the disk of the ODD of the VM or you can point the DVD/CD drive of your physical host as the disk of your ODD of the VM. That way you can install OS/Applications and access file on a physical CD/DVD in your VM. Below screenshot shows the options for a ODD in a VM.
Virtual Networks
Networking is a must have functionality in today's computing. So for your VMs you might need a network connection to perform tasks as software installations/updates, browsing internet and updating your OS etc. You might want to connect your VM to the external network if you are installing a test application on that VM which needs to be accessed by the users. Maybe you want to deploy a set of VMs that only have the ability to see each other but not the external network. Also you may need your VM to be accessed only by host machine it was created on but not the external network. Luckily Hyper-V provides options for all these scenarios and makes it easy for you to switch networking of your VM on the fly. It means that you can connect your VMs to different networks at any given time. You can even connect your VMs to two or more networks at the same time. To access networking functions from your VMs you must create Virtual Network Switches. They function same as physical networking switches, so you can connect more than one VM to a virtual network switch. These switches are also capable of VLANS. Since our objective here is showing your the basic functions of Hyper-V we will not be discussing the advanced features of these switches. There are three primary network switch types available in Hyper-V. They are,
1. External Network Switch
These types of network lets your VMs connect to the external physical network through your host computer's physical network adapter. When creating this type of virtual network switch you have to specify which one of your physical network adapters is going to be used for communicating with the external network. In order to do that you need to access Virtual Switch Manager in Hyper-V console.
2.Internal Network Switch.
Internal network switches are used to create virtual networks which allows communication only between the host computer and VM inside that host computer. You do not need to designate a physical adapter for these types of switches since there won't be any external communications. Virtual Switch Manager is the function of Hyper-V you need to use for this. In the virtual switch manager click on "New virtual switch" on the left pane and select internal. Then click on "Create Virtual Switch" button to create the internal network switch. You may also give a unique name for your internal network switch for easy reference.
3.Private Network Switch.
Private network switches are used to create virtual networks which allows communication only between VMs inside the host computer. You do not need to designate a physical adapter for these types of switches since there won't be any external communications. Virtual Switch Manager is the function of Hyper-V you need to use for this. In the virtual switch manager click on "New virtual switch" on the left pane and select private. Then click on "Create Virtual Switch" button to create the private network switch. You may also give a unique name for your internal network switch for easy reference.
VRAM ( Virtual Random Access Memory)
Your physical computer needs a RAM to operate normally. So does your VMS. In any Hyper Visor there are options to specify how much RAM you need to allocate to a VM and you can change the virtual RAM of your VMs using these options. Since we are talking about Hyper-V in our article here let's discuss options specific to Hyper-V. When talking about VRAM options in Hyper-V there are two types of VRAM options in Hyper-V. They are Dynamic VRAM and Static VRAM. Dynamic VRAM is the most versatile option of both of these. If you are using Dynamic VRAM on a VM, the algorithms in Hyper-V analyses how much RAM is needed for the VM to function optimally and allocate that amount from the host's physical RAM precisely so the host will be able to run greater number of VMs. Also when using Dynamic VRAM there is an option to set a VRAM buffer in Hyper-V. What this option does is that it defines a buffer as a percentage so it can calculate precisely how much memory a VM is going to need to operate without performance issues. On the other hand, Static RAM is the VRAM type that will stay consistent until the VM is turned off. Static RAM offers more reliable performance than Dynamic RAM and is great for VMs which are hosting memory dependent applications such as database servers, mail servers and application serves etc. Also in Hyper-V you can set a VRAM priority for the VM. This settings tells the host computer to allow priority to certain VMs so you can prioritize which VMS should run optimally and which VMs have lower priority for performance so you can keep your mission critical VMs in peak condition. Below is a screenshot from one of the VM's settings about VRAM.
Creating a Basic VM in Hyper-V
OK folks. You read this far that means you are still interested. Let's get to the fun stuff now. We are going to create a virtual machine on my laptop with the OS as Windows 10 2004 build 2GB of VRAM and 4 processor cores. We are going to use an .iso image to install our operating system and connect it to a external network called External LAN. This artcile assumes that you have installed Hyper-V with the necessary components on your computer using "add or remove programs" in Control Panel or Using "Server Manager" or powershell on your server.
1. Open Hyper-V manager on your server and click on new and then click on virtual machine.
2. A wizard window will open which will be explaining the use of the wizard. You can tick the "Do not show this window again" check box if you do not want to see this page again in the future. Click next on that Window.
3. Next window will open and it'll present you with the options to set a name for your VM and a storage location to save files of the VM. You can use network path for these files or you can save the files on a drive on the local computer. Hyper-V supports storing VM files on SMB 3.0 file shares. For the sake of simplicity of this article let's save the VM on a local folder on the host computer. Also when I create folder structure to host my VMs on a host computer I like to do that to a particular order. I usually create the folder which contains the same name as the VM. Then I create two folders inside it named HDD and Info. The HDD folder houses the VHD of the VM and information folder houses the information files which contains info about VRAM, VCORES, VNET of the VM. This way if your host goes down and in an unrecoverable state you could get the HDD of the host, plug it to a different host and copy files of essential VMs to the new host with ease. So in my case I named this VM as "Demo_Win_10" and I provided the path as in the screenshot. After providing that information click on next on that window.
4. Then on the next window you have to specify the generation for the VM. In context, Gen1 is for older Operating Systems that doesn't support UEFI based ROMS. Gen2 is for the Operating Systems that supports UEFI based ROMS. Gen1 is older and have many limitations such as maximum VRAM capacity being 2TB, network booting only possible via legacy vnet adapter which are limiter to 100Mbps capacity etc. Gen2 VMs are not limited in those ways and their have the ability to add virtual hardware while the VM is powered on. Since we are installing Windows 10 which is capable of UEFI based ROMS I'm going to select Generation 2 here. After selecting the generation for your VM click on "Next"
4.On the next window you are going to have to assign how much VRAM the VM is going to use. Since this is just demo machine and I'm going to assign 2GB VRAM and make it a Dynamic Memory. You'll have to specify memory in Mega-bytes so 2GB will be 2048MB. After setting the options click on "Next"
5.On the next windows you will have to assign a network for the VM. As I said earlier I want to add this VM to the physical network. Therefore I selected "External Lan" as my virtual which is bound to Ethernet adapter of my host PC. If you didn't create Virtual switches prior to selecting the VSwitch here the dropdown list will be empty. You can select the "Not Connected" default option if you wish to keep the VM out of a Virtual Network. After selecting the appropriate network for the VM click on "Next"
6. On the next windows you will need to create or attach a .vhd or .vhdx file for the VM which acts as the HDD of the VM. Since I didn't create the VHD file earlier I will create a .vhdx file with the default 127GB size and place it in the "HDD" directory of the VM folder. At this window, you can also select "Attach a virtual hard disk later" option to skip this page and create and attach VHD separately and add it later using VM settings Window. After selecting the HDD options click "Next" on the window.
7.On the next window of the wizard, you'll need to specify the OS installation media. You can skip this step by using the first option and add the OS installation method later in the VM settings window, provide and .iso file to be installed from or use a pxe server to install the OS. Since we are using an .iso file to install the OS, I'm pointing this to a an .iso file on my host computer's Hard Drive. After selecting the OS installation method click "Next" to go to the summary page.
8.Next you will be presented with the summary window which provides you the details about the VM you are going to create. You can review your selections here and change anything by going back. I don't have anything to change here so I'll click finish and let the Hyper-V manager to create the VM.
9.After creating the VM you will be able to see it on the Hyper-V manager. We are not done yet. We need to change the VCORES of the VM from 1 to 4 as we need 4 processing cores in our VM. therefore right-click on the VM and select "settings" on the drop-down menu, and the VM settings window will be opened.
10. On the settings window go to the Processor section and increase the "Number of virtual processors" value to 4 and then click "OK"
11. After that you'll have successfully created your VM and you can power it up by right-clicking the VM and selecting the start option and connect to it by again right-clicking and selecting "connect" option. After connecting you can complete the OS installation as you would on a physical computer and start using it.
Conclusion
So as you can see creating a VM in Hyper-V is a fairly straight forward and simple process. Please let me know if you run into any issues while creating a VM so I will be able to help you out.



Nice work! Keep the good thing up!
ReplyDeleteGreat Article. Please continue the good work!
ReplyDelete