測試環境為 Ubuntu16.04 x86_64
在使用 udevadm (以前會透過 #udevinfo) 之前先來了解一下什麼是 sysfs 與 udev?
核心 2.6 後的新檔案系統 sysfs,裝置名稱還是存放在 /dev/ 目錄下但是多了一個 /sys/ 的目錄 (該目錄是可瀏覽的),裡面存放當前硬體相對應的基本資訊.udev 則是透過 /sys/ 目錄的資訊創建出相對應的硬體設備節點 /dev/.
udev 則是管理目錄 /dev 的新方法,傳統的方式需要在 /dev/ 預先產生可能用不到的裝置名稱,udev 主要是依賴於 sysfs 提供的資訊與用戶提供的規則(Rule) 來創建相對應於系統中存在的 /dev 設備節點名稱.
更多關於 sysfs 與 udev 請參考 https://benjr.tw/10632
但直接看這些檔案很累人,這些詳細的資訊都可以透過指令 #udevadm 來查詢.
直接來看看 #udevadm 的參數說明.
udevadm - udev management tool SYNOPSIS udevadm [--debug] [--version] [--help] udevadm info options udevadm trigger [options] udevadm settle [options] udevadm control command udevadm monitor [options] udevadm test [options] devpath udevadm test-builtin [options] command devpath
Info
udevadm info options 常用的參數
- -q, –query=TYPE
使用 all 可以查詢全部的資訊,可用的參數有 name(N), symlink(S), path(P), property(E) 他們也分別代表第一個字元的分類. - -n, –name=FILE
可以直接指令裝置名稱 sda ,同指定裝置路徑 /dev/sda 的方式.
root@ubuntu:~# udevadm info --query=all --name=sda P: /devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda N: sda S: disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0 E: DEVLINKS=/dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0 E: DEVNAME=/dev/sda E: DEVPATH=/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda E: DEVTYPE=disk E: ID_BUS=scsi E: ID_MODEL=VMware_Virtual_S E: ID_MODEL_ENC=VMware\x20Virtual\x20S E: ID_PART_TABLE_TYPE=dos E: ID_PART_TABLE_UUID=ddcb3e72 E: ID_PATH=pci-0000:00:10.0-scsi-0:0:0:0 E: ID_PATH_TAG=pci-0000_00_10_0-scsi-0_0_0_0 E: ID_REVISION=1.0 E: ID_SCSI=1 E: ID_TYPE=disk E: ID_VENDOR=VMware_ E: ID_VENDOR_ENC=VMware\x2c\x20 E: MAJOR=8 E: MINOR=0 E: SUBSYSTEM=block E: TAGS=:systemd: E: USEC_INITIALIZED=3928528
第一個字元分別代表不同的分類 name(N), symlink(S), path(P), property(E) 他們也可以當作參數來使用.
name(N)
root@ubuntu:~# udevadm info --query=name --name=/dev/sda sda
symlink(S)
root@ubuntu:~# udevadm info --query=symlink --name=/dev/sda disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0
path(P)
root@ubuntu:~# udevadm info --query=path --name=/dev/sda /devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda
property(E)
root@ubuntu:~# udevadm info --query=property --name=/dev/sda DEVLINKS=/dev/disk/by-path/pci-0000:00:10.0-scsi-0:0:0:0 DEVNAME=/dev/sda DEVPATH=/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda DEVTYPE=disk ID_BUS=scsi ID_MODEL=VMware_Virtual_S ID_MODEL_ENC=VMware\x20Virtual\x20S ID_PART_TABLE_TYPE=dos ID_PART_TABLE_UUID=ddcb3e72 ID_PATH=pci-0000:00:10.0-scsi-0:0:0:0 ID_PATH_TAG=pci-0000_00_10_0-scsi-0_0_0_0 ID_REVISION=1.0 ID_SCSI=1 ID_TYPE=disk ID_VENDOR=VMware_ ID_VENDOR_ENC=VMware\x2c\x20 MAJOR=8 MINOR=0 SUBSYSTEM=block TAGS=:systemd: USEC_INITIALIZED=3928528
想要更詳細的資訊可以使用下面參數
- -a, –attribute-walk
會列出指定設備所有 udev 規則中使用的 sysfs properties (屬性),並會沿著上一層並顯示這一連串的所有設備屬性,直到該裝置的 udev 根目錄.
root@ubuntu:~# udevadm info --attribute-walk --name=sda Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device. looking at device '/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0/block/sda': KERNEL=="sda" SUBSYSTEM=="block" DRIVER=="" ATTR{alignment_offset}=="0" ATTR{capability}=="50" ATTR{discard_alignment}=="0" ATTR{events}=="" ATTR{events_async}=="" ATTR{events_poll_msecs}=="-1" ATTR{ext_range}=="256" ATTR{inflight}==" 0 0" ATTR{range}=="16" ATTR{removable}=="0" ATTR{ro}=="0" ATTR{size}=="41943040" ATTR{stat}==" 34786 89 1893242 28296 28842 44016 2580144 28620 0 19768 56392" looking at parent device '/devices/pci0000:00/0000:00:10.0/host2/target2:0:0/2:0:0:0': KERNELS=="2:0:0:0" SUBSYSTEMS=="scsi" DRIVERS=="sd" ATTRS{device_blocked}=="0" ATTRS{device_busy}=="0" ATTRS{dh_state}=="detached" ATTRS{eh_timeout}=="10" ATTRS{evt_capacity_change_reported}=="0" ATTRS{evt_inquiry_change_reported}=="0" ATTRS{evt_lun_change_reported}=="0" ATTRS{evt_media_change}=="0" ATTRS{evt_mode_parameter_change_reported}=="0" ATTRS{evt_soft_threshold_reached}=="0" ATTRS{inquiry}=="" ATTRS{iocounterbits}=="32" ATTRS{iodone_cnt}=="0xfcb8" ATTRS{ioerr_cnt}=="0x6" ATTRS{iorequest_cnt}=="0xfcb8" ATTRS{model}=="VMware Virtual S" ATTRS{queue_depth}=="32" ATTRS{queue_ramp_up_period}=="120000" ATTRS{queue_type}=="simple" ATTRS{rev}=="1.0 " ATTRS{scsi_level}=="3" ATTRS{state}=="running" ATTRS{timeout}=="30" ATTRS{type}=="0" ATTRS{vendor}=="VMware, " looking at parent device '/devices/pci0000:00/0000:00:10.0/host2/target2:0:0': KERNELS=="target2:0:0" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:10.0/host2': KERNELS=="host2" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:10.0': KERNELS=="0000:00:10.0" SUBSYSTEMS=="pci" DRIVERS=="mptspi" ATTRS{broken_parity_status}=="0" ATTRS{class}=="0x010000" ATTRS{config}=="" ATTRS{consistent_dma_mask_bits}=="32" ATTRS{d3cold_allowed}=="0" ATTRS{device}=="0x0030" ATTRS{dma_mask_bits}=="32" ATTRS{driver_override}=="(null)" ATTRS{enable}=="1" ATTRS{irq}=="17" ATTRS{local_cpulist}=="0" ATTRS{local_cpus}=="00000000,00000000,00000000,00000001" ATTRS{msi_bus}=="1" ATTRS{numa_node}=="-1" ATTRS{subsystem_device}=="0x1976" ATTRS{subsystem_vendor}=="0x15ad" ATTRS{vendor}=="0x1000" looking at parent device '/devices/pci0000:00': KERNELS=="pci0000:00" SUBSYSTEMS=="" DRIVERS==""
沒有解決問題,試試搜尋本站其他內容
One thought on “Linux command – udevadm info”