udev
USB 장치 이름을 지정하는 규칙을 만들려고 합니다 .샌디스크_Cruzer_16GB". %s{file}
대체 지정자를 어떻게 사용합니까 SYMLINK
?
KERNEL=="sd[a-z]", SUBSYSTEM=="block", ATTR{ro}=="0", ATTR{removable}=="1", SUBSYSTEMS=="usb", DRIVERS=="usb-storage", SYMLINK+="usb%s{vendor}"
나는 여기에 /sys/block/sdc/device/model
필요한 데이터 중 일부가 포함되어 있음을 발견했습니다.
출력 udevadm info -a /dev/sdc|less
:
looking at device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host19/target19:0:0/19:0:0:0/block/
sdc':
KERNEL=="sdc"
SUBSYSTEM=="block"
DRIVER==""
ATTR{ro}=="0"
ATTR{size}=="30277632"
ATTR{stat}==" 112 110 1776 80 0 0 0 0 0 72
80"
ATTR{range}=="16"
ATTR{discard_alignment}=="0"
ATTR{events}=="media_change"
ATTR{ext_range}=="256"
ATTR{events_poll_msecs}=="2000"
ATTR{alignment_offset}=="0"
ATTR{inflight}==" 0 0"
ATTR{removable}=="1"
ATTR{capability}=="51"
ATTR{events_async}==""
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host19/target19:0:0/19:0:0:0
':
KERNELS=="19:0:0:0"
SUBSYSTEMS=="scsi"
DRIVERS=="sd"
ATTRS{rev}=="PMAP"
ATTRS{type}=="0"
ATTRS{scsi_level}=="7"
ATTRS{model}=="Cruzer "
ATTRS{state}=="running"
ATTRS{queue_type}=="none"
ATTRS{iodone_cnt}=="0x16e"
ATTRS{iorequest_cnt}=="0x16e"
ATTRS{device_busy}=="0"
ATTRS{evt_capacity_change_reported}=="0"
ATTRS{timeout}=="30"
ATTRS{evt_media_change}=="0"
ATTRS{max_sectors}=="240"
ATTRS{ioerr_cnt}=="0x1"
ATTRS{queue_depth}=="1"
ATTRS{vendor}=="SanDisk "
ATTRS{evt_soft_threshold_reached}=="0"
ATTRS{device_blocked}=="0"
ATTRS{evt_mode_parameter_change_reported}=="0"
ATTRS{evt_lun_change_reported}=="0"
ATTRS{evt_inquiry_change_reported}=="0"
ATTRS{iocounterbits}=="32"
ATTRS{eh_timeout}=="10"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host19/target19:0:0':
KERNELS=="target19:0:0"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host19':
KERNELS=="host19"
SUBSYSTEMS=="scsi"
DRIVERS==""
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0':
KERNELS=="4-3:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
ATTRS{bInterfaceClass}=="08"
ATTRS{bInterfaceSubClass}=="06"
ATTRS{bInterfaceProtocol}=="50"
ATTRS{bNumEndpoints}=="02"
ATTRS{supports_autosuspend}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceNumber}=="00"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3':
KERNELS=="4-3"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{devpath}=="3"
ATTRS{idVendor}=="0781"
ATTRS{speed}=="480"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{busnum}=="4"
ATTRS{devnum}=="22"
ATTRS{configuration}==""
ATTRS{bMaxPower}=="300mA"
ATTRS{authorized}=="1"
ATTRS{bmAttributes}=="80"
ATTRS{bNumConfigurations}=="1"
ATTRS{maxchild}=="0"
ATTRS{bcdDevice}=="0100"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{quirks}=="0x0"
ATTRS{serial}=="FC0051E21A43B867"
ATTRS{version}==" 2.00"
ATTRS{urbnum}=="882"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="SanDisk"
ATTRS{removable}=="unknown"
ATTRS{idProduct}=="5575"
ATTRS{bDeviceClass}=="00"
ATTRS{product}=="Cruzer"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4':
KERNELS=="usb4"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{devpath}=="0"
ATTRS{idVendor}=="1d6b"
ATTRS{speed}=="480"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{authorized_default}=="1"
ATTRS{busnum}=="4"
ATTRS{devnum}=="1"
ATTRS{configuration}==""
ATTRS{bMaxPower}=="0mA"
ATTRS{authorized}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bNumConfigurations}=="1"
ATTRS{maxchild}=="6"
ATTRS{bcdDevice}=="0316"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{quirks}=="0x0"
ATTRS{serial}=="0000:00:1d.7"
ATTRS{version}==" 2.00"
ATTRS{urbnum}=="573"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 3.16.0-4-amd64 ehci_hcd"
ATTRS{removable}=="unknown"
ATTRS{idProduct}=="0002"
ATTRS{bDeviceClass}=="09"
ATTRS{product}=="EHCI Host Controller"
looking at parent device '/devices/pci0000:00/0000:00:1d.7':
KERNELS=="0000:00:1d.7"
SUBSYSTEMS=="pci"
DRIVERS=="ehci-pci"
ATTRS{irq}=="20"
ATTRS{subsystem_vendor}=="0x1028"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0320"
ATTRS{companion}==""
ATTRS{driver_override}=="(null)"
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{dma_mask_bits}=="32"
ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000003"
ATTRS{device}=="0x293a"
ATTRS{uframe_periodic_max}=="100"
ATTRS{enable}=="1"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0-1"
ATTRS{vendor}=="0x8086"
ATTRS{subsystem_device}=="0x02aa"
ATTRS{numa_node}=="-1"
ATTRS{d3cold_allowed}=="1"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
출력 udevadm info /dev/sdc
:
P: /devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host19/target19:0:0/19:0:0:0/block/sdc
N: sdc
S: disk/by-id/usb-SanDisk_Cruzer_FC0051E21A43B867-0:0
S: disk/by-path/pci-0000:00:1d.7-usb-0:3:1.0-scsi-0:0:0:0
S: usbSandisk
E: DEVLINKS=/dev/disk/by-id/usb-SanDisk_Cruzer_FC0051E21A43B867-0:0 /dev/disk/by-path/pci-0000:00:1d.7-usb-0:3:1.0-scsi-0:0:0:0 /dev/usbSandisk
E: DEVNAME=/dev/sdc
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0/host19/target19:0:0/19:0:0:0/block/sdc
E: DEVTYPE=disk
E: ID_BUS=usb
E: ID_DRIVE_THUMB=1
E: ID_INSTANCE=0:0
E: ID_MODEL=Cruzer
E: ID_MODEL_ENC=Cruzer\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
E: ID_MODEL_ID=5575
E: ID_PART_TABLE_TYPE=dos
E: ID_PART_TABLE_UUID=000610ac
E: ID_PATH=pci-0000:00:1d.7-usb-0:3:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=pci-0000_00_1d_7-usb-0_3_1_0-scsi-0_0_0_0
E: ID_REVISION=PMAP
E: ID_SERIAL=SanDisk_Cruzer_FC0051E21A43B867-0:0
E: ID_SERIAL_SHORT=FC0051E21A43B867
E: ID_TYPE=disk
E: ID_USB_DRIVER=usb-storage
E: ID_USB_INTERFACES=:080650:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=SanDisk
E: ID_VENDOR_ENC=SanDisk\x20
E: ID_VENDOR_ID=0781
E: MAJOR=8
E: MINOR=32
E: SUBSYSTEM=block
E: TAGS=:systemd:
E: USEC_INITIALIZED=89765815
답변1
이 페이지를 읽으신다면 man
(강조하세요):
$attr{파일}, %s{파일} 규칙에 대한 모든 키가 있는 장치에서 발견된 sysfs 속성 값 일치합니다. 일치하는 장치에 그러한 속성이 없는 경우 이전 커널, 하위 시스템, 드라이버 또는 속성테스트에서 부모를 선택합니다. 장치를 선택한 다음 해당 상위 장치의 속성을 사용하십시오..
일치하는 장치에는 속성이 없으며 vendor
특정 상위 장치와 일치하는 규칙의 속성을 사용합니다.SUBSYSTEMS=="usb", DRIVERS=="usb-storage"
looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb4/4-3/4-3:1.0':
KERNELS=="4-3:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usb-storage"
ATTRS{bInterfaceClass}=="08"
ATTRS{bInterfaceSubClass}=="06"
ATTRS{bInterfaceProtocol}=="50"
ATTRS{bNumEndpoints}=="02"
ATTRS{supports_autosuspend}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceNumber}=="00"
보시 vendor
다시피 상위 장치에도 속성이 없습니다.
해결책은 다음과 같은 환경 변수를 사용하는 것입니다.
KERNEL=="sd[a-z]", SUBSYSTEM=="block", ATTR{ro}=="0", ATTR{removable}=="1", \
SUBSYSTEMS=="usb", DRIVERS=="usb-storage", SYMLINK+="usb_%E{ID_VENDOR}_%E{ID_MODEL}"
그러면 이라는 심볼릭 링크가 생성됩니다 usb_Sandisk_Cruzer
. 여러 장치가 동일하다는 점에 유의하세요.id_supplier그리고모델이 링크는 마지막으로 연결된 링크를 가리킵니다. 이를 방지하려면 ID_SERIAL_SHORT
예를 들어 다음을 추가할 수 있습니다.SYMLINK+="usb_%E{ID_VENDOR}_%E{ID_MODEL}_%E{ID_SERIAL_SHORT}"