Skip to content

Instantly share code, notes, and snippets.

@gon1332
Last active October 14, 2023 15:15
Show Gist options
  • Save gon1332/70422af1fa6bed497964701b81fef124 to your computer and use it in GitHub Desktop.
Save gon1332/70422af1fa6bed497964701b81fef124 to your computer and use it in GitHub Desktop.
VirtualBox+Ubuntu: Fix USB device list not showing
#!/bin/bash
#
# Heavily inspired by https://github.com/dnschneid/crouton/wiki/VirtualBox-udev-integration
#
vbox_usbnode_path=$(find / -name VBoxCreateUSBNode.sh 2> /dev/null | head -n 1)
if [[ -z $vbox_usbnode_path ]]; then
echo Warning: VBoxCreateUSBNode.sh file has not been found.
exit 1
fi
chmod 755 $vbox_usbnode_path
chown root:root $vbox_usbnode_path
vboxusers_gid=$(getent group vboxusers | awk -F: '{printf "%d\n", $3}')
vbox_rules="SUBSYSTEM==\"usb_device\", ACTION==\"add\", RUN+=\"$vbox_usbnode_path \$major \$minor \$attr{bDeviceClass} $vboxusers_gid\"
SUBSYSTEM==\"usb\", ACTION==\"add\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$vbox_usbnode_path \$major \$minor \$attr{bDeviceClass} $vboxusers_gid\"
SUBSYSTEM==\"usb_device\", ACTION==\"remove\", RUN+=\"$vbox_usbnode_path --remove \$major \$minor\"
SUBSYSTEM==\"usb\", ACTION==\"remove\", ENV{DEVTYPE}==\"usb_device\", RUN+=\"$vbox_usbnode_path --remove \$major \$minor\""
echo "$vbox_rules" > /etc/udev/rules.d/virtualbox.rules
rm -f /etc/udev/rules.d/*-virtualbox.rules
udevadm control --reload
adduser `logname` vboxusers
echo All actions succeeded.
echo Log out and log in to see if the issue got fixed.
@vitalz
Copy link

vitalz commented Dec 26, 2019

Will it replace logname by a proper logged on user name? It didn't on Linux Mint in my case.

@gon1332
Copy link
Author

gon1332 commented Dec 26, 2019

Will it replace logname by a proper logged on user name? It didn't on Linux Mint in my case.

Yes. If this doesn't work, just replace it with your logged on user name.

@vitalz
Copy link

vitalz commented Dec 26, 2019

Will it replace logname by a proper logged on user name? It didn't on Linux Mint in my case.

Yes. If this doesn't work, just replace it with your logged on user name.

Thank you. This fix resolves a VirtualBox usb issue for guest OS Windows 7 on Mac mini mid-2010 host running Linux Mint.

@royalroot
Copy link

Thanks works perfectly.

@maikeldf
Copy link

It worked for Ubuntu 18.04 host / Win 10 guest
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment