在Linux 5/6上使用UDEV SCSI规则配置ASM DISK

绑定对象可以为磁盘 也可为分区(格式化后的磁盘)

识别磁盘(/sbin/scsi_id) 

  • Oracle Linux 5用如下脚本:
#!/bin/sh
for i in b c d e f g  
do  
echo "KERNEL==\"sd*\", BUS==\"scsi\", PROGRAM==\"/sbin/scsi_id -g -u -s /block/$parent", RESULT==\"`/sbin/scsi_id /block/sd$i`\", NAME=\"asm-disk$i\", OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\""  
done 
  • Oracle Linux 6用如下脚本(未验证):
#!/bin/sh
for i in b c d e f g  
do  
echo "KERNEL==\"sd*\", BUS==\"scsi\", PROGRAM==\"/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/\$name\", RESULT==\"`/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/sd$i`\", NAME=\"asm-disk$i\", OWNER=\"grid\", GROUP=\"asmadmin\", MODE=\"0660\""  
done

 

UDEV配置文件

重要:每个配置文件一行为一条规则,并且,(逗号)与下一个关键词之间有空格

  • Oracle Linux 5用如下参数
[root@node1 ~]# cat /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s /block/$parent", RESULT=="SATA_VBOX_HARDDISK_VB96e49463-3665e815_", NAME="asm-diskb", OWNER="grid", GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s /block/$parent", RESULT=="SATA_VBOX_HARDDISK_VB944f68ec-f33e8a99_", NAME="asm-diskc", OWNER="grid", GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s /block/$parent", RESULT=="SATA_VBOX_HARDDISK_VBf2e05152-1c6b4621_", NAME="asm-diskd", OWNER="grid", GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s /block/$parent", RESULT=="SATA_VBOX_HARDDISK_VB91ee2629-8151eac9_", NAME="asm-diske", OWNER="grid", GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s /block/$parent", RESULT=="SATA_VBOX_HARDDISK_VB4541d4a0-9c804156_", NAME="asm-diskf", OWNER="grid", GROUP="asmadmin", MODE="0660"
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s /block/$parent", RESULT=="SATA_VBOX_HARDDISK_VBa741850f-bf6c5aa6_", NAME="asm-diskg", OWNER="grid", GROUP="asmadmin", MODE="0660"
  • Oracle Linux 6 用如下参数(未验证)
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c294347acba383e23ecbd43867c4", NAME="asm-diskb", OWNER="grid", GROUP="asmadmin", MODE="0660"  
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c2913d3b49354c9d030816bd5de9", NAME="asm-diskc", OWNER="grid", GROUP="asmadmin", MODE="0660"  
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c296cf9ff63b87e2903925bdec21", NAME="asm-diskd", OWNER="grid", GROUP="asmadmin", MODE="0660"  
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c2952ef3147bf0c3efc345133b00", NAME="asm-diske", OWNER="grid", GROUP="asmadmin", MODE="0660"  
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c296f16a22e6292edfb3ec3b1934", NAME="asm-diskf", OWNER="grid", GROUP="asmadmin", MODE="0660"  
KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id --whitelisted --replace-whitespace --device=/dev/$name", RESULT=="36000c29ae38dfe96f6342cb2afd7f3fb", NAME="asm-diskg", OWNER="grid", GROUP="asmadmin", MODE="0660" 

 

添加SCSI设备信任关系

编辑"/etc/scsi_id.config" 文件配置SCSI设备信任关系: options=-g

[root@ncdb2 dev]# vi /etc/scsi_id.config
#
# scsi_id configuration
#
# lower or upper case has no affect on the left side. Quotes (") are
# required for spaces in values. Model is the same as the SCSI
# INQUIRY product identification field. Per the SCSI INQUIRY, the vendor
# is limited to 8 bytes, model to 16 bytes.
#
# The first matching line found is used. Short matches match longer ones,
# if you do not want such a match space fill the extra bytes. If no model
# is specified, only the vendor string need match.
#
# options=<any scsi_id command line options>
# vendor=string[,model=string],options=<per-device scsi_id options>

# some libata drives require vpd page 0x80
vendor="ATA",options=-p 0x80

options=-g


引导更新块设备分区表

# /sbin/partprobe /dev/sdb1
# /sbin/partprobe /dev/sdc1
# /sbin/partprobe /dev/sdd1
# /sbin/partprobe /dev/sde1
# /sbin/partprobe /dev/sdf1
# /sbin/partprobe /dev/sdg1

 

测试规则文件(99-oracle-asmdevices.rules)是否生效

# #Linux5
# udevtest /block/sdb/sdb1
# udevtest /block/sdc/sdc1

# #Linux6
# udevadm test /block/sdb/sdb1
# udevadm test /block/sdc/sdc1

输出结果:
[root@ncdb1 rules.d]# udevtest /block/sdb/sdb1
main: looking at device '/block/sdb/sdb1' from subsystem 'block'
udev_rules_get_name: add symlink 'disk/by-id/scsi-SATA_VBOX_HARDDISK_VB96e49463-3665e815-part1'
udev_rules_get_name: add symlink 'disk/by-path/pci-0000:00:0d.0-scsi-1:0:0:0-part1'
run_program: '/lib/udev/vol_id --export /dev/.tmp-8-17'
run_program: '/lib/udev/vol_id' returned with status 4
run_program: '/sbin/scsi_id -g -u -s /block/sdb'
run_program: '/sbin/scsi_id' (stdout) 'SATA_VBOX_HARDDISK_VB96e49463-3665e815_'
run_program: '/sbin/scsi_id' returned with status 0
udev_rules_get_name: rule applied, 'sdb1' becomes 'asm-diskb'
udev_device_event: device '/block/sdb/sdb1' already in database, validate currently present symlinks
udev_node_add: creating device node '/dev/asm-diskb', major = '8', minor = '17', mode = '0660', uid = '1100', gid = '1020'
udev_node_add: creating symlink '/dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VB96e49463-3665e815-part1' to '../../asm-diskb'
udev_node_add: creating symlink '/dev/disk/by-path/pci-0000:00:0d.0-scsi-1:0:0:0-part1' to '../../asm-diskb'
main: run: 'socket:/org/kernel/dm/multipath_event'
main: run: 'socket:/org/kernel/udev/monitor'
main: run: '/lib/udev/udev_run_devd'
main: run: 'socket:/org/freedesktop/hal/udev_event'
main: run: '/sbin/pam_console_apply /dev/asm-diskb /dev/disk/by-id/scsi-SATA_VBOX_HARDDISK_VB96e49463-3665e815-part1 /dev/disk/by-path/pci-0000:00:0d.0-scsi-1:0:0:0-part1'
[root@ncdb1 rules.d]#

 

重启UDEV服务

# #Linux5
# /sbin/udevcontrol reload_rules

# #Linux6
# udevadm control --reload-rules

# #Linux5 and Linux6
# /sbin/start_udev

 检查属主关系和权限

# cd /dev
# ls -al asm-disk*
brw-rw---- 1 oracle dba 8, 17 Apr  8 22:47 asm-disk1
brw-rw---- 1 oracle dba 8, 33 Apr  8 22:47 asm-disk2
#

 

posted @ 2016-02-15 19:26  PoleStar  阅读(3123)  评论(0编辑  收藏  举报