redhat 5下增加裸设备

1.关闭系统,在虚拟机上创建两块1G的硬盘

2.启动虚拟机,查看磁盘情况

[root@hxy ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table
[root@hxy ~]# 

3.格式化磁盘

[root@hxy ~]# fdisk /dev/sdb
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): 1
First cylinder (1-261, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): 
Using default value 261

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@hxy ~]# 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): 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@hxy ~]# 

查看格式化后的磁盘

[root@hxy ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         261     2096451   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
[root@hxy ~]# 

4.修改/etc/udev/rules.d/60-raw.rules文件

由于RHEL5中取消了rawdevices,如果不想将映射命令放到rc.local中的话,我们就需要将其配置到/etc/udev/rules.d/文件夹中
修改文件

[root@hxy ~]# vi /etc/udev/rules.d/60-raw.rules 
在文件中加入
ACTION=="add", KERNEL=="/dev/sdb1",RUN+="/bin/raw/dev/raw/raw1 %N"
ACTION=="add", ENV{MAJOR}=="8",ENV{MINOR}=="17",RUN+="/bin/raw /dev/raw/raw1 %M %m"
ACTION=="add", KERNEL=="/dev/sdc1",RUN+="/bin/raw/dev/raw/raw2 %N"
ACTION=="add", ENV{MAJOR}=="8",ENV{MINOR}=="33",RUN+="/bin/raw/dev/raw/raw2 %M %m"
KERNEL=="raw[1-2]", OWNER="oracle", GROUP="oinstall", MODE="640"
说明:/dev/sdb1,/dev/sdc1为需要绑定的设备名称  /dev/raw/raw1,/dev/raw/raw2为指定到的裸设备名
ENV{MAJOR}=="8",ENV{MINOR}=="17":设置裸设备的主次号码(可选)
若需要把设定裸设备的用户和用户组需要加入
把设备raw1的权限付给oracle
KERNEL=="raw1", OWNER="oracle", GROUP="oinstall", MODE="640"
如下为把多个裸设备一起赋给oracle
KERNEL=="raw[1-2]", OWNER="oracle", GROUP="oinstall", MODE="640"
保存!!!退出!!!

5.重启服务

[root@hxy ~]# start_udev
Starting udev: [  OK  ]

6.验证

[root@hxy ~]# ls /dev/raw -l
total 0
crw-r----- 1 oracle oinstall 162, 1 Feb 24 15:18 raw1
crw-r----- 1 oracle oinstall 162, 2 Feb 24 15:18 raw2

查询绑定的裸设备的主次号:
[root@hxy ~]# raw -aq
/dev/raw/raw1:  bound to major 8, minor 17
/dev/raw/raw2:  bound to major 8, minor 33
裸设备配置完成!可以建立 ASM了!

7.取消映射

如果要取消映射
这把刚才
ACTION=="add", ENV{MAJOR}=="8",ENV{MINOR}=="17",RUN+="/bin/raw /dev/raw/raw1 %M %m"
中设置的major and minor设置为0即可!也就是通过命令raw -aq查出的主次号
[root@hxy ~]# raw /dev/raw/raw1 0 0
/dev/raw/raw1:  bound to major 0, minor 0
再次查看,只剩下raw2了
[root@hxy ~]# ls /dev/raw -l
total 0
crw-r----- 1 oracle oinstall 162, 2 Feb 24 15:18 raw2

8.重新映射

再次设置回原来的值即可
[root@hxy ~]# raw /dev/raw/raw1 8 17
/dev/raw/raw1:  bound to major 8, minor 17
[root@hxy ~]# ls /dev/raw -l
total 0
crw-r----- 1 oracle oinstall 162, 1 Feb 24 15:30 raw1
crw-r----- 1 oracle oinstall 162, 2 Feb 24 15:18 raw2


redhat4以前下增加裸设备配置ASM参考

Raw Device Setup

This step is only necessary if you want ASM to access the disks as raw devices.

Edit the "/etc/sysconfig/rawdevices" file, adding the following lines.

/dev/raw/raw1 /dev/sdb1
/dev/raw/raw2 /dev/sdc1
/dev/raw/raw3 /dev/sdd1

Restart the rawdevices service using the following command.

service rawdevices restart
但是在Oracle Linux 5.6上也可以使用以上方法添加

你可能感兴趣的:(redhat 5下增加裸设备)