首页 > 代码库 > 在RHEL6上创建裸设备

在RHEL6上创建裸设备

如果想在Linux中安装oracle软件,并且使用裸设备方式建库,那么直接使用lvcreate是不会为我们创建出字符设备的,本文主要讨论如何对逻辑卷创建字符设备。操作系统使用的是RHEL6u4 64bit


$ uname -a

Linux oracle11.cc 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux



逻辑卷怎么创建略过,先看一下我当前系统有哪些逻辑卷


$ ls -l /dev/vg00/*m

lrwxrwxrwx 1 root root 7 Jul  5 20:37 /dev/vg00/control1_16m -> ../dm-9

lrwxrwxrwx 1 root root 8 Jul  5 20:37 /dev/vg00/control2_16m -> ../dm-10

lrwxrwxrwx 1 root root 8 Jul  5 20:37 /dev/vg00/redo1_128m -> ../dm-11

lrwxrwxrwx 1 root root 8 Jul  5 20:37 /dev/vg00/redo2_128m -> ../dm-12

lrwxrwxrwx 1 root root 8 Jul  5 20:37 /dev/vg00/redo3_128m -> ../dm-13

lrwxrwxrwx 1 root root 8 Jul  5 20:37 /dev/vg00/spfile_16m -> ../dm-14

lrwxrwxrwx 1 root root 7 Jul  5 20:37 /dev/vg00/sysaux_1024m -> ../dm-5

lrwxrwxrwx 1 root root 7 Jul  5 20:37 /dev/vg00/system_1024m -> ../dm-4

lrwxrwxrwx 1 root root 7 Jul  5 20:37 /dev/vg00/temp_512m -> ../dm-6

lrwxrwxrwx 1 root root 7 Jul  5 20:37 /dev/vg00/undo_512m -> ../dm-7

lrwxrwxrwx 1 root root 7 Jul  5 20:37 /dev/vg00/user_16m -> ../dm-8


使用udev的方式把块设备文件映射成字符设备文件

如果在rhel5中可以使用/etc/sysconfig/rawdevices 这个文件写映射,挺方便的。但是RHEL6中就找不到这个了。那么我们看一下怎么使用udev方式对他们映射的吧。


首先找到块设备的 MAJOR 和 MINOR

因为上面/dev/vg00 目录下的文件是软连接,所以需要直接查看所对应的块设备文件。


# id root

uid=0(root) gid=0(root) groups=0(root)


# ls -l /dev/dm-{4,5,6,7,8,9,10,11,12,13,14}

brw-rw---- 1 root   disk 253, 10 Jul  5 20:37 /dev/dm-10

brw-rw---- 1 root   disk 253, 11 Jul  5 20:37 /dev/dm-11

brw-rw---- 1 root   disk 253, 12 Jul  5 20:37 /dev/dm-12

brw-rw---- 1 root   disk 253, 13 Jul  5 20:37 /dev/dm-13

brw-rw---- 1 oracle dba  253, 14 Jul  5 20:37 /dev/dm-14

brw-rw---- 1 root   disk 253,  4 Jul  5 20:37 /dev/dm-4

brw-rw---- 1 root   disk 253,  5 Jul  5 20:37 /dev/dm-5

brw-rw---- 1 root   disk 253,  6 Jul  5 20:37 /dev/dm-6

brw-rw---- 1 root   disk 253,  7 Jul  5 20:37 /dev/dm-7

brw-rw---- 1 root   disk 253,  8 Jul  5 20:37 /dev/dm-8

brw-rw---- 1 root   disk 253,  9 Jul  5 20:37 /dev/dm-9



其中第五列就是MAJOR 第六列就是MINOR,比如/dev/dm-0的 MAJOR就是253,MINOR就是0


那么这两个参数是怎么使用的呢?

通过下面方法打开规则文件,范例都在里面呢。



# vi /etc/udev/rules.d/60-raw.rules 

(我对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.

范例中提到,有两种写raw映射的方法。第一种就是本文将要使用的。第二种一看就能看明白。

写法比较固定,例如:

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="4", RUN+="/bin/raw /dev/raw/raw1 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="5", RUN+="/bin/raw /dev/raw/raw2 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="6", RUN+="/bin/raw /dev/raw/raw3 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="7", RUN+="/bin/raw /dev/raw/raw4 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="8", RUN+="/bin/raw /dev/raw/raw5 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="9", RUN+="/bin/raw /dev/raw/raw6 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="10", RUN+="/bin/raw /dev/raw/raw7 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="11", RUN+="/bin/raw /dev/raw/raw8 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="12", RUN+="/bin/raw /dev/raw/raw9 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="13", RUN+="/bin/raw /dev/raw/raw10 %M %m"

ACTION=="add", ENV{MAJOR}=="253", ENV{MINOR}=="14", RUN+="/bin/raw /dev/raw/raw11 %M %m"


# start_udev

Starting udev: [  OK  ]


查询一下,发现裸设备已经出现了,但是权限还是root,需要在60-raw.rules 中添加授权语句。

# ls -l /dev/raw

total 0

crw-rw---- 1 root disk 162,  1 Jul  6 00:01 raw1

crw-rw---- 1 root disk 162, 10 Jul  6 00:01 raw10

crw-rw---- 1 root disk 162, 11 Jul  6 00:01 raw11

crw-rw---- 1 root disk 162,  2 Jul  6 00:01 raw2

crw-rw---- 1 root disk 162,  3 Jul  6 00:01 raw3

crw-rw---- 1 root disk 162,  4 Jul  6 00:01 raw4

crw-rw---- 1 root disk 162,  5 Jul  6 00:01 raw5

crw-rw---- 1 root disk 162,  6 Jul  6 00:01 raw6

crw-rw---- 1 root disk 162,  7 Jul  6 00:01 raw7

crw-rw---- 1 root disk 162,  8 Jul  6 00:01 raw8

crw-rw---- 1 root disk 162,  9 Jul  6 00:01 raw9

crw-rw---- 1 root disk 162,  0 Jul  6 00:01 rawctl



添加授权语句

KERNEL=="raw[0-9]*", NAME="raw/%k" OWNER="oracle" GROUP="dba", MODE="0660"


# star_udev

# ll /dev/raw

total 0

crw-rw---- 1 oracle dba  162,  1 Jul  6 00:05 raw1

crw-rw---- 1 oracle dba  162, 10 Jul  6 00:05 raw10

crw-rw---- 1 oracle dba  162, 11 Jul  6 00:05 raw11

crw-rw---- 1 oracle dba  162,  2 Jul  6 00:05 raw2

crw-rw---- 1 oracle dba  162,  3 Jul  6 00:05 raw3

crw-rw---- 1 oracle dba  162,  4 Jul  6 00:05 raw4

crw-rw---- 1 oracle dba  162,  5 Jul  6 00:05 raw5

crw-rw---- 1 oracle dba  162,  6 Jul  6 00:05 raw6

crw-rw---- 1 oracle dba  162,  7 Jul  6 00:05 raw7

crw-rw---- 1 oracle dba  162,  8 Jul  6 00:05 raw8

crw-rw---- 1 oracle dba  162,  9 Jul  6 00:05 raw9

crw-rw---- 1 root   disk 162,  0 Jul  6 00:05 rawctl


# raw -qa

/dev/raw/raw1:  bound to major 253, minor 4

/dev/raw/raw2:  bound to major 253, minor 5

/dev/raw/raw3:  bound to major 253, minor 6

/dev/raw/raw4:  bound to major 253, minor 7

/dev/raw/raw5:  bound to major 253, minor 8

/dev/raw/raw6:  bound to major 253, minor 9

/dev/raw/raw7:  bound to major 253, minor 10

/dev/raw/raw8:  bound to major 253, minor 11

/dev/raw/raw9:  bound to major 253, minor 12

/dev/raw/raw10: bound to major 253, minor 13

/dev/raw/raw11: bound to major 253, minor 14



http://blog.itpub.net/23135684/viewspace-696799/

http://www.dswcomputersystems.co.uk/howtos-2/informix-howtos/configuring-raw-disks-on-rhel-6/