Udev: различия между версиями
Материал из noname.com.ua
Перейти к навигацииПерейти к поискуSirmax (обсуждение | вклад) |
Sirmax (обсуждение | вклад) |
||
Строка 11: | Строка 11: | ||
==Автомониирование== |
==Автомониирование== |
||
Подключаю устройство (в моем случае это телефон, флешка в котором видиться как диск) |
Подключаю устройство (в моем случае это телефон, флешка в котором видиться как диск) |
||
+ | ===Как определилось устройство?=== |
||
<PRE> |
<PRE> |
||
13:35:03-root@sirmax:~#dmesg | tail |
13:35:03-root@sirmax:~#dmesg | tail |
||
Строка 24: | Строка 25: | ||
[6050777.508231] sd 21:0:0:0: [sdf] Attached SCSI removable disk |
[6050777.508231] sd 21:0:0:0: [sdf] Attached SCSI removable disk |
||
</PRE> |
</PRE> |
||
− | Определить всю информацию о устройстве |
+ | ===Определить всю информацию о устройстве=== |
+ | Определить всю информацию о устройстве |
||
<PRE> |
<PRE> |
||
13:32:56-root@sirmax:~#udevadm info -a --name=sdf |
13:32:56-root@sirmax:~#udevadm info -a --name=sdf |
Версия 14:07, 5 марта 2011
udev
Использование подсистемы udev в Gentoo
Захотелось сделать как обычно - автомонтирование фотоаппарата. телефона и флешек, причем в разные mount point. Второе - пробрасывать определенные устройства внутрь виртуальных машин.
Общие правила
- Udev считывает файлы из /etc/udev/rules.d в алфавитном порядке.
- Найдя первое подходящее правило для устройства, udev прекращает дальнейший поиск.
Автомониирование
Подключаю устройство (в моем случае это телефон, флешка в котором видиться как диск)
Как определилось устройство?
13:35:03-root@sirmax:~#dmesg | tail [6050777.245910] scsi 21:0:0:0: Direct-Access PQ: 0 ANSI: 0 [6050777.246123] sd 21:0:0:0: Attached scsi generic sg6 type 0 [6050777.395654] sd 21:0:0:0: [sdf] 15572992 512-byte logical blocks: (7.97 GB/7.42 GiB) [6050777.445663] sd 21:0:0:0: [sdf] Write Protect is off [6050777.445669] sd 21:0:0:0: [sdf] Mode Sense: 00 06 00 00 [6050777.445672] sd 21:0:0:0: [sdf] Assuming drive cache: write through [6050777.493599] sd 21:0:0:0: [sdf] Assuming drive cache: write through [6050777.498359] sdf: sdf1 [6050777.508225] sd 21:0:0:0: [sdf] Assuming drive cache: write through [6050777.508231] sd 21:0:0:0: [sdf] Attached SCSI removable disk
Определить всю информацию о устройстве
Определить всю информацию о устройстве
13:32:56-root@sirmax:~#udevadm info -a --name=sdf 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:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host21/target21:0:0/21:0:0:0/block/sdf': KERNEL=="sdf" SUBSYSTEM=="block" DRIVER=="" ATTR{range}=="16" ATTR{ext_range}=="256" ATTR{removable}=="1" ATTR{ro}=="0" ATTR{size}=="15572992" ATTR{alignment_offset}=="0" ATTR{discard_alignment}=="0" ATTR{capability}=="51" ATTR{stat}==" 64 26 720 356 0 0 0 0 0 356 356" ATTR{inflight}==" 0 0" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host21/target21:0:0/21:0:0:0': KERNELS=="21:0:0:0" SUBSYSTEMS=="scsi" DRIVERS=="sd" ATTRS{device_blocked}=="0" ATTRS{type}=="0" ATTRS{scsi_level}=="0" ATTRS{vendor}==" " ATTRS{model}==" " ATTRS{rev}==" " ATTRS{state}=="running" ATTRS{timeout}=="30" ATTRS{iocounterbits}=="32" ATTRS{iorequest_cnt}=="0x20fc" ATTRS{iodone_cnt}=="0x20fc" ATTRS{ioerr_cnt}=="0x0" ATTRS{modalias}=="scsi:t-0x00" ATTRS{evt_media_change}=="0" ATTRS{queue_depth}=="1" ATTRS{queue_type}=="none" ATTRS{max_sectors}=="240" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host21/target21:0:0': KERNELS=="target21:0:0" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host21': KERNELS=="host21" SUBSYSTEMS=="scsi" DRIVERS=="" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0': KERNELS=="2-3.2:1.0" SUBSYSTEMS=="usb" DRIVERS=="usb-storage" ATTRS{bInterfaceNumber}=="00" ATTRS{bAlternateSetting}==" 0" ATTRS{bNumEndpoints}=="02" ATTRS{bInterfaceClass}=="08" ATTRS{bInterfaceSubClass}=="06" ATTRS{bInterfaceProtocol}=="50" ATTRS{modalias}=="usb:v0BB4p0C15d0000dc00dsc00dp00ic08isc06ip50" ATTRS{supports_autosuspend}=="1" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2': KERNELS=="2-3.2" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="c0" ATTRS{bMaxPower}=="500mA" ATTRS{urbnum}=="16998" ATTRS{idVendor}=="0bb4" ATTRS{idProduct}=="0c15" ATTRS{bcdDevice}=="0000" ATTRS{bDeviceClass}=="00" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="2" ATTRS{devnum}=="22" ATTRS{devpath}=="3.2" ATTRS{version}==" 2.00" ATTRS{maxchild}=="0" ATTRS{quirks}=="0x0" ATTRS{avoid_reset_quirk}=="0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="HTC" ATTRS{product}=="Storage" ATTRS{serial}=="3fbf5000-7351-0801-3583-530114835680" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2/2-3': KERNELS=="2-3" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="e0" ATTRS{bMaxPower}=="100mA" ATTRS{urbnum}=="480" ATTRS{idVendor}=="05e3" ATTRS{idProduct}=="0605" ATTRS{bcdDevice}=="060b" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="01" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="2" ATTRS{devnum}=="2" ATTRS{devpath}=="3" ATTRS{version}==" 2.00" ATTRS{maxchild}=="4" ATTRS{quirks}=="0x0" ATTRS{avoid_reset_quirk}=="0" ATTRS{authorized}=="1" ATTRS{product}=="USB2.0 Hub" looking at parent device '/devices/pci0000:00/0000:00:0b.1/usb2': KERNELS=="usb2" SUBSYSTEMS=="usb" DRIVERS=="usb" ATTRS{configuration}=="" ATTRS{bNumInterfaces}==" 1" ATTRS{bConfigurationValue}=="1" ATTRS{bmAttributes}=="e0" ATTRS{bMaxPower}==" 0mA" ATTRS{urbnum}=="36" ATTRS{idVendor}=="1d6b" ATTRS{idProduct}=="0002" ATTRS{bcdDevice}=="0206" ATTRS{bDeviceClass}=="09" ATTRS{bDeviceSubClass}=="00" ATTRS{bDeviceProtocol}=="00" ATTRS{bNumConfigurations}=="1" ATTRS{bMaxPacketSize0}=="64" ATTRS{speed}=="480" ATTRS{busnum}=="2" ATTRS{devnum}=="1" ATTRS{devpath}=="0" ATTRS{version}==" 2.00" ATTRS{maxchild}=="8" ATTRS{quirks}=="0x0" ATTRS{avoid_reset_quirk}=="0" ATTRS{authorized}=="1" ATTRS{manufacturer}=="Linux 2.6.37-rc6-sirmax1 ehci_hcd" ATTRS{product}=="EHCI Host Controller" ATTRS{serial}=="0000:00:0b.1" ATTRS{authorized_default}=="1" looking at parent device '/devices/pci0000:00/0000:00:0b.1': KERNELS=="0000:00:0b.1" SUBSYSTEMS=="pci" DRIVERS=="ehci_hcd" ATTRS{vendor}=="0x10de" ATTRS{device}=="0x026e" ATTRS{subsystem_vendor}=="0x1458" ATTRS{subsystem_device}=="0x5004" ATTRS{class}=="0x0c0320" ATTRS{irq}=="23" ATTRS{local_cpus}=="f" ATTRS{local_cpulist}=="0-3" ATTRS{modalias}=="pci:v000010DEd0000026Esv00001458sd00005004bc0Csc03i20" ATTRS{dma_mask_bits}=="32" ATTRS{consistent_dma_mask_bits}=="32" ATTRS{enable}=="1" ATTRS{broken_parity_status}=="0" ATTRS{msi_bus}=="" ATTRS{companion}=="" looking at parent device '/devices/pci0000:00': KERNELS=="pci0000:00" SUBSYSTEMS=="" DRIVERS==""
При подключении
13:58:38-root@sirmax:/etc/udev#cat /var/log/messages | grep udev-flash-mount.sh Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_USB_DRIVER=usb-storage Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_MODEL=Storage Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_MODEL_ENC=Storage Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_REVISION=0000 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVTYPE=disk Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_TABLE=1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_BUS=usb Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: SUBSYSTEM=block Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_SERIAL=HTC_Storage_3fbf5000-7351-0801-3583-530114835680-0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVPATH=/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host26/target26:0:0/26:0:0:0/block/sdf Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_MODEL_ID=0c15 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_VENDOR_ENC=HTC Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_TABLE_SCHEME=mbr Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: MINOR=80 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ACTION=add Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_TABLE_COUNT=1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: PWD=/ Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDEV_LOG=3 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: MAJOR=8 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVLINKS=/dev/block/8:80 /dev/disk/by-id/usb-HTC_Storage_3fbf5000-7351-0801-3583-530114835680-0:0 /dev/disk/by-path/pci-0000:00:0b.1-usb-0:3.2:1.0-scsi-0:0:0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_VENDOR_ID=0bb4 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVNAME=/dev/sdf Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: SHLVL=1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_TYPE=disk Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_PART_TABLE_TYPE=dos Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PRESENTATION_NOPOLICY=0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_INSTANCE=0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_VENDOR=HTC Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_USB_INTERFACE_NUM=00 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_SERIAL_SHORT=3fbf5000-7351-0801-3583-530114835680 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_PATH=pci-0000:00:0b.1-usb-0:3.2:1.0-scsi-0:0:0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_USB_INTERFACES=:080650: Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: SEQNUM=1823 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: _=/usr/bin/env Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: add sdf Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_USB_DRIVER=usb-storage Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_MODEL=Storage Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_MODEL_ENC=Storage Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_REVISION=0000 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVTYPE=partition Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_LABEL=MOBILE Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_BUS=usb Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_LABEL_ENC=MOBILE Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: SUBSYSTEM=block Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_SERIAL=HTC_Storage_3fbf5000-7351-0801-3583-530114835680-0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_UUID=A08C-E85D Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_OFFSET=4194304 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVPATH=/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host26/target26:0:0/26:0:0:0/block/sdf/sdf1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_MODEL_ID=0c15 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_VENDOR_ENC=HTC Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_NUMBER=1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_VERSION=FAT32 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: MINOR=81 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ACTION=add Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: PWD=/ Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDEV_LOG=3 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_ALIGNMENT_OFFSET=0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_TYPE=vfat Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: MAJOR=8 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVLINKS=/dev/block/8:81 /dev/disk/by-id/usb-HTC_Storage_3fbf5000-7351-0801-3583-530114835680-0:0-part1 /dev/disk/by-path/pci-0000:00:0b.1-usb-0:3.2:1.0-scsi-0:0:0:0-part1 /dev/disk/by-uuid/A08C-E85D /dev/disk/by-label/MOBILE Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_VENDOR_ID=0bb4 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: DEVNAME=/dev/sdf1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: SHLVL=1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_USAGE=filesystem Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_TYPE=disk Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_PART_TABLE_TYPE=dos Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PRESENTATION_NOPOLICY=0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_SIZE=7969177600 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_FS_UUID_ENC=A08C-E85D Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_SCHEME=mbr Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_TYPE=0x0b Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION=1 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_INSTANCE=0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_VENDOR=HTC Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_USB_INTERFACE_NUM=00 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_SERIAL_SHORT=3fbf5000-7351-0801-3583-530114835680 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: UDISKS_PARTITION_SLAVE=/sys/devices/pci0000:00/0000:00:0b.1/usb2/2-3/2-3.2/2-3.2:1.0/host26/target26:0:0/26:0:0:0/block/sdf Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_PATH=pci-0000:00:0b.1-usb-0:3.2:1.0-scsi-0:0:0:0 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: ID_USB_INTERFACES=:080650: Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: SEQNUM=1824 Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: _=/usr/bin/env Mar 5 13:58:28 sirmax [udev-flash-mount.sh]: add sdf1