linux下配置裸设备

检查在机器中是否可以看到刚刚添加的虚拟盘:

[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 ~]#

发表评论

电子邮件地址不会被公开。