/ Dev dizinindeki aygıt adlarını değiştirmenin bir yolu var mı?


13

Bu kuralı test amacıyla yazdım:

SUBSYSTEMS=="usb", ATTRS{manufacturer}=="Kingston", ATTRS{serial}=="001CC0EC34A2BB318709004B", ATTRS{idVendor}=="0951", ATTRS{idProduct}=="1642", SYMLINK+="pen", NAME="pendrak"

aşağıdaki bilgilere dayanarak:

# udevadm info --name=/dev/sdb --attribute-walk

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:1d.7/usb2/2-5/2-5:1.0/host2/target2:0:0/2:0:0:0/block/sdb':
    KERNEL=="sdb"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{ro}=="0"
    ATTR{size}=="30299520"
    ATTR{stat}=="     419        0     3352     1208        0        0        0        0        0     1120     1208"
    ATTR{range}=="16"
    ATTR{discard_alignment}=="0"
    ATTR{events}=="media_change"
    ATTR{ext_range}=="256"
    ATTR{events_poll_msecs}=="3000"
    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/usb2/2-5/2-5:1.0/host2/target2:0:0/2:0:0:0':
    KERNELS=="2:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{rev}=="PMAP"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="0"
    ATTRS{model}=="DT 101 G2       "
    ATTRS{state}=="running"
    ATTRS{queue_type}=="none"
    ATTRS{iodone_cnt}=="0x2da"
    ATTRS{iorequest_cnt}=="0x2da"
    ATTRS{evt_capacity_change_reported}=="0"
    ATTRS{timeout}=="30"
    ATTRS{evt_media_change}=="0"
    ATTRS{max_sectors}=="240"
    ATTRS{ioerr_cnt}=="0x2"
    ATTRS{queue_depth}=="1"
    ATTRS{vendor}=="Kingston"
    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/usb2/2-5/2-5:1.0/host2/target2:0:0':
    KERNELS=="target2:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0/host2':
    KERNELS=="host2"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0':
    KERNELS=="2-5: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/usb2/2-5':
    KERNELS=="2-5"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="5"
    ATTRS{idVendor}=="0951"
    ATTRS{speed}=="480"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="4"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="200mA"
    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}=="001CC0EC34A2BB318709004B"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="1927"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Kingston"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="1642"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}=="DT 101 G2"

  looking at parent device '/devices/pci0000:00/0000:00:1d.7/usb2':
    KERNELS=="usb2"
    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}=="2"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="8"
    ATTRS{bcdDevice}=="0312"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="0000:00:1d.7"
    ATTRS{version}==" 2.00"
    ATTRS{urbnum}=="89"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 3.12-1-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}=="23"
    ATTRS{subsystem_vendor}=="0x1458"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0320"
    ATTRS{companion}==""
    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}=="0x27cc"
    ATTRS{uframe_periodic_max}=="100"
    ATTRS{enable}=="1"
    ATTRS{msi_bus}==""
    ATTRS{local_cpulist}=="0-1"
    ATTRS{vendor}=="0x8086"
    ATTRS{subsystem_device}=="0x5006"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="1"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

ve:

# udevadm info --name=/dev/sdb
P: /devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0/host2/target2:0:0/2:0:0:0/block/sdb
N: sdb
S: disk/by-id/usb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0
S: disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0
S: pen
E: DEVLINKS=/dev/disk/by-id/usb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0 /dev/disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0 /dev/pen
E: DEVNAME=/dev/sdb
E: DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0/host2/target2:0:0/2:0:0:0/block/sdb
E: DEVTYPE=disk
E: ID_BUS=usb
E: ID_INSTANCE=0:0
E: ID_MODEL=DT_101_G2
E: ID_MODEL_ENC=DT\x20101\x20G2\x20\x20\x20\x20\x20\x20\x20
E: ID_MODEL_ID=1642
E: ID_PART_TABLE_TYPE=dos
E: ID_PATH=pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=pci-0000_00_1d_7-usb-0_5_1_0-scsi-0_0_0_0
E: ID_REVISION=PMAP
E: ID_SERIAL=Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0
E: ID_SERIAL_SHORT=001CC0EC34A2BB318709004B
E: ID_TYPE=disk
E: ID_USB_DRIVER=usb-storage
E: ID_USB_INTERFACES=:080650:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=Kingston
E: ID_VENDOR_ENC=Kingston
E: ID_VENDOR_ID=0951
E: MAJOR=8
E: MINOR=16
E: SUBSYSTEM=block
E: USEC_INITIALIZED=32380484

