linux下配置裸裝置

eric0435發表於2012-11-08
檢查在機器中是否可以看到剛剛新增的虛擬盤:

[root@jyrac1 ~]# 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: 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

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

Disk /dev/sdd: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sde: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
通過fdisk -l可以看看所有磁碟的狀態,如果前期裸裝置規劃正確的話,在諸如/dev/sdb、/dev/sdc、/dev/sdd、/dev/sde下面是看不到任何分割槽資訊的,這也表明這些磁碟都是乾淨的磁碟,不像/dev/sda那樣不乾淨(有了檔案系統)。下面我們要對/dev/sdb到/dev/sde的四塊磁碟進行分割槽,分割槽過程如下圖所示(這裡以/dev/sdb為例,其他磁碟操作類似):

磁碟分割槽
需要你輸入的依次是"n/p/1/回車/回車/w"。
[root@jyrac1 ~]# fdisk /dev/sdb

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@jyrac1 ~]#

所有磁碟分割槽完後
[root@jyrac1 ~]# 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: 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/sdb1               1         130     1044193+  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

Disk /dev/sdd: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1        3916    31455238+  83  Linux

Disk /dev/sde: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1        3916    31455238+  83  Linux
[root@jyrac1 ~]#

檢查分割槽的結果:
[root@jyrac1 linux_5.4_asmlib]# cat /proc/partitions
major minor  #blocks  name

   8     0   20971520 sda
   8     1     104391 sda1
   8     2   20860402 sda2
   8    16    1048576 sdb
   8    17    1044193 sdb1
   8    32    1048576 sdc
   8    33    1044193 sdc1
   8    48   31457280 sdd
   8    49   31455238 sdd1
   8    64   31457280 sde
   8    65   31455238 sde1
 253     0   18743296 dm-0
 253     1    2097152 dm-10
[root@racnode1 root]#
編輯/etc/udev/rules.d/60-raw.rules配置檔案
#vi  /etc/udev/rules.d/60-raw.rules
載入裸裝置,新增以下內容
1)設定分割槽與RAW對應關係
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"
ACTION=="add", KERNEL=="/dev/sdd1",RUN+="/bin/raw /dev/raw/raw3 %N"
ACTION=="add", ENV{MAJOR}=="8",ENV{MINOR}=="49",RUN+="/bin/raw /dev/raw/raw3 %M %m"
ACTION=="add", KERNEL=="/dev/sde1",RUN+="/bin/raw /dev/raw/raw4 %N"
ACTION=="add", ENV{MAJOR}=="8",ENV{MINOR}=="65",RUN+="/bin/raw /dev/raw/raw4 %M %m"
KERNEL=="raw[1-4]", WNER="oracle", GROUP="oinstall", MODE="640"

2)設定RAW的許可權
ACTION=="add", KERNEL=="raw1", WNER="root", GROUP="oinstall", MODE="640"
ACTION=="add", KERNEL=="raw2", WNER="oracle", GROUP="oinstall", MODE="660"

 如果多個RAW的許可權相同可以做以下設定,如raw1,raw2許可權相同:
ACTION=="add", KERNEL=="raw[1-2]", WNER="oracle", GROUP="oinstall", MODE="660"



3.重啟服務
 #start_udev
[root@jyrac1 ~]# start_udev
Starting udev:   [  OK  ]
4.檢視raw裝置
ls /dev/raw/ -l

#ls -lrt /dev/raw 或者
#raw -aq
[root@jyrac1 ~]# ls /dev/raw/ -l
total 0
crw-r----- 1 oracle oinstall 162, 1 Nov  8 15:41 raw1
crw-r----- 1 oracle oinstall 162, 2 Nov  8 15:41 raw2
crw-r----- 1 oracle oinstall 162, 3 Nov  8 15:41 raw3
crw-r----- 1 oracle oinstall 162, 4 Nov  8 15:41 raw4
[root@jyrac1 ~]# ls -lrt /dev/raw
total 0
crw-r----- 1 oracle oinstall 162, 4 Nov  8 15:41 raw4
crw-r----- 1 oracle oinstall 162, 3 Nov  8 15:41 raw3
crw-r----- 1 oracle oinstall 162, 1 Nov  8 15:41 raw1
crw-r----- 1 oracle oinstall 162, 2 Nov  8 15:41 raw2
[root@jyrac1 ~]# raw -aq
/dev/raw/raw1:  bound to major 8, minor 17
/dev/raw/raw2:  bound to major 8, minor 33
/dev/raw/raw3:  bound to major 8, minor 49
/dev/raw/raw4:  bound to major 8, minor 65
[root@jyrac1 ~]#

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

相關文章