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"
那麼就會顯示我們指定的Majorminor
[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   
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章