Installing a Printer in a Windows 7 Virtual Machine with an Ubuntu Host


2014-04-21

I recently needed to print a document using a website that wanted to run a Java applet on a Windows machine. After a bit of work I had a Windows 7 virtual machine guest printing to a printer connected to the Ubuntu host machine. I'll go through the steps to do this here in case I need to do it again or someone else is stuck trying to accomplish the same thing.

Install VirtualBox from Oracle

In the past I was fine using the VirtualBox version from Ubuntu's repository. This works great if all you need is encapsulated in the VM you're working with. However, once you want to interface the VM more closely with the host OS, you can run into trouble. Apparently there is some functionality missing when it comes to passing USB devices through to the guest machine using the open-source VirtualBox version. So make sure you go to Oracle's VirtualBox download page and get the Oracle version: Download VirtualBox.

Install Guest Additions

Next install guest additions. After your guest OS (Windows 7) is installed, boot it up and click on the "Install Guest Additions" option in the "Devices" menu of the VirtualBox window running the OS.

Install the Extension Pack

Now you need to install the "Oracle VM VirtualBox Extension Pack", also found on the Oracle VirtualBox download page. After downloading it, simply double click on it in your file manager. At this point I got an error saying

"The installer failed with exit code 127: Error creating textual authentication agent: Error opening current controlling terminal for the process (`/dev/tty'): No such device or address."

It seems that VirtualBox needs different permissions to install the extension pack, so I closed VirtualBox, opened my file manager as root (sudo thunar or sudo nautilus) and double-clicked it again.

Add user to vboxusers

Add your user to the vboxusers group that VirtualBox should have created upon installation. Do this with the following command:

sudo usermod -aG vboxusers yourusername

Select the printer as a USB device

At this point I recommend shutting down the Windows 7 guest and rebooting your Ubuntu host, just to as superstitious way to make everything "kosher". Now, after booting the VM again, you should be able to select your printer in the Devices>USB Devices menu. Once you select it, there will be check mark beside it and Windows 7 should see it and start installing drivers for the printer.

After that has completed, you should be able to print using your printer as if the VM were physically connected to it.