Ama test etmek istediğimde, bana bu günlüğü verdi:

# udevadm test /devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0/host2/target2:0:0/2:0:0:0/block/sdb
calling: test
version 204
This program is for debugging only, it does not run any program
specified by a RUN key. It may show incorrect results, because
some values may be different, or not available at a simulation run.

=== trie on-disk ===
tool version:          204
file size:         5729797 bytes
header size             80 bytes
strings            1262125 bytes
nodes              4467592 bytes
load module index
Skipping overridden file: /lib/udev/rules.d/95-keymap.rules.
read rules file: /lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /lib/udev/rules.d/50-firmware.rules
read rules file: /lib/udev/rules.d/50-udev-default.rules
read rules file: /lib/udev/rules.d/55-dm.rules
read rules file: /lib/udev/rules.d/56-lvm.rules
read rules file: /lib/udev/rules.d/60-cdrom_id.rules
read rules file: /lib/udev/rules.d/60-fuse.rules
read rules file: /lib/udev/rules.d/60-gnupg.rules
read rules file: /lib/udev/rules.d/60-libfreenect0.2.rules
read rules file: /lib/udev/rules.d/60-libgphoto2-6.rules
read rules file: /lib/udev/rules.d/60-libpisock9.rules
read rules file: /lib/udev/rules.d/60-libsane.rules
read rules file: /lib/udev/rules.d/60-nvidia-kernel-common.rules
read rules file: /lib/udev/rules.d/60-pcmcia.rules
read rules file: /lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /lib/udev/rules.d/60-persistent-input.rules
read rules file: /lib/udev/rules.d/60-persistent-serial.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-dm.rules
read rules file: /lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /lib/udev/rules.d/60-persistent-storage.rules
read rules file: /lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /lib/udev/rules.d/60-virtualbox-dkms.rules
read rules file: /lib/udev/rules.d/60-virtualbox.rules
read rules file: /lib/udev/rules.d/61-accelerometer.rules
read rules file: /etc/udev/rules.d/61-removable-storage-polling.rules
read rules file: /lib/udev/rules.d/64-btrfs.rules
read rules file: /lib/udev/rules.d/64-xorg-xkb.rules
read rules file: /lib/udev/rules.d/69-cd-sensors.rules
IMPORT found builtin 'usb_id --export %p', replacing /lib/udev/rules.d/69-cd-sensors.rules:89
read rules file: /lib/udev/rules.d/69-libmtp.rules
read rules file: /lib/udev/rules.d/69-lvm-metad.rules
read rules file: /lib/udev/rules.d/69-xorg-vmmouse.rules
read rules file: /lib/udev/rules.d/70-btrfs.rules
read rules file: /etc/udev/rules.d/70-persistent-cd.rules
read rules file: /etc/udev/rules.d/70-persistent-net.rules
read rules file: /lib/udev/rules.d/70-power-switch.rules
read rules file: /lib/udev/rules.d/70-udev-acl.rules
read rules file: /etc/udev/rules.d/70-zram.rules
read rules file: /lib/udev/rules.d/75-cd-aliases-generator.rules
read rules file: /lib/udev/rules.d/75-net-description.rules
read rules file: /lib/udev/rules.d/75-persistent-net-generator.rules
read rules file: /lib/udev/rules.d/75-probe_mtd.rules
read rules file: /lib/udev/rules.d/75-tty-description.rules
read rules file: /lib/udev/rules.d/78-sound-card.rules
read rules file: /lib/udev/rules.d/80-btrfs-lvm.rules
read rules file: /lib/udev/rules.d/80-drivers.rules
read rules file: /lib/udev/rules.d/80-net-name-slot.rules
read rules file: /lib/udev/rules.d/80-networking.rules
read rules file: /lib/udev/rules.d/85-hdparm.rules
read rules file: /lib/udev/rules.d/85-hwclock.rules
read rules file: /lib/udev/rules.d/90-alsa-restore.rules
read rules file: /lib/udev/rules.d/90-pulseaudio.rules
read rules file: /lib/udev/rules.d/91-permissions.rules
read rules file: /lib/udev/rules.d/95-cd-devices.rules
read rules file: /lib/udev/rules.d/95-keyboard-force-release.rules
read rules file: /etc/udev/rules.d/95-keymap.rules
read rules file: /lib/udev/rules.d/95-udev-late.rules
read rules file: /lib/udev/rules.d/97-bluetooth-hid2hci.rules
read rules file: /etc/udev/rules.d/99-local.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 31233 bytes strings
27768 strings (226512 bytes), 24687 de-duplicated (198361 bytes), 3082 trie nodes used
IMPORT builtin 'usb_id' /lib/udev/rules.d/60-persistent-storage.rules:68
/sys/devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0: if_class 8 protocol 6
IMPORT builtin 'path_id' /lib/udev/rules.d/60-persistent-storage.rules:89
LINK 'disk/by-id/usb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0' /lib/udev/rules.d/60-persistent-storage.rules:108
LINK 'disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0' /lib/udev/rules.d/60-persistent-storage.rules:130
IMPORT '/sbin/blkid -o udev -p /dev/sdb' /lib/udev/rules.d/60-persistent-storage.rules:151
starting '/sbin/blkid -o udev -p /dev/sdb'
'/sbin/blkid -o udev -p /dev/sdb' [12103] exit with return code 0
RUN '/etc/init.d/hdparm hotplug' /lib/udev/rules.d/85-hdparm.rules:1
GROUP 6 /lib/udev/rules.d/91-permissions.rules:4
GROUP 25 /lib/udev/rules.d/91-permissions.rules:5
GROUP 25 /lib/udev/rules.d/91-permissions.rules:9
NAME="pendrak" ignored, kernel device nodes can not be renamed; please fix it in /etc/udev/rules.d/99-local.rules:1
LINK 'pen' /etc/udev/rules.d/99-local.rules:1
handling device node '/dev/sdb', devnum=b8:16, mode=0660, uid=0, gid=25
preserve permissions /dev/sdb, 060660, uid=0, gid=25
preserve already existing symlink '/dev/block/8:16' to '../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-id\x2fusb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0'
creating link '/dev/disk/by-id/usb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-id/usb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0' to '../../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fdisk\x2fby-path\x2fpci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0'
creating link '/dev/disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0' to '/dev/sdb'
preserve already existing symlink '/dev/disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0' to '../../sdb'
found 'b8:16' claiming '/run/udev/links/\x2fpen'
creating link '/dev/pen' to '/dev/sdb'
preserve already existing symlink '/dev/pen' to 'sdb'
.ID_FS_TYPE_NEW=
ACTION=add
DEVLINKS=/dev/disk/by-id/usb-Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0 /dev/disk/by-path/pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0 /dev/pen
DEVNAME=/dev/sdb
DEVPATH=/devices/pci0000:00/0000:00:1d.7/usb2/2-5/2-5:1.0/host2/target2:0:0/2:0:0:0/block/sdb
DEVTYPE=disk
ID_BUS=usb
ID_FS_TYPE=
ID_INSTANCE=0:0
ID_MODEL=DT_101_G2
ID_MODEL_ENC=DT\x20101\x20G2\x20\x20\x20\x20\x20\x20\x20
ID_MODEL_ID=1642
ID_PART_TABLE_TYPE=dos
ID_PATH=pci-0000:00:1d.7-usb-0:5:1.0-scsi-0:0:0:0
ID_PATH_TAG=pci-0000_00_1d_7-usb-0_5_1_0-scsi-0_0_0_0
ID_REVISION=PMAP
ID_SERIAL=Kingston_DT_101_G2_001CC0EC34A2BB318709004B-0:0
ID_SERIAL_SHORT=001CC0EC34A2BB318709004B
ID_TYPE=disk
ID_USB_DRIVER=usb-storage
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Kingston
ID_VENDOR_ENC=Kingston
ID_VENDOR_ID=0951
MAJOR=8
MINOR=16
SUBSYSTEM=block
USEC_INITIALIZED=32380484
run: '/etc/init.d/hdparm hotplug'
unload module index

