0

I have a remote Windows 10 computer that serves as host for Linux (Debian 9) running as guest inside VirtualBox. The VM runs in Network Bridged Mode, so both OSes have local IP addresses and can "see" each other. I have access to the guest Linux (which is part of a VPN) via SSH from my local machine. From the guest I can also access the host's command prompt/bash/powershell via SSH server (which is built into Windows 10). Sometimes I need to be able to access an attached USB device from both OSes. It doesn't have to be simultaneously - one after the other is OK.

It is trivial to switch an attached USB device between host and guest via VirtualBox GUI (Devices -> USB Devices). But is there a way to do so from the command line - either from host or from guest or, even better, from both?

1 Answer 1

4

To manage a VirtualBox VM using the commandline you'd use the VBoxManage command/tool. Beware that on Windows this is not added to the path, so you will have to manually navigate to the directory (e.g. cd /D C:\Program Files\Oracle\VirtualBox).

After that you can use the VBoxManage command to attach a USB device but it's a bit more intricate than doing it using the GUI.

Following this blog post by Antony Jepson:

  • Find the ID/name of the VM: VBoxManage list vms
  • Find the ID of the USB device: VBoxManage list usbhost
  • Attach the devices to the VM: VBoxManage controlvm <VM> usbattach <ID>

The official help Chapter 8 also has some information about what other commands are available. Specifically you're probably interested in usbdetach for controlvm in order to remove the USB device.

The mentioned blog post also shows how to create a USB filter to permanently attach a USB device to a VM.

3
  • Is there a way to do so from within the guest Linux? Mar 9, 2018 at 10:32
  • 1
    Maybe if you do create a remote session to the host from the guest. I'm doubtful you would be able to trigger this from within the guest as it would allow you to influence the host. Another possible workaround (probably not that reliable) would be a magic file on a file share. So your guest could change that file and script on your host could act on those changes.
    – Seth
    Mar 9, 2018 at 10:39
  • 1
    The mentionned blog post can be founded here antonyjepson.wordpress.com/2012/01/26/… now Sep 4, 2020 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.