Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

udevadm does not show all attributes inside a docker container

Tags:

docker

udev

When I run docker container and list properties of some device with udevadm inside the container, there are only the basic information about the device. When I do the same thing on host, I can see much more. What can I do to get all the information inside the container?

host$ udevadm info --query=property /dev/bus/usb/004/008
BUSNUM=004
DEVNAME=/dev/bus/usb/004/008
DEVNUM=008
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1
DEVTYPE=usb_device
DRIVER=usb
ID_BUS=usb
ID_MODEL=MCP2210_USB-to-SPI_Master
ID_MODEL_ENC=MCP2210 USB-to-SPI Master
ID_MODEL_ID=00de
ID_REVISION=0002
ID_SERIAL=Microchip_Technology_Inc._MCP2210_USB-to-SPI_Master_0000267472
ID_SERIAL_SHORT=0000267472
ID_USB_INTERFACES=:030000:
ID_VENDOR=Microchip_Technology_Inc.
ID_VENDOR_ENC=Microchip Technology Inc.
ID_VENDOR_FROM_DATABASE=Microchip Technology, Inc.
ID_VENDOR_ID=04d8
MAJOR=189
MINOR=391
PRODUCT=4d8/de/2
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=176769529274

host$ docker run -ti -v /dev/bus/usb/:/dev/bus/usb alpine sh
container# apk update
container# apk add eudev
container# udevadm info --query=property /dev/bus/usb/004/008
BUSNUM=004
DEVNAME=/dev/bus/usb/004/008
DEVNUM=008
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1
DEVTYPE=usb_device
DRIVER=usb
MAJOR=189
MINOR=391
PRODUCT=4d8/de/2
SUBSYSTEM=usb
TYPE=0/0/0

I have also tried to mount other volumes from host: /sys, /dev. Did not help.

EDIT according to the Alex P.'s answer:

I'm not very experienced with udev. I have copied this

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id", IMPORT{builtin}="hwdb --subsystem=usb"

to /dev/udev/rules.d/10-local.rules, I have set udev logging to debug, reloaded config with udevadm control --reload. Now I get this:

calling: info
P: /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2
N: bus/usb/004/016
no db file to read /run/udev/data/c189:399: No such file or directory
E: BUSNUM=004
E: DEVNAME=/dev/bus/usb/004/016
E: DEVNUM=016
E: DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.2
E: DEVTYPE=usb_device
E: DRIVER=usb
E: MAJOR=189
E: MINOR=399
E: PRODUCT=4d8/de/2
E: SUBSYSTEM=usb
E: TYPE=0/0/0

For now still no luck. I tried to run the container with --privileged flag, did not help. I have no other rules in /etc/udev/rules.d. I tried to copy all rules from my host, no luck.

host$ udevadm monitor --environment
    monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[183757.837879] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1 (usb)
ACTION=add
BUSNUM=004
DEVNAME=/dev/bus/usb/004/034
DEVNUM=034
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1
DEVTYPE=usb_device
MAJOR=189
MINOR=417
PRODUCT=4d8/de/2
SEQNUM=5985
SUBSYSTEM=usb
TYPE=0/0/0

KERNEL[183757.838467] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0
DEVTYPE=usb_interface
INTERFACE=3/0/0
MODALIAS=usb:v04D8p00DEd0002dc00dsc00dp00ic03isc00ip00in00
PRODUCT=4d8/de/2
SEQNUM=5986
SUBSYSTEM=usb
TYPE=0/0/0

KERNEL[183757.840044] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F
HID_ID=0003:000004D8:000000DE
HID_NAME=Microchip Technology Inc. MCP2210 USB-to-SPI Master
HID_PHYS=usb-0000:00:1d.0-1.1/input0
HID_UNIQ=0000267472
MODALIAS=hid:b0003g0001v000004D8p000000DE
SEQNUM=5987
SUBSYSTEM=hid

KERNEL[183757.840586] add      /class/usbmisc (class)
ACTION=add
DEVPATH=/class/usbmisc
SEQNUM=5988
SUBSYSTEM=class

KERNEL[183757.840891] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0 (usbmisc)
ACTION=add
DEVNAME=/dev/usb/hiddev0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0
MAJOR=180
MINOR=0
SEQNUM=5989
SUBSYSTEM=usbmisc

KERNEL[183757.841219] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0 (hidraw)
ACTION=add
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0
MAJOR=244
MINOR=0
SEQNUM=5990
SUBSYSTEM=hidraw

