Category Archives: Hyper-V

Hyper-V: Provide Internet Access for VMs with Internal/Private vSwitches

The Scenario

I have VMs configured to use either an Internal virtual switch or a Private virtual switch

The Problem

As neither an Internal or Private virtual switch are bound to a physical NIC they have no way of getting internet connectivity. This for me is a real problem as I want to connect to the internet to download updates and other files from these VMs.

The Solution

I’ve tested this solution on Hyper-V running on Windows Server 2008 R2 Enterprise, 2012 R2 Standard and Windows 10 Professional. This solution assumes the following:

  1. You have already created a standard Private and/or Internal virtual switch
  2. You have a physical NIC on the Hyper-V host that is already connected to a network that has Internet access.

Step 1: Open the services on the Hyper-V host and select the “Routing and Remote Access” service, enable it and set it to automatically run.

Check also that the “Internet Connection Sharing (ICS)” is set to automatic and is started.

Step 2: Open the Network and Sharing Center (NCS) and open the properties of the physical NIC on the Hyper-V host that is connected a network that has Internet connectivity. Select the Share tab and enable the “Allow other network users to connect through this computer’s Internet connection” option.

In the drop down menu select the virtual switch Private/Internal NIC which will use this ICS connection. In the NCS a new icon will appear called “Incoming Connections“.

Step 3: Staying in the Network and Sharing Center open the properties of the virtual switch Private/Internal NIC and ensure it has a static IP address. In my tests it was automatically assigned 192.168.137.1/24, but you can assign any address as you require – make a note of this as it is needed in Step 4.

Step 4: For the VMs to use this ICS, login to them and open their Network and Sharing Center and configure the NIC to have a static IP address in the same subnet. In my example I gave my VM the address 192.168.137.10/24. Finally set the default gateway for the VM to be the IP address of the address of the virtual switch Private/Internal NIC, in my case 192.168.137.1.

In my example I also added the google DNS server 8.8.8.8 to the DNS settings in the VM, but configure this as fits your requirements.

Step 5: Test you have Internet connectivity. In my example no further configuration was required, I had Internet access immediately

Important: As this client has got direct Internet access it is advisable to install an anti-virus solution and ensure it is fully patched.

 

Disclaimer: provided “AS IS” with no warranties and confer no rights

AVG 17.5.x firewall blocking Hyper-V VM connections

The Scenario

I have a Windows 10 (v1607) Pro instance with AVG Internet Security 17.5 installed, including the AVG Firewall component.

I have the Hyper-V feature enabled and an Internal Hyper-V vSwitch named “hv-int” which all my VMs use. This vSwitch uses the APIPA 169.254.0.0/16 range.

AVG175_version.png

The Problem

I cannot locally connect to any of my VMs via the Connect option in Hyper-V Manager, the connection just times out after several attempts. When I disable the AVG Firewall it works fine, but I don’t want to permanently disable my Firewall for obvious reasons.

The Solution

By default all local network connections, including Hyper-V vSwitches are classified as Public. By changing this to the more trusted Private option the local connections are permitted:

Step 1: Open the AVG management console

AVG175-0.png

Step 2:  Click the Internet Security option:

AVG175-1.png

 

Step 3:  Click the top-right Menu > Settings option – this lists the AVG components installed.

AVG175-2.png

Step 4: Click the left-menu Components option and in the main pane scroll down to the Firewall option. Click Customize.

AVG175-3.png

Step 5: Click the left-menu Network profiles option and in the main pane locate your Hyper-V vSwitch. Change the Profile type from Public to Private. Click OK to confirm the changes and exit out of the AVG console.

AVG175-4.png

Now try launching a local connection to the VM via the Hyper-V Manager, in my case it now worked.

 

Disclaimer: provided “AS IS” with no warranties and confer no rights

Hyper-V Compact VHD(X) Disk Task Taking Hours to Complete in GUI

The Scenario

I have a VM on my Windows Server 2012 R2 Standard with Hyper-V role. It has a dynamically expanding disk which I need to compact to reclaim disk space on the host.

The Problem

I used the Hyper-V Management console to compact the disk, but after several hours it’s still running. And because you can only compact a disk on a powered-off VM my business critical VM remains offline.

