VirtualHere with Raspberry Pi as USB server

When you want to use USB devices in a virtual machine you don't want to connect them to your physical ESXi-host and then from there pass through to a virtual machine. By doing this you pin the virtual machine to the host. For example with a failover the virtual machine would boot on another host and would not be able to connect to it's USB-device, which is still plugged into the failed host. Also with vMotion your options are limited. To solve this problem several solutions have been around to access USB-devices remotely via the network. 

Raspberry Pi logoWhen I was working with a Raspberry Pi recently I stumbled upon a program named VirtualHere USB Server which allows for remote connectivity to devices that are connected to a Raspberry Pi. The great thing about this solution is the low cost: the Raspberry Pi costs somewhere from $35 to $50, depending where you live and where you order it. And a license for using multiple devices with VirtualHere costs $29.00. In the free trial-version you can connect one device and a popup will be displayed. So for under one hundred dollars you can run a USB-server in your network that also doesn't consume too much power.

In the image below you see the Raspberry Pi model B that I have used for this project in a case, with power and Ethernet plugged in and one USB-device, a USB-thermometer. I have also tested other USB-devices such as a memory-stick and it's simple and easy to use those over the network. You can also use a USB-hub for multiple devices but make sure it's a powered hub if you are connecting many devices to not draw too much power from the Raspberry Pi itself.

Raspberry Pi with USB device

I would go for the Model B of the Raspberry Pi because it has a built-in 10/100 Ethernet-network-connection. VirtualHere also has this software available for the BeagleBoard by the way so that's also an option. And if you own a QNAP or Synology NAS you can also turn that into a USB server. 

Server Setup

How to setup the Raspberry Pi is beyond the scope of this article, the best location to read about how to do that is at www.raspberrypi.org/downloads 

For my setup I have installed the Raspberry Pi with Raspbian. From there go to the Pi Store where you will find the VirtualHere USB Server for installation. Or download it from the developer's website at www.virtualhere.com/usb_server_software.

What you need to do to make it into a server is load it as a daemon at startup. How to do this is described here: www.virtualhere.com/oem_faq

Once it is running it is a good idea to first go into the client and manually connect to one of your devices to see if it works. Once it works it is a good idea to configure additional security to authorize which users or from which hosts you can access the USB-devices.

Client Setup

The client is available for Windows (32 bit and 64 bit) and OSX 10  
www.virtualhere.com/usb_client_software

The client setup will ask you to install Bonjour to automatically discover USB Servers in your network. There is no need to do this, you can setup access to your server based on the IP address. And also the port is configurable (default port is TCP 7575). In the config.ini file that you will see below you can also see that you can disable the automatic discovery feature (AVAHI) by setting the value of the UseAVAHI parameter to 0.

If you right click the USB Hubs entry in the client there is an option to disable the Auto-Find feature and specify the IP-adress and port of the hub you have installed.

Specify hubs for VirtualHere Client

Once you are connected to the server the devices attached to your USB Server are listed and you can right-click those to connect. As you can see in the image below there is also a feature to automatically attach to the device when the client is started. Also the client can be started with Windows by adding it to the Startup-menu. At this time (January 2014) there is no feature to run the client as a service, but the developer (Michael Moore) wrote in a forum-post that he is working on that.

Auto-Use device for VirtualHere Client

Add security to your setup

If your setup works than you have noticed that you could connect to the server without any authentication and that you could use all of the attached devices. If you are going to implement this in your organizations network then you want to control access to your USB-devices.

There are several possibilities to control access, based on username, IP-address and which device is being accessed. In this article I have used the example of specifying the IP-address of the client that is allowed to access the devices on the USB Server. The shell-script is clear and simple so adding your own criteria should not be too much of a problem. This example is based on the developer's information: www.virtualhere.com/node/273

Before modifying the configuration file stop the daemon with this command:

sudo /etc/init.d/vhusbdpi stop

Next you specify the authentication script in the config.ini file. Edit the file with nano:

​sudo nano /<path-to-config file>/config.ini  (for example: ​sudo nano /root/config.ini)

And add this line to the end of the file: (all on one line)

clientAuthorization=/home/pi/auth.sh "$VENDOR_ID$" "$PRODUCT_ID$" "$CLIENT_ID$" "$CLIENT_IP$" "$PRODUCT_SERIAL$"

config.ini file for VirtualHere

In this example the script that handles the authentication is auth.sh in user pi's home directory. Don't forget to make it executable with this command: chmod +x auth.sh

authentication script for VirtualHere

Now start the daemon again:

sudo /etc/init.d/vhusbdpi start

If you need to find out what the vendor ID is or the product ID then you could have a look at the log files where information about the authentication is logged. Or right-click the device in the client and access the properties to display that information. 

VirtualHere USB device information in client

With this information you could for example modify the IF-statement with and AND operator to check both the IP-address and the product-ID to allow a specific server to access only one specific device. When modifying the authentication script there is no need to stop and start the daemon, the authentication script is run each time a client tries to connect to a device.

 

Follow us on LinkedIn

  

   

   

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer