在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" 是设备的主/次号码,X 是系统使用的 raw 设备号码。在设置的时候,主次号码是可选的。 如果不指定,默认从1,1开始,
如:/dev/raw/raw1: bound to major 1, minor 1
现在我们把/dev/sdb1 知道到raw1上,就可以在/etc/udev/rules.d/60-raw.rules文件里添加如下内容: