Running Hyper-V on Amazon EC2 Bare Metal Instances
This post courtesy of Siavash Irani, AWS Solutions Architect and Bryan Mareletto, AWS Technical Program Manager
AWS recently announced the general availability of Amazon EC2 bare metal Instances. This post provides an overview of launching, setting up, and configuring a Hyper-V enabled host, launching a guest virtual machine (VM) within Hyper-V running on i3.metal.
The key elements of this process include the following steps:
- Launch a Windows Server 2016 with Hyper-V AMI provided by Amazon.
- Configure Hyper-V networking.
- Launch a Hyper-V guest VM.
Launch a Windows Server 2016 with Hyper-V AMI provided by Amazon
1. Open the EC2 console.
2. Choose Public Images and search for the Amazon Hyper-V AMIs.
3. Select your preferred Hyper-V AMI, and choose Launch.
4. Follow the Launch wizard process to launch the instance on i3.metal.
The Amazon Hyper-V AMIs have the Hyper-V role pre-enabled. You can also launch a Windows Server 2016 Base AMI to i3.metal, and enable the Hyper-V role for your use case.
Configure Hyper-V networking
To enable networking for your Hyper-V guests—so they can have connectivity to other resources in your VPC, or to the internet via your VPC internet gateway, ensure that you have first configured your VPC. For more information, see Creating and Attaching an Internet Gateway.
Hyper-V provides three types of virtual switches for networking:
In this solution, you are creating an internal virtual switch and using the Hyper-V host as the NAT server for the guest VMs, similar to Microsoft’s topic Set up a NAT network.
You can specify your own virtual network range. For this example, use 192.168.0.0/24 as the range for the virtual network inside the Hyper-V host.
- Run the following PowerShell command to create the internal virtual switch:
New-VMSwitch -SwitchName "Hyper-VSwitch" -SwitchType Internal
- Determine which network interface is associated with the virtual switch. For this solution, the Get-NetAdapter command shows that the Hyper-V virtual switch has an ifIndex value of 12.
- Configure the Hyper-V Virtual Ethernet adapter with the NAT gateway IP address. This IP address is used as default gateway (Router IP) for the guest VMs. The following command sets the IP address 192.168.0.1 with a subnet mask 255.255.255.0 on the Interface (InterfaceIndex 12):
New-NetIPAddress -IPAddress 192.168.0.1 -PrefixLength 24 -InterfaceIndex 12
- Create a NAT virtual network using the range of 192.168.0.0/24:
New-NetNat -Name MyNATnetwork -InternalIPInterfaceAddressPrefix 192.168.0.0/24
Now the environment is ready for the guest VMs to have outbound communication with other resources through the host NAT. For each VM, assign an IP address with the default gateway (192.168.0.1). This can be done manually within each guest VM. In this solution, you make it easier by enabling a DHCP server within the Hyper-V host to automatically assign IP addresses.
Setting up DHCP server role on the host
- Run the following command to add the DHCP role to the host:
Install-WindowsFeature -Name 'DHCP' -IncludeManagementTools
- To configure the DHCP server to bind on the Hyper-V virtual interface, choose Control Panel, Administrative Tools, DHCP.
- Select this computer, add or remove bindings, and then select the IP address corresponding to Hyper-V virtual interface (that is, 192.168.0.1).
- Configure the DHCP scope and specify a range from the subnet that you determined earlier. In this example, use 192.168.0.10~192.168.0.20.
Add-DhcpServerv4Scope -Name GuestIPRange -StartRange 192.168.0.10 -EndRange 192.168.0.20 -SubnetMask 255.255.255.0 -State Active
- For Router, choose the NAT gateway IP address assigned it to the Hyper-V network adapter (192.168.0.1).
- For DNS server, use the Amazon DNS, which is the second IP address for the VPC (172.30.0.2).
Launch a Hyper-V guest VM
For this post, follow the new VM wizard to create an Ubuntu 18.04 LTS guest VM. First, download the Ubuntu installation ISO from the Ubuntu website to your Hyper-V host, and store it on a secondary EBS volume that you added as the D: drive.
I3.metal instances use Amazon EBS and instance store volumes with the NVM Express (NVMe) interface. When you stop an I3.metal instance, any data stored on instance store volumes is gone. I recommend storing your guest VM’s hard drive (vhd or vhdx) on an EBS volume that is attached to your I3.Metal instance. This can be the root volume (C:) or any additional EBS volumes attached to the instance. For more information, see What’s the difference between instance store and EBS?
After that is complete, follow these steps:
- In Hyper-V Manager, choose Actions, New, Virtual Machine.
- Follow the wizard with your desired configuration up to the Configure Networking section.
- In the Configure Networking step, for Connection, choose Hyper-V Switch, and choose Next.
- In the Connect Virtual Hard Disk step, enter a name for the virtual hard disk. Use the default location C:\Users\Public\Documents\Hyper-V\Virtual Hard Disks\.
- Specify the size of the virtual hard disk, and choose Next.
- In the Installation Options step, choose the Ubuntu ISO that you downloaded earlier.
- Finish the wizard and start the VM, then follow the steps on the Ubuntu installation wizard. As you have already set up DHCP and NAT for the Hyper-V network, the Ubuntu VM automatically gets an IP address from the DHCP scope that you defined earlier.
- Confirm the connectivity of the VM to the internet
You’ve just built a Hyper-V host on an EC2 bare metal instance. Now you’re ready to add more guest VMs and put them to work!