旅途

如果想飞得高,就该把地平线忘掉

linux创建裸设备和oracle使用裸设备

1.裸设备:

未分区的硬盘(独立的),未被格式化的分区(包括主分区和逻辑分区)

2.测试,创建裸设备

-bash-3.00# fdisk -l

Disk /dev/sda: 160.0 GB, 160000000000 bytes
255 heads, 63 sectors/track, 19452 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        7662    61440592+  83  Linux
/dev/sda3            7663       14036    51199155   83  Linux
/dev/sda4           14037       19452    43504020    5  Extended
/dev/sda5           14037       14673     5116671   83  Linux
/dev/sda6           14674       15310     5116671   83  Linux
/dev/sda7           15311       15947     5116671   83  Linux
/dev/sda8           15948       16339     3148708+  83  Linux
/dev/sda9           16340       16466     1020096   83  Linux
/dev/sda10          16467       19016    20482843+  83  Linux
/dev/sda11          19017       19079      506016   83  Linux
/dev/sda12          19080       19141      497983+  83  Linux
-bash-3.00# fdisk /dev/sda

The number of cylinders for this disk is set to 19452.
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)

Command (m for help): n
First cylinder (19142-19452, default 19142):
Using default value 19142
Last cylinder or +size or +sizeM or +sizeK (19142-19452, default 19452): +512M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

-bash-3.00# reboot

Broadcast message from root (pts/2) (Sun Nov  2 21:54:12 2008):

The system is going down for reboot NOW!

-bash-3.00# raw /dev/raw/raw3 /dev/sda13
/dev/raw/raw3:  bound to major 8, minor 13

3.修改属主和权限

-bash-3.00# chown oracle10:oracle10 /dev/raw/raw3
-bash-3.00# chmod 777 /dev/raw/raw3
-bash-3.00# ls -l /dev/raw/raw3
crwxrwxrwx  1 oracle10 oracle10 162, 3 Nov  2 21:59 /dev/raw/raw3

4.oracle添加裸设备为数据文件(或redo log)

SQL> alter tablespace space_test add datafile '/dev/raw/raw3' size 400M;
Tablespace altered.

SQL> select name from v$datafile;

NAME
------------------------------------------------------------------------------------------------------------------------------------------------------
/work/oracle10/oracle/oradata/oracle10/system01.dbf
/work/oracle10/oracle/oradata/oracle10/space_test.dbf
/work/oracle10/oracle/oradata/oracle10/sysaux01.dbf
/work/oracle10/oracle/oradata/oracle10/users01.dbf
/work/oracle10/oracle/oradata/oracle10/example01.dbf
/work/oracle10/oracle/oradata/oracle10/dsgtest_part.dbf
/work/oracle10/oracle/oradata/oracle10/dsgtest_part_01.dbf
/work/oracle10/oracle/oradata/oracle10/undotbs02.db
/dev/raw/raw3

9 rows selected.

SQL>

证明裸设备和文件系统可以共存。

日志文件同理也可以创建,同时可以创建这样形式的裸设备日志文件

SQL> select member from v$logfile;

MEMBER
------------------------------------------------------------------------------------------------------------------------------------------------------
/work/oracle10/oracle/oradata/oracle10/redo03.log
/work/oracle10/oracle/oradata/oracle10/redo02.log
/work/oracle10/oracle/oradata/oracle10/redo01.log
/work/oracle10/oracle/oradata/oracle10/redo04

SQL> !ls -l /work/oracle10/oracle/oradata/oracle10/redo04
lrwxrwxrwx  1 root root 13 Nov  2 18:43 /work/oracle10/oracle/oradata/oracle10/redo04 -> /dev/raw/raw1

4.插曲:

1.reboot之后发现找不到/dev/raw/raw3,修改/etc/sysconfig/rawdevices

添加:

# Applications needing raw device access should open regular
# block devices with O_DIRECT.
# raw device bindings
# format:  <rawdev> <major> <minor>
#          <rawdev> <blockdev>
# example: /dev/raw/raw1 /dev/sda1
#          /dev/raw/raw2 8 5
/dev/raw/raw3 /dev/sda13

2.reboot之后提示找不到刚创建的裸设备形式的数据文件,查看裸设备挂载的块设备,发现权限被改成root,修改成oracle10:oracle10之后,数据库就可以open了

vi /etc/udev/permissions.d/50-udev.permissions

# raw devices
ram*:root:disk:0660
raw/*:oracle10:oracle10:0777

再重启,权限就没问题了

5.思考

查资料发现linux的裸设备需要指到一个块设备上(/dev/raw/raw*),而unix并不需要这一步

裸设备是一种字符设备(character device),不需要操作系统缓冲就可以直接读写,可以提高效率

另一种是块设备(block device),需要操作系统缓冲,可以mount文件系统

ls -l /dev/sd*

brw-rw----  1 root disk 8, 11 Nov  3  2008 /dev/sda11
brw-rw----  1 root disk 8, 12 Nov  3  2008 /dev/sda12
brw-rw----  1 root disk 8, 13 Nov  3  2008 /dev/sda13

[oracle10@rhel4 dev]$ ls -l /dev/raw/*
crwxrwxrwx  1 oracle10 oracle10 162, 1 Nov  2 22:31 /dev/raw/raw1
crwxrwxrwx  1 oracle10 oracle10 162, 3 Nov  2 22:31 /dev/raw/raw3

我的理解是,linux本身把为未格式化的分区当作块设备,然后通过连接(raw /dev/raw/raw3 /dev/sda13),当成c设备来用,而unix不需要这一步,直接就是字符设备,这个不确定~

posted on 2009-09-30 00:20 旅途 阅读(2729) 评论(0)  编辑 收藏 引用 所属分类: LINUX基础、管理


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理