当我在容器内运行docker container并列出某个设备的udevadm
属性时,只有该设备的基本信息。当我在主机上做同样的事情时,我可以看到更多。如何获取容器内的所有信息?
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
我还尝试从host:/ sys,/ dev挂载其他卷。没有帮助。
编辑根据Alex P.的回答:
我对udev不是很有经验。我复制了这个
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id", IMPORT{builtin}="hwdb --subsystem=usb"
到/dev/udev/rules.d/10-local.rules,我已将udev日志记录设置为debug,使用udevadm control --reload
重新加载配置。现在我明白了:
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
现在仍然没有运气。 我试图用--privileged标志运行容器,没有帮助。我在/etc/udev/rules.d中没有其他规则。我试图从我的主人那里复制所有规则,没有运气。
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
在容器中,缺少ID字段:
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
答案 0 :(得分:7)
如果您只关心从udev数据库获取信息,那么您可以将主机的udev数据库安装到docker容器中,例如,
-v /run/udev:/run/udev:ro
通过这样做,您不需要在docker容器中运行udev守护程序,但在执行ID_
时仍然会获得所有udevadm info
属性。这对我来说是在Debian主机上运行的Debian docker容器。
我还建议安装/dev
,这样您的docker容器就会知道设备文件的任何更改。
答案 1 :(得分:1)
根据这个this博客,在容器中运行时,udev在docker中效果不佳。因此我决定这个问题需要解决方法。使用udev我只能在/ sys中获取设备的路径,并直接从该路径获取所需信息,例如: G:
container# cat "/sys$(udevadm info -q path /dev/bus/usb/002/009)/idVendor"
我打算将此标记为已解决,但这只是一种解决方法,而不是问题的真正答案。
修改强>
根据this post,需要这些标志才能让udevadm显示udev事件(以及属性): - net = host -v / dev:/ dev
这仅适用于udevadm monitor
,不适用于udevadm info
。
答案 2 :(得分:0)
添加以下udev
规则以填充ID_
属性:
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", IMPORT{builtin}="usb_id", IMPORT{builtin}="hwdb --subsystem=usb"