Using libusb with a Linux kernel greater than 3.4 and without udev

The majority of people have gotten used to using their udev based unix distributions, along with any bugs it decides to manifest and I am sure that they feel comfortable because they are now like the Windows users, who do not mind not being in control of their machines. The Linux kernel developers have also sold out to udev by removing the USB file system, which was used by libusb to show the devices on the USB bus, so that udev now has to be used if you want to see what USB devices you have with lsusb. This also caused me to not be able to pass through USB devices in Qemu, but at first I thought it was just a bug and did not realise that Qemu was using the usbfs before. It has actually taken me a few years to finally realise why Qemu would not pass through the devices and I finally received my answer when I came across a post on the libusb-devel mailing list, which you can find at the below link:

The long and short of it is that the usbfs was used as a device file system, a bit like devfs, which allowed USB devices to be directly accessed, so another means had to be devised to create the device nodes when usbfs was removed. The job was passed onto udev, which meant that you were forced to have it installed if you wanted to directly access your USB devices. Udev is nice for people who do not want to have a lean operating system, that never has any slowdowns, but if you want to handle all of your devices manually, then you would have to forget about direct access to any USB device nodes. After finding this thread, I ended up writing a bash script that will create all of the needed device nodes, according to the explanation of Alan Stern on the mailing list post. Below is the script and I will also attach it to the article as well.



for ((b = 1;b <= BUSSES;b++))
    bbb=$(printf "%03d" $b)
    mkdir -p /dev/bus/usb/$bbb
    for ((d = 1;d <= 127;d++))
        ddd=$(printf "%03d" $d)
        mknod /dev/bus/usb/$bbb/$ddd c 189 $((($b - 1) * 128 + ($d - 1)))
exit 0

I know the above code works because I used it on the laptop that I typed this on and can now pass through USB devices to Qemu on it as well. I kept the number of buses at 4 because my laptop does not have a PCI slot, so 4 is the maximum that I can use, but if you have a monster computer with many USB buses, then you will have to increase the value to cover the largest bus number that is in the /sys/bus/usb/devices directory.

USB device nodes add script — Downloaded 37 times