The Hyper-V Deployment guide contains little more than this: “Note: No access to a physical COM port is available from a virtual machine.” What follows is a recipe to access the physical COM ports on the host from a guest using com0com, and its related utilities.
Unlike many other virtualization solutions, it’s not particularly easy to connect a Windows 2008 Hyper-V guest to its host serial ports. Perversely, there are settings to connect the guest COM ports to “named pipes,” but there’s no way on the host to connect COM ports to named pipes. (It appears that this option is used primarily for debugging programs, rather than for using actual serial ports — it doesn’t appear to have been intended to be used to provide actual serial port access from the guest.)
The Hyper-V Deployment guide contains little more than this:
“Note: No access to a physical COM port is available from a virtual machine.”
What follows is a recipe to access the physical COM ports on the host from a guest using com0com, and its related utilities. The idea is to make a COM port on the host available via TCP/IP, and then attach to it via the guest, then make this process automatic.
First, on the guest, you’ll need an appropriate version of hub4com, and the batch file bundled with it, com2tcp-rfc2217.bat. Naturally, I’m running 64-bit Windows 2008, and there doesn’t appear to be a version compiled for 64-bit Windows, so I had to compile my own. This can be kind of a pain, especially if you’re using Visual Studio Express, so you’re welcome to download my 64-bit hub2com binaries here.
My device is on COM3, and I can make it available on port 7000 using the following command line:
This gives me a DOS Window that shows me what’s going on — this is handy for debugging, but hardly something I want to leave on my screen all the time. The simplest solution is to create a launcher script:
This script effectively hides the program so that it can run in the background, so all that remains is to have it launch when the system starts. That’s best accomplished using the registry to create a new “Expandable String Value” under “HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun”. It doesn’t matter what the Name of the String Value is, but the Data should be the command line necessary to launch the script:
When done this way, the port is made available whether or not anybody is actually logged into the machine.
The guest is only slightly trickier, requiring both com0com and hub2com binaries to be installed. Since my guest is 32-bit Windows XP, I could use the precompiled “i386” binaries directly from the c0m0com sourceforge page.
The com0com installer wants to create a null modem pair from “cnca0” to “cncb0.” You’ll need this pair of virtual devices, and you’ll want to turn on “baud rate emulation,” and rename one end like a regular COM port. This can be accomplished from the com0com command line setup:
Once the virtual port pair is available, one end can be connected to the host, using the hub2com batch file com2tcp-rfc2217:
As before, this opens a DOS Window where you can see what’s going on. At this point, COM3 on the guest is communicating directly with COM3 on the host. As before, a small launcher script is created to hide this window:
And, as before, a registry string is added to the guest to launch this automatically in its own “HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun” key.
Simple, eh? Well, perhaps not, but once it’s set up, the guest Hyper-V machine can communicate via COM3. Additional ports can be added in the same way.
Accessing USB devices from virtual environments such as VMware and Hyper-V is useful in many situations. In this article, we are going to show you how to make a USB recognizable in Hyper-V either as a host or client.
Hyper-V USB Passthrough is the ability to access USB devices from within Hyper-V (formerly known as Windows Server Virtualization)
Table of contents:
Access USB in Hyper-V in 3 clicks
USB over Network (aka USB Network Gate) provides a solution to the question of how to access a USB in Hyper-V. The specialized communication software enables you to attach USB devices in Hyper-V by sharing USB devices across a network.
USB Network Gate is a client-server solution, meaning that its server-side gives access to USB devices to other computers on the network or to Virtual Machines, and client-side allows using them as local resources. You can use any computer connected to the network as a server, either Windows 10, Mac or Linux one.
Here’s how to access USB in Hyper-V by employing the dedicated software solution of USB Network Gate.
This solution requires just a few easy steps to implement Hyper-V USB passthrough. No additional hardware or configuration is required.
- Install the software on the host and guest operating systems.
- Share a device that is physically attached to the host over your network.
- On the client VM locate the USB peripheral in the application and click ‘Connect’.
That’s how to mount a USB flash drive in Hyper-V. It really is that easy. You will see the peripheral in your VM’s Device Manager and be able to access it as if it was directly connected to your machine.
Pros and cons to access USB in Hyper-V with USB Network Gate
- Virtually all USB devices are supported.
- Simple configuration to implement USB access across the network.
- USB Network Gate is compatible with the Linux, Mac and Windows operating systems including Windows 10.
- Creates secure USB connections.
- USB Network Gate is commercial software and has a financial cost.
- Network connectivity is needed to redirect USB traffic.
How to get Hyper-V to recognize USB
Hyper-V USB passthrough can be performed at the client Hyper-V level or at the host level if you are connecting to USB devices.
Server-side USB passthrough in Hyper-V
It is not as easy to implement Hyper-V USB passthrough as it is to set it up in VMware. Let’s take a look at how it’s done in the following step-by-step demonstration.
- We will attach a 32GB USB flash drive into a Hyper-V server and designate it as Drive E. The host operating system immediately sees the drive as available system storage.
Note: A potential issue is that direct access to the USB device is limited to one operating system at a time. In order to make the device available to the Hyper-V clients we need to take it offline and remove the logical connection to the host OS.
- We do this by opening the machine’s Run prompt and executing the DISKMGMT.MSC command. This starts the Disk Management console. Locate the entry for your USB disk and right-click on the disk. You need to use the actual disk, not the drive letter or volume name.
There is an Offline option in the shortcut menu which will be used to take the disk offline.
Note: The Disk Management Console might not offer the Offline option for small USB storage devices. If that is the case, passthrough for USB in Hyper-V will not be able to be implemented.
- Open the Hyper-V Manager after you have successfully taken the USB device offline.
- Select the VM that requires access to the device. Right-click on it and select Settings from the shortcut menu which opens the VM settings screen.
- Next, you need to select the Hard Disk option for the SCSI controller and click the Add button.
- When the next screen displays, select the Physical Hard Disk option and use the drop-down menu to select your USB storage device.
Now the Virtual Machine should be able to recognize and access the USB device. You may need to use the VM’s Disk Management Console to add a drive letter if the device is not immediately visible.
Hyper V Add Serial Portal
Hyper V Enhance session mode - access USB with RDP client
To copy files between virtual machines in earlier versions of Hyper-V you employed a network file copy or Remote Desktop Connection session. Both of these options entail having an operational network connection. Using the Virtual Machine Connection limited the amount of data that could be sent to the VM.
A similar method is used in enhanced session mode but the requirement to connect to the VM over the network is eliminated. All that is needed is a network connection to the Hyper-V host where the VM is running.
This feature of enhanced session mode can be instrumental in cases where a VM needs to interact with local devices but may not be able to achieve network connectivity. Here are some examples:
- Printing to a local printer from a VM
- Using a USB-attached reader to log into a VM using a smart card
- Debugging issues encountered with a VM without requiring it to be network connected
Developers can make use of Microsoft Hyper-V USB passthrough to test and debug USB applications from within a VM without relying on Remote Desktop Connection.
- Hyper-V Manager is used to configure enhanced sessions. Simply select the Hyper-V server to be configured and click on ‘Hyper-V Settings’.
- Enable server settings in the Enhanced Session Mode Policy which will be used for all VMs running under the Hyper-V host. Enabling the allow enhanced session mode setting determines if the guest VMs can make use of enhanced sessions.
- When enabled, enhanced session mode connections are allowed by Hyper-V if certain conditions are met. They are:
- ✔ The OS of the virtual machine supports enhanced session mode.
- ✔ The VM is running Remote Desktop Service.
- ✔ The Virtual Machine Connection tools requested an enhanced session mode connection.
Disabling the allow enhanced session mode setting forces the Virtual Machine Connection tool to use the methods previously seen in pre-R2 Hyper-V releases.
Enabling User Settings
Enhanced session mode is used to configure user settings. Enabling this setting allows the Virtual Machine Connection tool to use enhanced session mode if it is available in the guest VM. The following conditions must be met for enhanced session mode to be used:
- The OS of the guest VM supports enhanced session mode.
- Remote Desktop Service is running on the guest.
- Allow enhanced session mode is enabled on the Hyper-V host.
So, does Hyper-V support USB devices? As we have demonstrated, the answer is yes. You can enable USB support in a few different ways, but we believe that using the USB Network Gate application is the easiest and most effective solution. It will save time when compared to using Hyper-V enhanced session mode and any other solution.