gpt4 book ai didi

docker - udevadm不会在docker容器中显示所有属性

转载 作者:行者123 更新时间:2023-12-04 17:16:23 31 4
gpt4 key购买 nike

当我运行docker容器并在容器中使用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

我还尝试从主机/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日志设置为调试,并使用 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

最佳答案

如果您只想从udev数据库中获取信息,则可以将主机的udev数据库挂载到docker容器中,例如,

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

这样,您无需在docker容器内运行udev守护程序,但在执行 ID_时仍会获得所有 udevadm info属性。对于在Debian主机上运行的Debian docker容器,这为我工作。

我还建议您也挂载 /dev,以便您的Docker容器将知道设备文件的任何更改。

关于docker - udevadm不会在docker容器中显示所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41753218/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com