UDEV  [183757.842324] add      /class/usbmisc (class)
ACTION=add
DEVPATH=/class/usbmisc
SEQNUM=5988
SUBSYSTEM=class
USEC_INITIALIZED=183757842069

UDEV  [183758.395467] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1 (usb)
ACTION=add
BUSNUM=004
DEVNAME=/dev/bus/usb/004/034
DEVNUM=034
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1
DEVTYPE=usb_device
DRIVER=usb
ID_BUS=usb
ID_MODEL=MCP2210_USB-to-SPI_Master
ID_MODEL_ENC=MCP2210\x20USB-to-SPI\x20Master
ID_MODEL_ID=00de
ID_REVISION=0002
ID_SERIAL=Microchip_Technology_Inc._MCP2210_USB-to-SPI_Master_0000267472
ID_SERIAL_SHORT=0000267472
ID_USB_INTERFACES=:030000:
ID_VENDOR=Microchip_Technology_Inc.
ID_VENDOR_ENC=Microchip\x20Technology\x20Inc.
ID_VENDOR_FROM_DATABASE=Microchip Technology, Inc.
ID_VENDOR_ID=04d8
MAJOR=189
MINOR=417
PRODUCT=4d8/de/2
SEQNUM=5985
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=183757852027

UDEV  [183758.396989] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0
DEVTYPE=usb_interface
DRIVER=usbhid
ID_VENDOR_FROM_DATABASE=Microchip Technology, Inc.
INTERFACE=3/0/0
MODALIAS=usb:v04D8p00DEd0002dc00dsc00dp00ic03isc00ip00in00
PRODUCT=4d8/de/2
SEQNUM=5986
SUBSYSTEM=usb
TYPE=0/0/0
USEC_INITIALIZED=183758396448

UDEV  [183758.398096] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0 (usbmisc)
ACTION=add
DEVNAME=/dev/usb/hiddev0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0
MAJOR=180
MINOR=0
SEQNUM=5989
SUBSYSTEM=usbmisc
USEC_INITIALIZED=183758397905

UDEV  [183758.398728] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F
HID_ID=0003:000004D8:000000DE
HID_NAME=Microchip Technology Inc. MCP2210 USB-to-SPI Master
HID_PHYS=usb-0000:00:1d.0-1.1/input0
HID_UNIQ=0000267472
MODALIAS=hid:b0003g0001v000004D8p000000DE
SEQNUM=5987
SUBSYSTEM=hid
USEC_INITIALIZED=183758398168

UDEV  [183758.399920] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0 (hidraw)
ACTION=add
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0
MAJOR=244
MINOR=0
SEQNUM=5990
SUBSYSTEM=hidraw
USEC_INITIALIZED=183758399726

KERNEL[183758.400685] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0 (usbmisc)
ACTION=remove
DEVNAME=/dev/usb/hiddev0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0
MAJOR=180
MINOR=0
SEQNUM=5991
SUBSYSTEM=usbmisc

KERNEL[183758.400766] remove   /usbmisc (class)
ACTION=remove
DEVPATH=/usbmisc
SEQNUM=5992
SUBSYSTEM=class

KERNEL[183758.400956] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0
MAJOR=244
MINOR=0
SEQNUM=5993
SUBSYSTEM=hidraw

KERNEL[183758.401068] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F
HID_ID=0003:000004D8:000000DE
HID_NAME=Microchip Technology Inc. MCP2210 USB-to-SPI Master
HID_PHYS=usb-0000:00:1d.0-1.1/input0
HID_UNIQ=0000267472
MODALIAS=hid:b0003g0001v000004D8p000000DE
SEQNUM=5994
SUBSYSTEM=hid

UDEV  [183758.403532] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0 (usbmisc)
ACTION=remove
DEVNAME=/dev/usb/hiddev0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0
MAJOR=180
MINOR=0
SEQNUM=5991
SUBSYSTEM=usbmisc
USEC_INITIALIZED=183758400806

UDEV  [183758.404020] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F/hidraw/hidraw0
MAJOR=244
MINOR=0
SEQNUM=5993
SUBSYSTEM=hidraw
USEC_INITIALIZED=183758402106

UDEV  [183758.404380] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.001F
HID_ID=0003:000004D8:000000DE
HID_NAME=Microchip Technology Inc. MCP2210 USB-to-SPI Master
HID_PHYS=usb-0000:00:1d.0-1.1/input0
HID_UNIQ=0000267472
MODALIAS=hid:b0003g0001v000004D8p000000DE
SEQNUM=5994
SUBSYSTEM=hid
USEC_INITIALIZED=183758402790