Gördüğünüz gibi, sembolik bağlantı oluşturuldu, ancak ad değişmedi ve aşağıdaki hatayı aldım:

NAME="pendrak" ignored, kernel device nodes can not be renamed; please fix it in /etc/udev/rules.d/99-local.rules:1

Başka bir şey, bağlantının rastgele sdb, sdb1, sdb2, vb.

# ls -al /dev/pen
lrwxrwxrwx 1 root root 3 Mar 13 12:49 /dev/pen -> sdb
# ls -al /dev/pen
lrwxrwxrwx 1 root root 4 Mar 13 12:53 /dev/pen -> sdb2
# ls -al /dev/pen
lrwxrwxrwx 1 root root 4 Mar 13 12:53 /dev/pen -> sdb1
# ls -al /dev/pen
lrwxrwxrwx 1 root root 4 Mar 13 12:53 /dev/pen -> sdb2
# ls -al /dev/pen
lrwxrwxrwx 1 root root 4 Mar 13 12:53 /dev/pen -> sdb3

Her pendrive'ı taktığımda değişir.

Buradaki görev, cihazın adını sdb'den (veya ne olursa olsun) değiştirmek pendrakve ayrıca bir bağlantı oluşturmaktır. Hata, "çekirdek aygıt düğümlerinin yeniden adlandırılamayacağını" iddia etti - bu, adı hiç değiştiremediğim anlamına geliyor ve yapabileceğim tek şey semboller oluşturmak mı?

