Redhat 5 中裸设备(raw) 的配置


 

 

Redhat 5 之前的版本中,系统通过/etc/sysconfig/rawdevices配置raw的控制文件,通过/etc/init.d/rawdevices来管理raw设备的启动和关闭。而在Redhat 5之后,原来的raw设备接口已经取消了,redhat 5中通过udev规则进行配置。 要配置,需要编辑/etc/udev/rules.d/60-raw.rules 这个文件。

 

 

 

下面给出一个添加raw设备的测试过程。

 

1.现在虚拟机上添加一个硬盘。 我们仅做测试,所以分10M

 

 

 

2. 启动我们的虚拟机,连上后查看磁盘情况

[root@centos ~]# fdisk -l

Disk /dev/sda: 16.1 GB, 16106127360 bytes

255 heads, 63 sectors/track, 1958 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *         201        1958    14121135   83  Linux

/dev/sda2               1         200     1606468+  82  Linux swap / Solaris

Partition table entries are not in disk order

 

Disk /dev/sdb: 10 MB, 10485760 bytes

64 heads, 32 sectors/track, 10 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

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

 

这里的/dev/sdb 因为是刚加上来的硬盘,还没有格式化。

 

 

 

3. 格式化/dev/sdb

[root@centos ~]# 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-10, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-10, default 10):

Using default value 10

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

 

查看格式化之后的硬盘情况:

[root@centos ~]# fdisk -l

 

Disk /dev/sda: 16.1 GB, 16106127360 bytes

255 heads, 63 sectors/track, 1958 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *         201        1958    14121135   83  Linux

/dev/sda2               1         200     1606468+  82  Linux swap / Solaris

 

Partition table entries are not in disk order

Disk /dev/sdb: 10 MB, 10485760 bytes

64 heads, 32 sectors/track, 10 cylinders

Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1          10       10224   83  Linux

[root@centos ~]#

 

 

 

 

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

[root@centos ~]# more /etc/udev/rules.d/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="<device name>", RUN+="/bin/raw /dev/raw/rawX %N"
主/次号码:
ACTION=="add", ENV{MAJOR}="A", ENV{MINOR}="B", RUN+="/bin/raw /dev/raw/rawX %M %m"

用你需要绑定的设备名称替换 <device name>(如:/dev/sda1)。"A" 和 "B" 是设备的主/次号码,是系统使用的 raw 设备号码。在设置的时候,主次号码是可选的。 如果不指定,默认从11开始,

如:/dev/raw/raw1:  bound to major 1, minor 1

 

 

现在我们/dev/sdb1 知道到raw1上,就可以在/etc/udev/rules.d/60-raw.rules文件里添加如下内容:

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

 


5. 重启服务:
[root@centos ~]# start_udev

Starting udev:             [  OK  ]

 


6. 查看raw设备:
[root@centos ~]# ls -lrt /dev/raw

 

total 0

crw------- 1 root root 162, 1 Aug  8 06:56 raw1

[root@centos ~]# raw -aq

/dev/raw/raw1:  bound to major 1, minor 1

 

如果我们添加了下面的语句:

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

那么就会显示我们指定的Major和minor

[root@centos ~]# ls -lrt /dev/raw

total 0

crw-rw---- 1 dave tianlesoftware 162, 1 Aug  8 08:06 raw1

[root@centos ~]# raw -aq

/dev/raw/raw1:  bound to major 8, minor 1

 

 

 

 

 

7. 设置raw设备的用户和权限信息

 

/etc/udev/rules.d/60-raw.rules文件里添加如下信息:

ACTION=="add", KERNEL=="raw1", OWNER="dave", GROUP="tianlesoftware", MODE="660"

如果有多个raw设备,可以写成:

ACTION=="add", KERNEL=="raw[1-4]", OWNER="dave", GROUP="tianlesoftware", MODE="660"

 

 

Oracle 中使用raw设备时,如果裸设备对应的属组不是oracle,裸设备将无法供oracle使用

 

 

查看结果:

[root@centos ~]# start_udev

Starting udev:                                  [  OK  ]

[root@centos ~]# ls -lrt /dev/raw

total 0

crw-rw---- 1 dave tianlesoftware 162, 1 Aug  8 06:59 raw1

[root@centos ~]# raw -aq

/dev/raw/raw1:  bound to major 1, minor 1

 

 

 

8. 取消raw 映射

把major and minor设成0,就可以取消裸设备的绑定。

[root@rac1 mapper]# raw /dev/raw/raw9 0 0   

from:http://blog.csdn.net/tianlesoftware/article/details/5796962

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值