配置裸设备(raw devices)

裸设备,是没有经过格式化的分区或磁盘,也叫裸分区(原始分区),不被Unix通过文件系统来读取的特殊字符设备。它由应用程序负责对
它进行读写操作。不经过文件系统的缓冲,是不被操作系统直接管理的设备。由于跨过操作系统管理,使得I/O效率更高。在基于SUSE Linux
10上安装Oracle 10g RAC的话,由于Oracle 10g 不支持将ocr与votingdisk 存放在ASM 磁盘中,因此,依然需要为其使用裸设备方式。SUSE
Linux裸设备的配置与其他的Linux稍有差异,下面将具体描述。

1、先对磁盘进行分区,sdd如下面的方法炮制
#下面的示例中使用sdc和sdd来用作裸设备,一块用于ocr,一块用于votingdisk
bo2dbp:~ # fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-200, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-200, default 200):
Using default value 200

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

2、分区后的结果
bo2dbp:~ # fdisk -l /dev/sdc

Disk /dev/sdc: 209 MB, 209715200 bytes
64 heads, 32 sectors/track, 200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         200      204784   83  Linux
bo2dbp:~ # fdisk -l /dev/sdd

Disk /dev/sdd: 209 MB, 209715200 bytes
64 heads, 32 sectors/track, 200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         200      204784   83  Linux

3、配置裸设备
bo2dbp:~ # vi /etc/raw

# /etc/raw
#
# sample configuration to bind raw devices
# to block devices
#
# The format of this file is:
# raw<N>:<blockdev>
#
# example:
# ———
# raw1:hdb1
#
# this means: bind /dev/raw/raw1 to /dev/hdb1
#
# …

#Add new raw devices
raw1:sdc1
raw2:sdd1

4、启动裸设备
bo2dbp:~ # rcraw start
bind /dev/raw/raw1 to /dev/sdc1…                                    done
bind /dev/raw/raw2 to /dev/sdd1…                                    done

5、配置裸设备随系统启动
bo2dbp:~ # chkconfig raw
raw  on
#修改裸设备的权限与所有者,尽管该操作会修改,但重启之后将失效。永久修改见第7点.检查裸设备是否自动激活: chkconfig –list | grep raw
bo2dbp:~ # chown oracle:dba /dev/raw/raw[1-2]
bo2dbp:~ # chmod 660 /dev/raw/raw[1-2]

