这篇文章主要介绍在Oracle Linux 7中如何使用udev来设置用户自定义的设备名。在Oracle Linux 7 中的设置方法与之前的Linux版本有较大差别。
下面的例子的对/dev/sdb,/dev/sdc通过设置udev rules来创建用户定义的设备名称
1.查看Linux版本
[root@linuxidc.com ~]# uname -a
Linux linuxidc.com 3.8.13-55.1.6.el7uek.x86_64 #2 SMP Wed Feb 11 14:18:22 PST 2015 x86_64 x86_64 x86_64 GNU/Linux
2.查找设备的UUID
[root@linuxidc.com ~]# fdisk -l
Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x41b4373b
Device Boot Start End Blocks Id System
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000209aa
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 104857599 51915776 8e Linux LVM
Disk /dev/sdc: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/ol-root: 47.7 GB, 47747956736 bytes, 93257728 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/ol-swap: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@linuxidc.com dev]# /usr/lib/udev/scsi_id -g -u /dev/sdb
36000c294ae49672e100c14f8d1708ba0
[root@linuxidc.com dev]# /usr/lib/udev/scsi_id -g -u /dev/sdc
36000c2952e94e2262a0c351bbb9817eb
注意:如果是使用vmvare虚拟机,那么显示uuid需要在vmx文件中增加disk.enableUUID = “TRUE”,我这里使用了是vmvare虚拟机,在相应的虚拟机的vmx文件增加了disk.enableUUID = “TRUE”
~ # vi/vmfs/volumes/581c05d5-12b526b2-f04f- 5c260afd5108/oracle_linux7_1/oracle_linux7_1.vmx
.encoding = “UTF-8”
disk.EnableUUID=”TRUE”
…省略…
3.创建新的udev rule
[root@linuxidc.com dev]# vi /etc/udev/rules.d/99-my-asmdevices.rules
KERNEL==”sd*[!0-9]”, ENV{DEVTYPE}==”disk”, SUBSYSTEM==”block”, PROGRAM==”/usr/lib/udev/scsi_id -g -u -d $devnode”, RESULT==”36000c294ae49672e100c14f8d1708ba0″, RUN+=”/bin/sh -c ‘mknod /dev/asmdisk01 b $major $minor; chown grid:oinstall /dev/asmdisk01; chmod 0660 /dev/asmdisk01′”
KERNEL==”sd*[!0-9]”, ENV{DEVTYPE}==”disk”, SUBSYSTEM==”block”, PROGRAM==”/usr/lib/udev/scsi_id -g -u -d $devnode”, RESULT==”36000c2952e94e2262a0c351bbb9817eb”, RUN+=”/bin/sh -c ‘mknod /dev/asmdisk02 b $major $minor; chown grid:oinstall /dev/asmdisk02; chmod 0660 /dev/asmdisk02′”
4.测试新的udev rule
执行以下命令或重启来验证新的udev rule
4.1 检查新的设备名称:
[root@linuxidc.com dev]# /sbin/udevadm trigger –type=devices –action=change
[root@linuxidc.com dev]# ls -lrt asm*
brw-rw—-. 1 grid oinstall 8, 32 Dec 15 18:32 asmdisk02
brw-rw—-. 1 grid oinstall 8, 16 Dec 15 18:32 asmdisk01
4.2 为了重新加载udev rule执行以下命令:
[root@linuxidc.com dev]# /sbin/udevadm control –reload
4.3为了诊断udev rule执行以下命令:
[root@linuxidc.com dev]# /sbin/udevadm test /sys/block/sdb
calling: test
version 208
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: 208
file size: 6376691 bytes
header size 80 bytes
strings 1401963 bytes
nodes 4974648 bytes
load module index
read rules file: /usr/lib/udev/rules.d/10-dm.rules
read rules file: /usr/lib/udev/rules.d/100-balloon.rules
read rules file: /usr/lib/udev/rules.d/11-dm-lvm.rules
read rules file: /usr/lib/udev/rules.d/11-dm-mpath.rules
read rules file: /usr/lib/udev/rules.d/13-dm-disk.rules
read rules file: /usr/lib/udev/rules.d/40-libgphoto2.rules
IMPORT found builtin ‘usb_id –export %%p’, replacing /usr/lib/udev/rules.d/40- libgphoto2.rules:11
read rules file: /usr/lib/udev/rules.d/40-RedHat.rules
read rules file: /usr/lib/udev/rules.d/40-usb-media-players.rules
read rules file: /usr/lib/udev/rules.d/40-usb_modeswitch.rules
read rules file: /usr/lib/udev/rules.d/42-usb-hid-pm.rules
read rules file: /usr/lib/udev/rules.d/50-rbd.rules
read rules file: /usr/lib/udev/rules.d/50-udev-default.rules
read rules file: /usr/lib/udev/rules.d/56-hpmud.rules
read rules file: /usr/lib/udev/rules.d/60-alias-kmsg.rules
read rules file: /usr/lib/udev/rules.d/60-cdrom_id.rules
read rules file: /usr/lib/udev/rules.d/60-fprint-autosuspend.rules
read rules file: /usr/lib/udev/rules.d/60-keyboard.rules
read rules file: /usr/lib/udev/rules.d/60-net.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-alsa.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-input.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-serial.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-storage-tape.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-storage.rules
read rules file: /usr/lib/udev/rules.d/60-persistent-v4l.rules
read rules file: /usr/lib/udev/rules.d/60-raw.rules
read rules file: /usr/lib/udev/rules.d/61-accelerometer.rules
read rules file: /usr/lib/udev/rules.d/61-gnome-bluetooth-rfkill.rules
read rules file: /usr/lib/udev/rules.d/62-multipath.rules
read rules file: /usr/lib/udev/rules.d/63-md-raid-arrays.rules
read rules file: /usr/lib/udev/rules.d/64-btrfs.rules
read rules file: /usr/lib/udev/rules.d/65-libwacom.rules
read rules file: /usr/lib/udev/rules.d/65-md-incremental.rules
read rules file: /usr/lib/udev/rules.d/65-sane-backends.rules
read rules file: /usr/lib/udev/rules.d/69-cd-sensors.rules
IMPORT found builtin ‘usb_id –export %p’, replacing /usr/lib/udev/rules.d/69-cd- sensors.rules:89
read rules file: /usr/lib/udev/rules.d/69-dm-lvm-metad.rules
read rules file: /usr/lib/udev/rules.d/69-libmtp.rules
read rules file: /usr/lib/udev/rules.d/69-xorg-vmmouse.rules
read rules file: /etc/udev/rules.d/70-persistent-ipoib.rules
read rules file: /usr/lib/udev/rules.d/70-power-switch.rules
read rules file: /usr/lib/udev/rules.d/70-printers.rules
read rules file: /usr/lib/udev/rules.d/70-spice-vdagentd.rules
read rules file: /usr/lib/udev/rules.d/70-touchpad-quirks.rules
read rules file: /usr/lib/udev/rules.d/70-uaccess.rules
read rules file: /usr/lib/udev/rules.d/70-wacom.rules
read rules file: /usr/lib/udev/rules.d/71-biosdevname.rules
read rules file: /usr/lib/udev/rules.d/71-seat.rules
read rules file: /usr/lib/udev/rules.d/73-idrac.rules
read rules file: /usr/lib/udev/rules.d/73-seat-late.rules
read rules file: /usr/lib/udev/rules.d/75-net-description.rules
read rules file: /usr/lib/udev/rules.d/75-probe_mtd.rules
read rules file: /usr/lib/udev/rules.d/75-tty-description.rules
read rules file: /usr/lib/udev/rules.d/77-mm-ericsson-mbm.rules
read rules file: /usr/lib/udev/rules.d/77-mm-huawei-net-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-mm-longcheer-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-mm-nokia-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-mm-pcmcia-device-blacklist.rules
read rules file: /usr/lib/udev/rules.d/77-mm-platform-serial-whitelist.rules
read rules file: /usr/lib/udev/rules.d/77-mm-simtech-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-mm-telit-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-mm-usb-device-blacklist.rules
read rules file: /usr/lib/udev/rules.d/77-mm-usb-serial-adapters-greylist.rules
read rules file: /usr/lib/udev/rules.d/77-mm-x22x-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-mm-zte-port-types.rules
read rules file: /usr/lib/udev/rules.d/77-nm-olpc-mesh.rules
read rules file: /usr/lib/udev/rules.d/78-sound-card.rules
read rules file: /usr/lib/udev/rules.d/80-drivers.rules
read rules file: /usr/lib/udev/rules.d/80-kvm.rules
read rules file: /usr/lib/udev/rules.d/80-mm-candidate.rules
read rules file: /usr/lib/udev/rules.d/80-net-name-slot.rules
read rules file: /usr/lib/udev/rules.d/80-udisks2.rules
read rules file: /usr/lib/udev/rules.d/81-kvm-rhel.rules
read rules file: /usr/lib/udev/rules.d/85-regulatory.rules
read rules file: /usr/lib/udev/rules.d/85-usbmuxd.rules
read rules file: /usr/lib/udev/rules.d/90-alsa-restore.rules
read rules file: /usr/lib/udev/rules.d/90-alsa-tools-firmware.rules
read rules file: /usr/lib/udev/rules.d/90-iprutils.rules
read rules file: /usr/lib/udev/rules.d/90-pulseaudio.rules
read rules file: /usr/lib/udev/rules.d/90-vconsole.rules
read rules file: /usr/lib/udev/rules.d/91-drm-modeset.rules
read rules file: /usr/lib/udev/rules.d/95-cd-devices.rules
read rules file: /usr/lib/udev/rules.d/95-dm-notify.rules
read rules file: /usr/lib/udev/rules.d/95-udev-late.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-dell.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-fujitsu.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-gateway.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-ibm.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-lenovo.rules
read rules file: /usr/lib/udev/rules.d/95-upower-battery-recall-toshiba.rules
read rules file: /usr/lib/udev/rules.d/95-upower-csr.rules
read rules file: /usr/lib/udev/rules.d/95-upower-hid.rules
read rules file: /usr/lib/udev/rules.d/95-upower-wup.rules
read rules file: /usr/lib/udev/rules.d/97-bluetooth-serial.rules
read rules file: /usr/lib/udev/rules.d/98-kexec.rules
read rules file: /usr/lib/udev/rules.d/98-rdma.rules
read rules file: /etc/udev/rules.d/99-my-asmdevices.rules
read rules file: /usr/lib/udev/rules.d/99-qemu-guest-agent.rules
read rules file: /usr/lib/udev/rules.d/99-systemd.rules
rules contain 393216 bytes tokens (32768 * 12 bytes), 38852 bytes strings
30460 strings (257150 bytes), 27006 de-duplicated (221753 bytes), 3455 trie nodes used
GROUP 6 /usr/lib/udev/rules.d/50-udev-default.rules:51
IMPORT ‘scsi_id –export –whitelisted -d /dev/sdb’ /usr/lib/udev/rules.d/60- persistent-storage.rules:40
starting ‘scsi_id –export –whitelisted -d /dev/sdb’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_SCSI=1’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_VENDOR=VMware’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_VENDOR_ENC=VMware\x20\x20’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_MODEL=Virtual_disk’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_MODEL_ENC=Virtual\x20disk \x20\x20\x20\x20’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_REVISION=1.0’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_TYPE=disk’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_SERIAL=36000c294ae49672e100c14f8d1708ba0’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_SERIAL_SHORT=6000c294ae49672e100c14f8d1708ba0’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_WWN=0x6000c294ae49672e’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_WWN_VENDOR_EXTENSION=0x100c14f8d1708ba0’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_WWN_WITH_EXTENSION=0x6000c294ae49672e100c14f8d1708ba0’
‘scsi_id –export –whitelisted -d /dev/sdb'(out) ‘ID_SCSI_SERIAL=6000c294ae49672e100c14f8d1708ba0’
‘scsi_id –export –whitelisted -d /dev/sdb’ [24105] exit with return code 0
LINK ‘disk/by-id/scsi-36000c294ae49672e100c14f8d1708ba0’ /usr/lib/udev/rules.d/60- persistent-storage.rules:42
IMPORT builtin ‘path_id’ /usr/lib/udev/rules.d/60-persistent-storage.rules:58
LINK ‘disk/by-path/pci-0000:02:01.0-scsi-0:0:0:0’ /usr/lib/udev/rules.d/60-persistent- storage.rules:59
IMPORT builtin ‘blkid’ /usr/lib/udev/rules.d/60-persistent-storage.rules:73
probe /dev/sdb raid offset=0
LINK ‘disk/by-id/wwn-0x6000c294ae49672e100c14f8d1708ba0’ /usr/lib/udev/rules.d/60- persistent-storage.rules:83
PROGRAM ‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb’ /etc/udev/rules.d/99-my- asmdevices.rules:2
starting ‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb’
‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb'(out) ‘36000c294ae49672e100c14f8d1708ba0’
‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb’ [24106] exit with return code 0
RUN ‘/bin/sh -c ‘mknod /dev/asmdisk01 b $major $minor; chown grid:oinstall /dev/asmdisk01; chmod 0660 /dev/asmdisk01” /etc/udev/rules.d/99-my-asmdevices.rules:2
PROGRAM ‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb’ /etc/udev/rules.d/99-my- asmdevices.rules:4
starting ‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb’
‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb'(out) ‘36000c294ae49672e100c14f8d1708ba0’
‘/usr/lib/udev/scsi_id -g -u -d /dev/sdb’ [24107] exit with return code 0
handling device node ‘/dev/sdb’, devnum=b8:16, mode=0660, uid=0, gid=6
set permissions /dev/sdb, 060660, uid=0, gid=6
preserve already existing symlink ‘/dev/block/8:16’ to ‘../sdb’
found ‘b8:16’ claiming ‘/run/udev/links/\x2fdisk\x2fby-id\x2fscsi- 36000c294ae49672e100c14f8d1708ba0’
creating link ‘/dev/disk/by-id/scsi-36000c294ae49672e100c14f8d1708ba0’ to ‘/dev/sdb’
preserve already existing symlink ‘/dev/disk/by-id/scsi- 36000c294ae49672e100c14f8d1708ba0’ to ‘../../sdb’
found ‘b8:16’ claiming ‘/run/udev/links/\x2fdisk\x2fby-id\x2fwwn- 0x6000c294ae49672e100c14f8d1708ba0’
creating link ‘/dev/disk/by-id/wwn-0x6000c294ae49672e100c14f8d1708ba0’ to ‘/dev/sdb’
preserve already existing symlink ‘/dev/disk/by-id/wwn- 0x6000c294ae49672e100c14f8d1708ba0’ to ‘../../sdb’
found ‘b8:16’ claiming ‘/run/udev/links/\x2fdisk\x2fby-path\x2fpci-0000:02:01.0-scsi- 0:0:0:0’
creating link ‘/dev/disk/by-path/pci-0000:02:01.0-scsi-0:0:0:0’ to ‘/dev/sdb’
preserve already existing symlink ‘/dev/disk/by-path/pci-0000:02:01.0-scsi-0:0:0:0’ to ‘../../sdb’
.ID_FS_TYPE_NEW=
ACTION=add
DEVLINKS=/dev/disk/by-id/scsi-36000c294ae49672e100c14f8d1708ba0 /dev/disk/by-id/wwn- 0x6000c294ae49672e100c14f8d1708ba0 /dev/disk/by-path/pci-0000:02:01.0-scsi-0:0:0:0
DEVNAME=/dev/sdb
DEVPATH=/devices/pci0000:00/0000:00:11.0/0000:02:01.0/host3/target3:0:0/3:0:0:0/block/sd b
DEVTYPE=disk
ID_BUS=scsi
ID_FS_TYPE=
ID_MODEL=Virtual_disk
ID_MODEL_ENC=Virtual\x20disk\x20\x20\x20\x20
ID_PART_TABLE_TYPE=dos
ID_PATH=pci-0000:02:01.0-scsi-0:0:0:0
ID_PATH_TAG=pci-0000_02_01_0-scsi-0_0_0_0
ID_REVISION=1.0
ID_SCSI=1
ID_SCSI_SERIAL=6000c294ae49672e100c14f8d1708ba0
ID_SERIAL=36000c294ae49672e100c14f8d1708ba0
ID_SERIAL_SHORT=6000c294ae49672e100c14f8d1708ba0
ID_TYPE=disk
ID_VENDOR=VMware
ID_VENDOR_ENC=VMware\x20\x20
ID_WWN=0x6000c294ae49672e
ID_WWN_VENDOR_EXTENSION=0x100c14f8d1708ba0
ID_WWN_WITH_EXTENSION=0x6000c294ae49672e100c14f8d1708ba0
MAJOR=8
MINOR=16
MPATH_SBIN_PATH=/sbin
SUBSYSTEM=block
TAGS=:systemd:
USEC_INITIALIZED=545736
run: ‘/bin/sh -c ‘mknod /dev/asmdisk01 b 8 16; chown grid:oinstall /dev/asmdisk01; chmod 0660 /dev/asmdisk01”
unload module index
4.4 如果不再需要device可以手动删除device文件
[root@linuxidc.com dev]# /bin/rm /dev/asmdisk01
[root@linuxidc.com dev]# /bin/rm /dev/asmdisk02
[root@linuxidc.com dev]# ls -lrt asm*
ls: cannot access asm*: No such file or directory
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-12/138494.htm