Linux 7的使用人越来越多,但是linux 7相对于5和6的版本,变动确实比较大,本文主要描写在linux 7中如何实现udev,实现设备持久化,权限和所属组的修改.
主要通过scsi_id命令生成一个独一无二的SCSI标示符(uuid)来实现设备的持久化.
[root@localhost ~]# uname -rs
Linux 3.10.0-123.el7.x86_64
[root@localhost ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)
[root@localhost ~]#
3.1、查看磁盘分区
在进行udev绑定的时候,可以是一个未分区的磁盘,也可以是磁盘的一个分区。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000824e9
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 62914559 30944256 8e Linux LVM
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0x827a3ff8
Device Boot Start End Blocks Id System
/dev/sdb1 2048 1026047 512000 83 Linux
/dev/sdb2 1026048 2097151 535552 83 Linux
Disk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 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/rhel-root: 28.5 GB, 28462546944 bytes, 55590912 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/rhel-swap: 3221 MB, 3221225472 bytes, 6291456 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
3.2、查看磁盘的UUID
通过以下命令可以查看磁盘的UUID。
[root@localhost dev]# /lib/udev/scsi_id --whitelisted --replace-whitespace /dev/sdb
1ATA_VBOX_HARDDISK_VB78895597-a79acef1
[root@localhost dev]# /lib/udev/scsi_id --whitelisted --replace-whitespace /dev/sdb1
1ATA_VBOX_HARDDISK_VB78895597-a79acef1
[root@localhost dev]# /lib/udev/scsi_id --whitelisted --replace-whitespace /dev/sdb2
1ATA_VBOX_HARDDISK_VB78895597-a79acef1
[root@localhost dev]# /lib/udev/scsi_id --whitelisted --replace-whitespace /dev/sdc
1ATA_VBOX_HARDDISK_VB060b794b-fed4026b
由以上结果可以看到,sdb、sdb1、sdb2具有相同的UUID,在进行绑定时要在KERNEL参数中区分。
3.3、创建规则文件并编写绑定规则
创建规则文件/etc/udev/rules.d/99-oracle-asm.rules,并加入如下内容。需要请注意:规则文件必须以 .rules结尾,否则会被忽略。
[root@localhost rules.d]# cat /etc/udev/rules.d/99-oracle-asm.rules
KERNEL=="sd?1", SUBSYSTEM=="block", PROGRAM="/lib/udev/scsi_id --whitelisted --replace-whitespace /dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB78895597-a79acef1", SYMLINK+="asm-disk1", OWNER=="grid", GROUP=="asmadmin", MODE="0660"
KERNEL=="sd?2", SUBSYSTEM=="block", PROGRAM="/lib/udev/scsi_id --whitelisted --replace-whitespace /dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB78895597-a79acef1", SYMLINK+="asm-disk2", OWNER=="grid", GROUP=="asmadmin", MODE="0660"
KERNEL=="sd?", SUBSYSTEM=="block", PROGRAM="/lib/udev/scsi_id --whitelisted --replace-whitespace /dev/$name", RESULT=="1ATA_VBOX_HARDDISK_VB060b794b-fed4026b", RUN+="/bin/sh -c 'mknod /dev/asm-disk3 b $major $minor;chown grid:asmadmin /dev/asm-disk3;chmod 0660 /dev/asm-disk3'"
以上规则使用了两种方式进行udev绑定,其中:asm-disk1、asm-disk2使用软链接方式实现,asm-disk3使用mknod命令真实创建udev设备。
两种方式的区别可以通过ls命令看出
[root@localhost dev]# ls -l /dev/sdb* /dev/sdc* /dev/asm*
lrwxrwxrwx. 1 root root 4 Sep 5 10:39 /dev/asm-disk1 -> sdb1
lrwxrwxrwx. 1 root root 4 Sep 5 10:39 /dev/asm-disk2 -> sdb2
brw-rw----. 1 grid asmadmin 8, 32 Sep 5 10:37 /dev/asm-disk3
brw-rw----. 1 grid asmadmin 8, 16 Sep 5 10:39 /dev/sdb
brw-rw----. 1 grid asmadmin 8, 17 Sep 5 10:39 /dev/sdb1
brw-rw----. 1 grid asmadmin 8, 18 Sep 5 10:39 /dev/sdb2
brw-rw----. 1 grid asmadmin 8, 32 Sep 5 10:39 /dev/sdc
执行以下命令将磁盘信息的变化通知内核
[root@localhost dev]# /sbin/partprobe /dev/sdb1
[root@localhost dev]# /sbin/partprobe /dev/sdb2
[root@localhost dev]# /sbin/partprobe /dev/sdc