Yanıtlar:


14

Udev kılavuzuna göre, /dev/dizindeki dosyaların adlarını değiştirmenin bir yolu yoktur :

NAME
The name to use for a network interface. The name of a device node
cannot be changed by udev, only additional symlinks can be created.

Yani, benim durumumda bunlara benzer kurallar yazmalıyım:

KERNEL=="sd?3", ACTION=="add", ENV{ID_SERIAL_SHORT}=="001CC0EC34A2BB318709004B", \
    SYMLINK+="pen%n", \
    RUN+="/usr/bin/udevil mount /dev/pen%n /mnt/dane"

KERNEL=="sd?1", ACTION=="add", ENV{ID_SERIAL_SHORT}=="001CC0EC34A2BB318709004B", \
    SYMLINK+="pen%n", \
    RUN+="/usr/bin/udevil mount /dev/pen%n /mnt/debian"

KERNEL=="sd?2", ACTION=="add", ENV{ID_SERIAL_SHORT}=="001CC0EC34A2BB318709004B", \
    SYMLINK+="pen%n", \
    RUN+="/sbin/cryptsetup luksOpen /dev/pen%n pen%n --key-file=/home/morfik/Desktop/pen2.key", \
    RUN+="/usr/bin/udevil mount /dev/mapper/pen%n /mnt/szyfr"
KERNEL=="sd?2", ACTION=="remove", ENV{ID_SERIAL_SHORT}=="001CC0EC34A2BB318709004B", \
    RUN+="/sbin/cryptsetup luksClose pen%n"

Üç bağlantı oluştururlar: kalem1, kalem2, kalem3. Bunların her biri ilgili sdb'ye (veya ne olursa olsun) cihaza bağlanır ve bunları udevil aracıyla belirtilen dizinlere açar ve bağlar.



2
Bu, yanıtta okuyabileceğiniz gibi yalnızca ağ arabirimleri için geçerlidir.
Mikhail Morfikov

1
Not: Bu, diğer cihaz türleriyle de çalışıyordu, ancak bu özellik bazı sistemd sürümleriyle kaldırıldı.
ibre5041

Artık çekirdek aygıt düğümlerini yeniden adlandıramazsak, herhangi bir geçici çözüm var mı? Herhangi bir kaba kuvvet yolu var mı? : D
midnite

Sadece semboller oluşturun. Ne olursa olsun aynı isimlere sahip tüm cihazlar için yapıyorum.
Mikhail Morfikov
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.