Learn how to enable LXC USB passthrough from our experts. Our LXC/LXD Support team is here to help you with your questions and concerns.
All About USB passthrough in LXC
LXC is a popular lightweight virtualization technology. It allows us to run multiple isolated containers on a single host.
On the other hand, the USB passthrough feature allows a USB device connected to the host to be passed through to a container/In other words, it makes the USB device accessible to applications running inside the container.
With LXC USB passthrough we can use USB devices like flash drives, external hard drives, and other USB peripherals, within a container. This comes in handy while running applications inside a container that need direct access to USB devices.
However, in order to use LXC USB passthrough, you have to install the corresponding Linux kernel modules on the host system. Furthermore, we have to configure the container to allow USB passthrough. After that, all we have to do is plug in the USB device and it will be automatically detected and made available to the container.
How to enable USB passthrough for LXC containers
- First, we have to install the required packages as seen below:
sudo apt-get install lxc lxc-templates libvirt-bin qemu-kvm
- Next, we have to add the following line to the LXC configuration file which can be found at /etc/lxc/default.conf:
lxc.cgroup.devices.allow = c 189:* rwm
- After that, restart the LXC service.
- Then, add this line to the container’s configuration file located at /var/lib/lxc//config:
lxc.cgroup.devices.allow = c 189:* rwm
- Then, start the container.
- After that, it is time to plug in the USB device that we want to pass through to the container.
- We can easily find the device path by running the lsusb command.
The output of this command includes a list of all USB devices currently connected to the system. Here, we have to note down the vendor and product IDs of the device you plan on passing through.
- Next, we must create a new file called usb.cfg in the container’s configuration directory and add the following lines:
lxc.cgroup.devices.allow = c <major>:<minor> rwm
lxc.mount.entry = /dev/bus/usb/<bus>/<device> /dev/bus/usb/<bus>/<device> none bind,optional,create=fileRemember to replace major and minor with the major and minor numbers of the USB device. Furthermore, replace bus and device with the bus and device numbers that we noted down in step 7.
- Now, restart the container.
- It is time to verify if the USB device is available inside the container by running the lssub command within the container.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
In summary, our Support Techs demonstrated how to enable USB passthrough in LXC with a few easy steps.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
Hallo,
Vielen Dank für diese Anleitung. Ich stocke leider am Ende mit der Angabe der Haupt- und Nebennummern und der Bus und
Geräte-Nummern.
lxc.mount.entry = /dev/bus/usb// /dev/bus/usb// none bind,optional,create=file
Ich habe folgende Zeile über lsusb bekommen:
Bus 002 Device 002: ID 090c:2000 Silicon Motion, Inc. – Taiwan (formerly Feiya Technology Corp.) Intenso Speed Line
Was würde denn da wohin kommen?
Vielen Dank
sorry, it´s a English side…
Hello,
Thank you for this guide. Unfortunately, I stock at the end when specifying the main and secondary numbers and the bus and
Device numbers.
lxc.mount.entry = /dev/bus/usb// /dev/bus/usb// none bind, optional, create=file
I got the following line via lsusb: Line
Bus 002 Device 002: ID 090c:2000 Silicon Motion, Inc. – Taiwan (formerly Feiya Technology Corp.) Intenso Speed
What I have to insert and where?
Thank you
Hello Thomas,
Our experts can help you with the issue.we will be happy to talk to you through our live chat(click on the icon at right-bottom).