The Solution

In my case the compact process actually completed successfully within 30 minutes, it’s just the GUI had crashed even though it looked like it was still running normally (the green progress bar hadn’t quite reached the end). I found this out by look in the Event Logs:

Event Viewer > Applications and Services Logs > Microsoft > Windows > Hyper-V-VMMS > Operational log

Search for event ID 27301

“The system successfully compacted ‘:\Virtual Hard Disks\.vhdx’.”

Once I saw this I pressed cancel on the GUI compact window and restarted the Hyper-V management console. I was then able to successfully power-on my VM and the space had been successfully reclaimed.

I also noticed that the high disk activity that had been seen during the early stages of the disk compaction had completely stopped, however the above event log gave me the confidence to cancel the GUI.

NB To enable disk performance counter in Server 2012 R2 open an elevated command prompt and enter the following command “diskperf -y” then close/reopen the task manager window.

Disclaimer: provided “AS IS” with no warranties and confer no rights

Hyper-V VM not recognising F8 Safe Boot Mode Keystroke

The Scenario

I have a Windows Server Vm running in Hyper-V. I have a problem with the OS and need to boot into Safe Mode by pressing F8 at boot time.

The Problem

The VM is not responding to the F8 keystroke, even if i start pressing it repeatedly, even over-zealously (mimicking days of yore when I played Daley Thompson’s Decathlon on the ZX Spectrum) as soon as the VM starts. The Safe Mode menu fails to materialise, instead it just boots as normal.

The Solution

Change the VM Automatic Start Action settings by changing the Automatic start delay time from 0 to 5 seconds (or any number greater than 3 seems to work). Click OK to Confirm.

f8_error

Now when you restart the VM and press F8 the menu will appear:

8_per_1

 

Get Hyper-V host name from guest VM

The Problem
I have a server that I know is a VM but I do not know what Hyper-V host it is on.

The Solution
Open an elevated PowerShell prompts on the guest VM and enter the following:

(get-item “HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters”).GetValue(“HostName”)

The Hyper-V host name will be returned

NB: please be careful when pasting lines that have quotation marks into PowerShell and notepad, then into PowerShell. I’ve found the format of the quotation mark is not recognised and causes the command to fail. If in doubt, manually replace the quotation marks.

Disclaimer: provided “AS IS” with no warranties and confer no rights

AVG blocking Hyper-V Internet Connection (IE not responding to connection attempts)

The Scenario

I have a Windows 8.1 Pro client and I’ve just installed a new instance of AVG Internet Security.

avg5

On my client I have the Hyper-V feature enabled with several guest VMs running These VMs are connected to the Internet via an external vSwitch which is bound to the hosts main Ethernet NIC.

The Problem

Since installing AVG my guest VMs can no longer connect to any webpage

browser-error1

Running the diagnostics returns the error “website is online but isn’t responding to connection attempts”

2browser-error1

The Solution

In the AVG advanced firewall settings there is an option to allow all traffic from/to virtual machines, this must be enabled.

Open the AVG console and select the Firewall component

avg0

Open the Firewall settings (click the cog)

avg1

Select the Advanced settings option

avg2

Open the Expert mode

avg3

Navigate to the Advanced Settings and check the box next to “Allow any traffic from/to virtual machines supported by the firewall. Click Apply and OK to complete the reconfiguration.

avg4

The guest VM is now able to connect to the Internet.

 

Disclaimer: provided “AS IS” with no warranties and confer no rights

Cannot connect to Hyper-V host via Windows 8 Client and Hyper-V Manager

The Scenario

I have domain Windows 8.1 client with Hyper-V manager installed. There is also a Hyper-V host (Windows Server 2012 R2 with Hyper-V role). The client needs to connect to the Hyper-V host via the Hyper-V Manager. The user logged on to the client is a member of the Hyper-V Administrators group on the host.

The Problem

The connection attempt fails with the following error:

hvm-error1

The Solution

On the host open an elevated command prompt and run:

MOFCOMP %SYSTEMROOT%\System32\WindowsVirtualization.V2.mof

mofcomp

No reboot is required, the fix is immediate.

Disclaimer: provided “AS IS” with no warranties and confer no rights