Bobcares

LXC USB passthrough

by | May 8, 2023

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.

All About USB passthrough in LXC

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

  1. First, we have to install the required packages as seen below:

    sudo apt-get install lxc lxc-templates libvirt-bin qemu-kvm

  2. 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

  3. After that, restart the LXC service.
  4. Then, add this line to the container’s configuration file located at /var/lib/lxc//config:

    lxc.cgroup.devices.allow = c 189:* rwm

  5. Then, start the container.
  6. After that, it is time to plug in the USB device that we want to pass through to the container.
  7. 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.

  8. 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=file

    Remember 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.

  9. Now, restart the container.
  10. 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.

GET STARTED

3 Comments

  1. Thomas Neumann

    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

    Reply
  2. Thomas Neumann

    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:
    Bus 002 Device 002: ID 090c:2000 Silicon Motion, Inc. – Taiwan (formerly Feiya Technology Corp.) Intenso Speed Line

    What I have to insert and where?

    Thank you

    Reply
    • Hiba Razak

      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).

      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF