Udev
Материал из noname.com.ua
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==""