在Linux上使用raw device方式

ysping發表於2009-08-05

在Linux上使用raw device方式

在Linux上使用raw device一般有兩個方式,下面分別測試一下:

第一種方式是非lvm方式,直接使用partion方式如下:

一,建立分割槽
[root@localhost ~]# fdisk -l

[@more@]

Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 514048+ 83 Linux
/dev/sda2 65 1174 8916075 83 Linux
/dev/sda3 1175 1435 2096482+ 82 Linux swap
/dev/sda4 1436 1566 1052257+ 5 Extended
/dev/sda5 1436 1566 1052226 83 Linux

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

Disk /dev/sdc: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table
[root@localhost oracle]# fdisk /dev/sdb


The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): n p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1): 65
Last cylinder or +size or +sizeM or +sizeK (65-1044, default 1044):
Using default value 1044

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 65 1044 7871850 83 Linux

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 65 1044 7871850 83 Linux

Command (m for help): h
h: unknown command
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
1 p
Partition number (1-4): 1
First cylinder (1-1044, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044): 65

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (66-1044, default 66):
Using default value 66
Last cylinder or +size or +sizeM or +sizeK (66-1044, default 1044): 130

Command (m for help): n
Command action
e extended
p primary partition (1-4)
3
Invalid partition number for type `3'
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (131-1044, default 131):
Using default value 131
Last cylinder or +size or +sizeM or +sizeK (131-1044, default 1044): 196

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (197-1044, default 197): 4
Value out of range.
First cylinder (197-1044, default 197):
Using default value 197
Last cylinder or +size or +sizeM or +sizeK (197-1044, default 1044): 262

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 65 522081 83 Linux
/dev/sdb2 66 130 522112+ 83 Linux
/dev/sdb3 131 196 530145 83 Linux
/dev/sdb4 197 262 530145 83 Linux

二,繫結raw device
[root@localhost oracle]# raw /dev/raw/raw1 /dev/sdb1
/dev/raw/raw1: bound to major 8, minor 18
[root@localhost oracle]# raw /dev/raw/raw2 /dev/sdb2
/dev/raw/raw2: bound to major 8, minor 18
[root@localhost oracle]# raw /dev/raw/raw3 /dev/sdb3
/dev/raw/raw3: bound to major 8, minor 18
[root@localhost oracle]# raw /dev/raw/raw4 /dev/sdb4
/dev/raw/raw4: bound to major 8, minor 18
[root@localhost oracle]#vi /etc/sysconfig/rawdevices
在檔案中加入如下內容:
/dev/raw/raw1 /dev/sdb1
/dev/raw/raw2 /dev/sdb2
/dev/raw/raw3 /dev/sdb4
/dev/raw/raw4 /dev/sdb4
另執行 /etc/init.d/rawdevices restart 使配置檔案中的裸裝置生效,執行 /sbin/chkconfig rawdevices on 保證機器啟動的時候裸裝置能夠載入。

三,授權
[root@localhost oracle]# chown -R oracle:dba /dev/raw/raw1
[root@localhost oracle]# chown -R oracle:dba /dev/raw/raw2
[root@localhost oracle]# chown -R oracle:dba /dev/raw/raw3
[root@localhost oracle]# chown -R oracle:dba /dev/raw/raw4
另修改配置檔案/etc/udev/permissions.d/50-udev.permissions
註釋掉raw/*:root:disk:0660,新增新行raw/*:oracle:dba:0660
此時,如繫結raw device,則預設許可權為oracle:dba了。
--另如需要可以進行相應連結,
如ln -s /dev/raw/raw1 /u1/oracle/oradata/test10g/test_raw1.dbf,然後可以直接為oracle所用了。


另一種是lvm的方式,測試如下:
一,建立pv
[root@localhost ~]# pvcreate -M2 --metadatasize 100M /dev/sdb7 /dev/sdb8 /dev/sdb9 /dev/sdb10 /dev/sdc
Physical volume "/dev/sdb7" successfully created
Physical volume "/dev/sdb8" successfully created
Physical volume "/dev/sdb9" successfully created
Physical volume "/dev/sdb10" successfully created
Physical volume "/dev/sdc" successfully created
[root@localhost ~]# lvmdiskscan
/dev/ramdisk [ 16.00 MB]
/dev/ram [ 16.00 MB]
/dev/sda1 [ 502.00 MB]
/dev/ram2 [ 16.00 MB]
/dev/root [ 8.50 GB]
/dev/ram3 [ 16.00 MB]
/dev/sda3 [ 2.00 GB]
/dev/ram4 [ 16.00 MB]
/dev/ram5 [ 16.00 MB]
/dev/sda5 [ 1.00 GB]
/dev/ram6 [ 16.00 MB]
/dev/ram7 [ 16.00 MB]
/dev/ram8 [ 16.00 MB]
/dev/ram9 [ 16.00 MB]
/dev/ram10 [ 16.00 MB]
/dev/ram11 [ 16.00 MB]
/dev/ram12 [ 16.00 MB]
/dev/ram13 [ 16.00 MB]
/dev/ram14 [ 16.00 MB]
/dev/ram15 [ 16.00 MB]
/dev/sdb1 [ 980.50 MB]
/dev/sdb2 [ 980.53 MB]
/dev/sdb3 [ 1.92 GB]
/dev/sdb5 [ 509.84 MB]
/dev/sdb6 [ 549.07 MB]
/dev/sdb7 [ 509.84 MB] LVM physical volume
/dev/sdb8 [ 509.84 MB] LVM physical volume
/dev/sdb9 [ 549.07 MB] LVM physical volume
/dev/sdb10 [ 627.51 MB] LVM physical volume
/dev/sdb11 [ 1011.88 MB]
/dev/sdc [ 8.00 GB] LVM physical volume
3 disks
23 partitions
1 LVM physical volume whole disk
4 LVM physical volumes

二,建立vg
[root@localhost ~]# vgcreate vg_db1 /dev/sdc -s 128m
Volume group "vg_db1" successfully created
[root@localhost ~]# vgcreate vg_db2 /dev/sdc -s 128m
Volume group "vg_db2" successfully created

三,建立lv
[root@localhost ~]# lvcreate -L 512m -I 64k vg_db2 -n lv_db2_02
Ignoring stripesize argument with single stripe
Logical volume "lv_db2_02" created
[root@localhost ~]# lvcreate -L 1024m -I 64k vg_db2 -n lv_db2_03
Ignoring stripesize argument with single stripe
Logical volume "lv_db2_03" created
[root@localhost ~]# lvcreate -L 512m -I 64k vg_db2 -n lv_db2_04
Ignoring stripesize argument with single stripe
Logical volume "lv_db2_04" created
[root@localhost ~]# lvcreate -L 2048m -I 64k vg_db2 -n lv_db2_05
Ignoring stripesize argument with single stripe
Logical volume "lv_db2_05" created

四,繫結
[root@localhost ~]# raw /dev/raw/raw1 /dev/mapper/vg_db2-lv_db2_01
/dev/raw/raw4: bound to major 253, minor 5
[root@localhost ~]# raw /dev/raw/raw2 /dev/mapper/vg_db2-lv_db2_02
/dev/raw/raw4: bound to major 253, minor 5
[root@localhost ~]# raw /dev/raw/raw3 /dev/mapper/vg_db2-lv_db2_03
/dev/raw/raw4: bound to major 253, minor 5
[root@localhost ~]# raw /dev/raw/raw4 /dev/mapper/vg_db2-lv_db2_04
/dev/raw/raw4: bound to major 253, minor 5
後面授權等作業和第一種方式類同,上面要注意的是lv的命名方式,命名方式分解如下:
/dev/mapper/+ vgname + '-' + lvname.

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

相關文章