redhat5.5测试环境中使用udev配置raw设备

CandyInCsdn 2012-09-04

在RedHat 5中,是通过udev 来管理raw 设备的。 那么udev 如何知道raw 设备, 就是通过MAJOR 和 MINOR。 如果我们只写:

ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"

那么Udev 就无法识别出raw 设备,从而无法管理。 也就无法挂载raw。 只有指定了MAJOR 和 MINOR 后才能进行管理。 
 
但是又出来一个问题,我这里有5个分区需要映射,我指定了raw ,MAJOB和 MINOR 后, 5个分区并没有全部挂载,而是只挂载了2个raw。 

后来改了一种方法,就是将raw 设备的挂载添加到/etc/rc.d/rc.local文件中, 让raw开机自动挂载。 这样udev 就能识别出raw设备并进行管理了。
 
这种方法的配置如下:

[root@rac2 rules.d]# cat 60-raw.rules
# Enter raw device bindings here.
#
# An example would be:
#   ACTION=="add", KERNEL=="sda", RUN+="/bin/raw /dev/raw/raw1 %N"
# to bind /dev/raw/raw1 to /dev/sda, or
#   ACTION=="add", ENV{MAJOR}=="8", ENV{MINOR}=="1", RUN+="/bin/raw /dev/raw/raw2 %M %m"
# to bind /dev/raw/raw2 to the device with major 8, minor 1.
ACTION=="add", KERNEL=="crsp5", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="crsp6", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="crsp7", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="crsp8", RUN+="/bin/raw /dev/raw/raw4 %N"
ACTION=="add", KERNEL=="crsp9", RUN+="/bin/raw /dev/raw/raw5 %N"
ACTION=="add", KERNEL=="raw[1-2]", WNER="root", GROUP="oinstall", MODE="660"
ACTION=="add", KERNEL=="raw[3-5]", WNER="Oracle", GROUP="oinstall", MODE="660"
        -- 这个是对raw 设备进行权限设置的
 
[root@rac2 rules.d]# cat /etc/rc.d/rc.local
#!/bin/sh
#
# This script. will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style. init stuff.
 
touch /var/lock/subsys/local
 
/bin/raw /dev/raw/raw1 /dev/mapper/crsp5
/bin/raw /dev/raw/raw2 /dev/mapper/crsp6
/bin/raw /dev/raw/raw3 /dev/mapper/crsp7
/bin/raw /dev/raw/raw4 /dev/mapper/crsp8
/bin/raw /dev/raw/raw5 /dev/mapper/crsp9
-- 系统启动时挂载raw设备
 
这样设置之后,用start_udev命令重启udev 或者重启操作系统之后, RAW就能自动挂载,并且权限也修改了过来。
 
[root@rac2 rules.d]# ls -lrt /dev/raw/raw*
crw-rw---- 1 oracle oinstall 162, 1 Nov 25 02:35 /dev/raw/raw1
crw-rw---- 1 oracle oinstall 162, 2 Nov 25 02:35 /dev/raw/raw2
crw-rw---- 1 oracle oinstall 162, 3 Nov 25 02:35 /dev/raw/raw3
crw-rw---- 1 oracle oinstall 162, 4 Nov 25 02:35 /dev/raw/raw4
crw-rw---- 1 oracle oinstall 162, 5 Nov 25 02:35 /dev/raw/raw5
[root@rac2 rules.d]# raw -qa
/dev/raw/raw1:  bound to major 253, minor 5
/dev/raw/raw2:  bound to major 253, minor 6
/dev/raw/raw3:  bound to major 253, minor 7
/dev/raw/raw4:  bound to major 253, minor 8
/dev/raw/raw5:  bound to major 253, minor 9
 
说明:
Linux 4下做多可以绑定8192个裸设备。但是在linux下,最多只能有255个分区,所以,如果用裸设备绑定分区,最多只能绑定255个裸设备。 如果是用lvm,则没有这个限制。

相关推荐