6、测试裸设备
bo2dbp:~ # dd if=/dev/zero of=/dev/raw/raw1 bs=1024k count=200
dd: writing `/dev/raw/raw1′: No space left on device
200+0 records in
199+0 records out
209698816 bytes (210 MB) copied, 2.59567 seconds, 80.8 MB/s

7、修改裸设备启动后权限及所有者
#使用root用户修改/etc/udev/rules.d/50-udev-default.rules,确保raw设备的权限GROUP=”dba”, MODE=”660″, OWNER=”oracle”
#将其中包含KENREL==”raw”的记录修改为如下
KERNEL==”raw[0-9]*”, SUBSYSTEM==”raw”, NAME=”raw/%k”, GROUP=”dba”, MODE=”660″, OWNER=”oracle”

8、确认配置成功
#重启之后的状态     #Author :Robinson Cheng  Blog:http://blog.csdn.net/robinson_0612
bo2dbp:~ # ls -hltr /dev/raw
total 0
crw-rw—- 1 root   disk 162, 0 Sep 19 10:22 rawctl
crw-rw—- 1 oracle dba  162, 1 Sep 19 10:22 raw1
crw-rw—- 1 oracle dba  162, 2 Sep 19 10:22 raw2

bo2dbs:~ # /usr/sbin/raw -qa
/dev/raw/raw1:  bound to major 8, minor 33
/dev/raw/raw2:  bound to major 8, minor 49

创建裸设备的方法:

Method 1. Using rawdevices service

Edit the file /etc/sysconfig/rawdevices

$ service rawdevices start
# raw device bindings
# format:  <rawdev> <major> <minor>
#          <rawdev> <blockdev>
# example: /dev/raw/raw1 /dev/sda1
#          /dev/raw/raw2 8 5
/dev/raw/raw1 /dev/hda5
/dev/raw/raw2 /dev/hda6

Note: /dev/raw/raw0 is not allowed because minor number cannot be zero.

Start the rawdevices service

# service rawdevices start
# chkconfig rawdevices on

Method 2. Using udev to configure RAW device

Creating the raw devices using udev:

Nevertheless, to create raw devices, add entries to /etc/udev/rules.d/60-raw.rules in the following formats:

For device names:

ACTION==”add”, KERNEL==”<device name>”, RUN+=”raw /dev/raw/rawX %N”

For major / minor numbers:

ACTION==”add”, ENV{MAJOR}==”A”, ENV{MINOR}==”B”, RUN+=”raw /dev/raw/rawX %M %m”

Note: Replace device name> with the name of the device needed to bind (such as /dev/sda1). “A” and “B” are the major / minor numbers of the device needed for binding, an “X” is the raw device number that the system wants to use.

Creating persistent raw devices for single path LUNs:

If using unpartitioned LUNs, to create a single raw device for the whole LUN use this rule format:

ACTION==”add”, KERNEL==”sd*[!0-9]“, PROGRAM==”/sbin/scsi_id -g -u -s %p”, RESULT==”3600601601bd2180072193a9242c3dc11″, RUN+=”/bin/raw /dev/raw/raw1 %N”

Note: Set the RESULT value to the output of scsi_id -g -u -s /block/sdX (where sdX is the current path to the LUN). This will create the raw device /dev/raw/raw1 that will be persistently bound to the LUN with WWID 3600601601bd2180072193a9242c3dc11.

If using partitioned LUNs, where raw devices are created for each of the partitions on the LUN, use this rule format:

ACTION==”add”, KERNEL==”sd*[0-9]“, PROGRAM==”/sbin/scsi_id -g -u -s %p”, RESULT==”3600601601bd2180072193a9242c3dc11″, RUN+=”/bin/raw /dev/raw/raw%n %N”

Note: Set RESULT to the output of scsi_id -g -u -s /block/sdX. This will create the raw device(s) /dev/raw/raw1, /dev/raw/raw2, etc. for each partition on the LUN and they will be persistently bound to the LUN with WWID 3600601601bd2180072193a9242c3dc11.

Setting ownership and permissions on the raw devices:

To set specific ownership and/or permissions for the raw devices, add entries to /etc/udev/rules.d/60-raw.rules in the following format:

ACTION==”add”, KERNEL==”raw*”, OWNER=”root”, GROUP=”disk”, MODE=”0660″

Testing and implementing the udev rules:

Before implementing them, use the udevtest command to verify the udev rules work as expected. To verify that the raw device is created for a specific disk or partition, eg /dev/sdb1:

[root@rhel5 rules.d]# udevtest /block/sdb/sdb1 | grep raw
main: run: ‘/bin/raw /dev/raw/raw1 /dev/.tmp-8-17′

To check ownership/permission settings for a particular raw device, eg. /dev/raw/raw1:

[root@rhel5 rules.d]# udevtest /class/raw/raw1 | grep mode
udev_node_add: creating device node ‘/dev/raw/raw1′, major = ’162′, minor = ’1′, mode = ’0600′, uid = ’0′, gid = ’0′

Finally, to actually create the raw device(s), use the start_udev command:

[root@rhel5 rules.d]# start_udev
Starting udev:                                             [  OK  ]

Check that the raw device(s) have been created:

[root@rhel5 rules.d]# raw -qa
/dev/raw/raw1:  bound to major 8, minor 17
[root@rhel5 rules.d]# ls -l /dev/raw
total 0
crw-rw—- 1 root   disk 162,  1 Jan 29 02:47 raw1

Creating persistent raw devices for multipathed LUNs or LVM device:

Unfortunately it is not possible to write udev rules for creating raw devices on multipath devices (/dev/dm-*) without manipulating existing udev rules. Modifying existing rules for this purpose could cause unforeseen problems and is not supported by Red Hat Global Support Services. If absolutely necessary, an alternate method for creating raw devices on top of multipath devices could be to create the raw devices in /etc/rc.d/rc.local, so long as the raw device is not required before rc.local is executed. For example:

/bin/raw /dev/raw/raw1 /dev/mpath/mpath1p1
/bin/raw /dev/raw/raw2 /dev/mpath/mpath1p2
/bin/chmod 660 /dev/raw/raw1
/bin/chown root:disk /dev/raw/raw1
/bin/chmod 660 /dev/raw/raw2
/bin/chown root:disk /dev/raw/raw2

If absolutely want to create raw devices for multipathed LUNs or LVM device using udev, can add the following udev rules in the file /etc/udev/rules.d/60-raw.rules

# Device mapper raw rules
KERNEL!=”dm-[0-9]*”, GOTO=”skip_dm”
ACTION!=”change”, GOTO=”skip_dm”
PROGRAM!=”/sbin/dmsetup ls –exec /bin/basename -j %M -m %m”, GOTO=”skip_dm”
RESULT==”mpath2″, RUN+=”/bin/raw /dev/raw/raw2 /dev/mapper/mpath2″
RESULT==”mpath1″, RUN+=”/bin/raw /dev/raw/raw1 /dev/mapper/mpath1″
LABEL=”skip_dm”
KERNEL==”raw1″, ACTION==”add”, OWNER=”root”, GROUP=”disk”, MODE=”0660″
KERNEL==”raw2″, ACTION==”add”, OWNER=”root”, GROUP=”disk”, MODE=”0660″

[root@cnrac7 ~]# date; fdisk -l; date
Wed May  4 17:08:22 EDT 2011
 
Disk /dev/sda: 24.6 GB, 24696061952 bytes
255 heads, 63 sectors/track, 3002 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3002    24009142+  8e  Linux LVM
 
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
Disk /dev/sdd: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
 
Disk /dev/sde: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
Wed May  4 17:08:23 EDT 2011

Create partition tables on /dev/sdb, /dev/sdc, /dev/sdd and /dev/sde:

[root@cnrac7 ~]# fdisk /dev/sdb
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):
Using default value 130
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@cnrac7 ~]# fdisk /dev/sdc
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130):
Using default value 130
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@cnrac7 ~]# fdisk /dev/sdd
 
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@cnrac7 ~]# fdisk /dev/sde
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652):
Using default value 652
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.

Now we have following partition tables:

[root@cnrac7 ~]# date; fdisk -l; date
Wed May  4 17:20:48 EDT 2011
 
Disk /dev/sda: 24.6 GB, 24696061952 bytes
255 heads, 63 sectors/track, 3002 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        3002    24009142+  8e  Linux LVM
 
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  83  Linux
 
Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         130     1044193+  83  Linux
 
Disk /dev/sdd: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        1305    10482381   83  Linux
 
Disk /dev/sde: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1         652     5237158+  83  Linux
Wed May  4 17:20:48 EDT 2011

We will create raw devices using these partitions.

Add udev raw devices binding rules to /etc/udev/rules.d/60-raw.rules:

[root@cnrac7 ~]# date; cat /etc/udev/rules.d/60-raw.rules; date
Wed May  4 17:25:38 EDT 2011
# This file and interface are deprecated.
# Applications needing raw device access should open regular
# block devices with O_DIRECT.
#
# 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=="sdb1", RUN+="/bin/raw /dev/raw/raw1 %N"
ACTION=="add", KERNEL=="sdc1", RUN+="/bin/raw /dev/raw/raw2 %N"
ACTION=="add", KERNEL=="sdd1", RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", KERNEL=="sde1", RUN+="/bin/raw /dev/raw/raw4 %N"
Wed May  4 17:25:39 EDT 2011

Add udev raw device permission rules to /etc/udev/rules.d/65-raw-permissions.rules:

[root@cnrac7 ~]# date; cat /etc/udev/rules.d/65-raw-permissions.rules; date
Wed May  4 17:33:35 EDT 2011
# Set permissions of raw bindings to Oracle Clusterware devices
KERNEL=="raw1", OWNER="ora112", GROUP="oinstall", MODE="640"
KERNEL=="raw2", OWNER="ora112", GROUP="oinstall", MODE="640"
KERNEL=="raw3", OWNER="ora112", GROUP="oinstall", MODE="640"
KERNEL=="raw4", OWNER="ora112", GROUP="oinstall", MODE="640"
Wed May  4 17:33:35 EDT 2011

Now restart udev:

[root@cnrac7 ~]# date; start_udev; date
Wed May  4 17:37:46 EDT 2011
Starting udev: [  OK  ]
Wed May  4 17:37:59 EDT 2011

Check raw devices:

[root@cnrac7 ~]# date; raw -qa; ls -l /dev/raw/raw*; date
Wed May  4 17:38:12 EDT 2011
/dev/raw/raw1:  bound to major 8, minor 17
/dev/raw/raw2:  bound to major 8, minor 33
/dev/raw/raw3:  bound to major 8, minor 49
/dev/raw/raw4:  bound to major 8, minor 65
crw-r----- 1 ora112 oinstall 162, 1 May  4 17:37 /dev/raw/raw1
crw-r----- 1 ora112 oinstall 162, 2 May  4 17:37 /dev/raw/raw2
crw-r----- 1 ora112 oinstall 162, 3 May  4 17:37 /dev/raw/raw3
crw-r----- 1 ora112 oinstall 162, 4 May  4 17:37 /dev/raw/raw4
Wed May  4 17:38:12 EDT 2011

Using Raw Devices for Oracle Databases

The rawdevices service can only initialize devices named according to the /dev/raw/rawN format. However, devices in this location do not have the correct ownership or permissions for an Oracle database file by default. Additionally, because these device names are owned by the dev package, each time the package is updated (for example, as part of an operating system update), all devices are recreated with the default ownership and permissions at boot. It is therefore necessary to set ownership and permissions each time the dev package is updated.

Procedure 13.1. Configure a raw device

  1. Configure the desired device in the /etc/sysconfig/rawdevices file:
    /dev/raw/raw1 	/dev/sdb1
  2. Start and enable the device by running:
    # service rawdevices start
    # chkconfig rawdevices on
At this point, you could set ownership and permissions with chmod and chown. However, because these devices will be created dynamically at boot time, permissions set in this manner will not persist after a reboot.

Procedure 13.2. Configure persistent ownership and permissions

  1. To set specific ownership and/or permissions for the raw devices, add entries to /etc/udev/rules.d/60-raw.rules in the following format:
    ACTION=="add", KERNEL=="raw*", OWNER="root", GROUP="disk", MODE="0660"
  2. Test that the permissions you applied work as intended with udevtest:
    # udevtest /block/sdb/sdb1 | grep raw
     main: run: '/bin/raw /dev/raw/raw1 /dev/.tmp-8-17'
    To test the ownership of a specific device, such as /dev/raw/raw1, use:
    # udevtest /class/raw/raw1 | grep mode
     udev_node_add: creating device node '/dev/raw/raw1', major = '162', minor = '1', mode = '0600', uid = '0', gid = '0'
  3. Run the following command to activate the udev rules:
    # start_udev

发表评论