Redhat 5 中裸裝置(raw) 的配置

us_yunleiwang發表於2013-12-05

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="", RUN+="/bin/raw /dev/raw/rawX %N"
主/次號碼:
ACTION=="add", ENV{MAJOR}="A", ENV{MINOR}="B", RUN+="/bin/raw /dev/raw/rawX %M %m"

用你需要繫結的裝置名稱替換 (如:/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使用

 

 

檢視結果:

[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   

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23490154/viewspace-1062353/,如需轉載,請註明出處,否則將追究法律責任。

相關文章