Linux command – udevadm monitor

Loading

測試環境為 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

monitor

這個參數可以立即監聽由 udev 規則發出的核心 uevent 和 events,並將 devpath 的 events 顯示在視窗,可以即時監聽核心的 uevent 和 udev event 發生的事件.

下面是執行 # udevadm monitor 後插入 USB Key 所顯示的訊息.

root@ubuntu:~# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[1993.444669] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2 (usb)
KERNEL[1993.459934] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0 (usb)
UDEV  [1993.670237] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2 (usb)
KERNEL[1993.861410] add      /module/usb_storage (module)
KERNEL[1993.895256] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33 (scsi)
KERNEL[1993.906748] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/scsi_host/host33 (scsi_host)
UDEV  [1993.916965] add      /module/usb_storage (module)
KERNEL[1993.917378] add      /bus/usb/drivers/usb-storage (drivers)
UDEV  [1993.925471] add      /bus/usb/drivers/usb-storage (drivers)
KERNEL[1993.930302] add      /module/uas (module)
KERNEL[1993.944289] add      /bus/usb/drivers/uas (drivers)
UDEV  [1993.945254] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0 (usb)
UDEV  [1993.962482] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33 (scsi)
UDEV  [1993.965989] add      /bus/usb/drivers/uas (drivers)
UDEV  [1993.972854] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/scsi_host/host33 (scsi_host)
UDEV  [1993.973766] add      /module/uas (module)
KERNEL[1994.946356] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0 (scsi)
KERNEL[1994.949953] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0 (scsi)
KERNEL[1994.950122] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_disk/33:0:0:0 (scsi_disk)
KERNEL[1994.951795] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_device/33:0:0:0 (scsi_device)
KERNEL[1994.963593] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_generic/sg3 (scsi_generic)
KERNEL[1994.963774] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/bsg/33:0:0:0 (bsg)
KERNEL[1994.979028] add      /devices/virtual/bdi/8:32 (bdi)
UDEV  [1994.988436] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0 (scsi)
UDEV  [1995.024327] add      /devices/virtual/bdi/8:32 (bdi)
KERNEL[1995.029708] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc (block)
KERNEL[1995.029756] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc/sdc1 (block)
UDEV  [1995.030945] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0 (scsi)
UDEV  [1995.045627] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_disk/33:0:0:0 (scsi_disk)
UDEV  [1995.056509] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_device/33:0:0:0 (scsi_device)
UDEV  [1995.102938] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_generic/sg3 (scsi_generic)
UDEV  [1995.105700] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/bsg/33:0:0:0 (bsg)
UDEV  [1995.672638] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc (block)
UDEV  [1995.875137] add      /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc/sdc1 (block)

移除 USB Key 時顯示的訊息.

KERNEL[3100.499346] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/bsg/33:0:0:0 (bsg)
KERNEL[3100.537291] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_generic/sg3 (scsi_generic)
KERNEL[3100.537314] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_device/33:0:0:0 (scsi_device)
KERNEL[3100.537325] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_disk/33:0:0:0 (scsi_disk)
KERNEL[3100.537342] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc/sdc1 (block)
KERNEL[3100.552077] remove   /devices/virtual/bdi/8:32 (bdi)
KERNEL[3100.552655] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc (block)
KERNEL[3100.553124] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0 (scsi)
KERNEL[3100.577856] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0 (scsi)
KERNEL[3100.596865] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/scsi_host/host33 (scsi_host)
KERNEL[3100.597342] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33 (scsi)
KERNEL[3100.597791] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0 (usb)
KERNEL[3100.598743] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2 (usb)
UDEV  [3100.729085] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_disk/33:0:0:0 (scsi_disk)
UDEV  [3100.744438] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_device/33:0:0:0 (scsi_device)
UDEV  [3100.747467] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/bsg/33:0:0:0 (bsg)
UDEV  [3100.748071] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/scsi_generic/sg3 (scsi_generic)
UDEV  [3100.751066] remove   /devices/virtual/bdi/8:32 (bdi)
UDEV  [3100.752116] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/scsi_host/host33 (scsi_host)
UDEV  [3100.764768] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc/sdc1 (block)
UDEV  [3100.810823] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0/block/sdc (block)
UDEV  [3100.813356] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0/33:0:0:0 (scsi)
UDEV  [3100.822044] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33/target33:0:0 (scsi)
UDEV  [3100.822687] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0/host33 (scsi)
UDEV  [3100.826347] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2/1-2:1.0 (usb)
UDEV  [3100.837934] remove   /devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-2 (usb)

如果覺得監聽的時候太多訊息,可以使用參數只監聽部分的訊息.

  • -k, –kernel
    Print the kernel uevents.
  • -u, –udev
    Print the udev event after the rule processing.
  • -p, –property
    Also print the properties of the event.
  • -s, –subsystem-match=string/[string]
    Filter events by subsystem[/devtype]. Only udev events with a matching subsystem value will pass.
  • -t, –tag-match=string
    Filter events by property. Only udev events with a given tag attached will pass.
沒有解決問題,試試搜尋本站其他內容

One thought on “Linux command – udevadm monitor

  1. 自動引用通知: Linux – udev | Benjr.tw

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料