VirtualBox: switch access to an attached USB device between guest and host from command line
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.
Related videos on Youtube
user1876484
Updated on September 18, 2022Comments
-
user1876484 over 1 year
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?
-
user1876484 about 6 yearsIs there a way to do so from within the guest Linux?
-
Seth about 6 yearsMaybe 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.
-
Emmanuel Caradec over 3 yearsThe mentionned blog post can be founded here antonyjepson.wordpress.com/2012/01/26/… now