/ dev 디렉토리에서 장치 이름을 변경하는 방법이 있습니까?


13

테스트 목적으로이 규칙을 작성했습니다.

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

다음 정보를 기반으로 :

# 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==""

과:

# 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

그러나 테스트하고 싶을 때 다음과 같은 로그를 얻었습니다.

# 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

보시다시피 심볼릭 링크가 생성되었지만 이름은 변경되지 않았으며 다음 오류가 발생했습니다.

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

다른 점은 링크가 sdb, sdb1, sdb2 등을 임의로 가리 킵니다.

# 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

펜 드라이브를 꽂을 때마다 변경됩니다.

여기서의 작업은 장치 이름을 sdb (또는 그 밖의 것)에서 변경 pendrak하고 링크를 만드는 것입니다. 이 오류는 "커널 장치 노드의 이름을 바꿀 수 없습니다"라고 주장했습니다. 이름을 전혀 변경할 수 없으며 심볼릭 링크를 만드는 것뿐입니까?

답변:


14

udev 매뉴얼에 따르면 /dev/디렉토리 에서 파일 이름을 변경하는 방법은 없습니다 .

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.

따라서 필자의 경우 다음과 유사한 규칙을 작성해야합니다.

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"

그들은 pen1, pen2, pen3의 세 가지 링크를 만듭니다. 각각은 해당 sdb (또는 그 장치)에 연결되며 udevil 도구를 통해 지정된 디렉토리에서 단순히 마운트하고 마운트합니다.



2
답변에서 읽을 수있는 네트워크 인터페이스에만 적용됩니다.
Mikhail Morfikov

1
참고 : 이것은 다른 장치 유형에서도 작동했지만이 기능은 일부 시스템 릴리즈에서 제거되었습니다.
ibre5041

더 이상 커널 장치 노드의 이름을 바꿀 수 없다면 해결 방법이 있습니까? 무차별적인 방법? : D
midnite

심볼릭 링크를 만드십시오. 무엇이든 상관없이 같은 이름을 가져야하는 모든 장치에 대해하고 있습니다.
Mikhail Morfikov
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.