UDEV  [183758.405108] remove   /usbmisc (class)
ACTION=remove
DEVPATH=/usbmisc
SEQNUM=5992
SUBSYSTEM=class
USEC_INITIALIZED=183758401553

In the container, the ID fields are missing:

    monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[183877.777776] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1 (usb)
ACTION=add
BUSNUM=004
DEVNAME=/dev/bus/usb/004/035
DEVNUM=035
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1
DEVTYPE=usb_device
MAJOR=189
MINOR=418
PRODUCT=4d8/de/2
SEQNUM=5999
SUBSYSTEM=usb
TYPE=0/0/0

KERNEL[183877.778115] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0 (usb)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0
DEVTYPE=usb_interface
INTERFACE=3/0/0
MODALIAS=usb:v04D8p00DEd0002dc00dsc00dp00ic03isc00ip00in00
PRODUCT=4d8/de/2
SEQNUM=6000
SUBSYSTEM=usb
TYPE=0/0/0

KERNEL[183877.779627] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020 (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020
HID_ID=0003:000004D8:000000DE
HID_NAME=Microchip Technology Inc. MCP2210 USB-to-SPI Master
HID_PHYS=usb-0000:00:1d.0-1.1/input0
HID_UNIQ=0000267472
MODALIAS=hid:b0003g0001v000004D8p000000DE
SEQNUM=6001
SUBSYSTEM=hid

KERNEL[183877.780178] add      /class/usbmisc (class)
ACTION=add
DEVPATH=/class/usbmisc
SEQNUM=6002
SUBSYSTEM=class

KERNEL[183877.780314] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0 (usbmisc)
ACTION=add
DEVNAME=/dev/usb/hiddev0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0
MAJOR=180
MINOR=0
SEQNUM=6003
SUBSYSTEM=usbmisc

KERNEL[183877.780413] add      /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020/hidraw/hidraw0 (hidraw)
ACTION=add
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020/hidraw/hidraw0
MAJOR=244
MINOR=0
SEQNUM=6004
SUBSYSTEM=hidraw

KERNEL[183878.337362] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0 (usbmisc)
ACTION=remove
DEVNAME=/dev/usb/hiddev0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/usbmisc/hiddev0
MAJOR=180
MINOR=0
SEQNUM=6005
SUBSYSTEM=usbmisc

KERNEL[183878.337467] remove   /usbmisc (class)
ACTION=remove
DEVPATH=/usbmisc
SEQNUM=6006
SUBSYSTEM=class

KERNEL[183878.337521] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020/hidraw/hidraw0 (hidraw)
ACTION=remove
DEVNAME=/dev/hidraw0
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020/hidraw/hidraw0
MAJOR=244
MINOR=0
SEQNUM=6007
SUBSYSTEM=hidraw

KERNEL[183878.337584] remove   /devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020 (hid)
ACTION=remove
DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb4/4-1/4-1.1/4-1.1:1.0/0003:04D8:00DE.0020
HID_ID=0003:000004D8:000000DE
HID_NAME=Microchip Technology Inc. MCP2210 USB-to-SPI Master
HID_PHYS=usb-0000:00:1d.0-1.1/input0
HID_UNIQ=0000267472
MODALIAS=hid:b0003g0001v000004D8p000000DE
SEQNUM=6008
SUBSYSTEM=hid
like image 931
pallly Avatar asked Jan 19 '17 22:01

pallly


2 Answers

If you only care about getting information from the udev database, then you can mount the host's udev database into the docker container, e.g.,

-v /run/udev:/run/udev:ro

By doing so, you won't need to run a udev daemon inside the docker container, but still get all the ID_ attributes when doing udevadm info. This worked for me for a Debian docker container running on a Debian host.

I also suggest mounting /dev as well so your docker container will know about any changes to the device files.

like image 171
Edmundo Avatar answered Sep 19 '22 12:09

Edmundo


According to this this blog, udev just does not play well with docker when running in containers. I thus decided that this problem needs a workaround. With udev I only get the path of the device in /sys, and get the needed information directly from that path, e. g.:

container# cat "/sys$(udevadm info -q path /dev/bus/usb/002/009)/idVendor"

I am going to mark this as solved, however it's just a workaround, not the real answer to the question.

EDIT

According to this post, these flags are needed to get udevadm display the udev events (along with attributes): --net=host -v /dev:/dev

This only works for udevadm monitor, not for udevadm info.

like image 30
pallly Avatar answered Sep 19 '22 12:09

pallly