linux下裸设备的使用-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务

来源:百度文库 编辑:神马文学网 时间:2024/04/28 05:36:02
一个裸设备(裸分区)只能有一个数据文件
一个表空间能有多个裸设备(裸分区)组成
我的归纳
1、裸设备定义:
一块没有分区的硬盘,称为原始设备(RAW DEVICE)
或是个分区,不过没有用EXT3,OCFS等文件系统格式化,称为原始分区(RAW PARTITION)
以上两者都是裸设备
2、裸设备的绑定
有文件系统的分区是采用mount的方式挂载到某一个挂载点的(目录)
而裸设备不能mount,只能绑定到/dev/raw/下的某一个设备名
比如/dev/raw/raw1
3、裸设备的绑定方法
有两种方法,这里介绍一种,另一种能google搜索到
修改/etc/sysconfig/rawdevices,添加以下内容,
这里sdd1和sdd2是原始分区名或原始设备(硬盘)名,
raw1和raw2是/dev目录下的原始设备名,编号从raw1到raw255,也就是最多能绑定255个裸设备
/dev/raw/raw1 /dev/sdd1
/dev/raw/raw2 /dev/sdd2
然后修改裸设备的属主和访问权限
chown oracle:dba /dev/raw/raw1
chown oracle:dba /dev/raw/raw2
chmod 660 /dev/raw/raw1
chmod 660 /dev/raw/raw2
最后使得裸设备生效,并且在机器启动的时候就自动加载
执行 /etc/init.d/rawdevices restart 使裸设备生效
执行 /sbin/chkconfig rawdevices on 确保机器启动的时候裸设备能够加载,这一步非常重要
4、裸设备的读写
不能用cp等命令操作,写入内容用dd命令,能参阅相关资料
5、清空裸设备,相当于格式化啦bs是快的大小,block size
count是快的数量,这两者相乘大于裸设备的容量即可
dd if=/dev/zero of=/dev/raw/raw1 bs=8192 count=12800
dd if=/dev/zero of=/dev/raw/raw2 bs=8192 count=12800
-------
另外
rhel4使用udev来管理设备
手动修改/dev/raw/raw1 不能永久生效
要想使得权限持久生效
需要修改文件/etc/udev/permissions.d/50-udev.permissions 的第113行
raw/*:root:disk:0660
改成
raw/*

racle:dba:0660
重启机器
如果/dev/下没有 /raw/ 目录,能自己手工建立
参考:metalink Note:224302.1
全文如下:
FAQ Details
Q:  1. What is a raw device?
A:Raw device, also known as a raw partition is a disk partition that is not mounted and written by Linux filesystem (ext2/ext3, reiserfs) or by Oracle Cluster File System (OCFS, OCFS2), but is accessed by a character device driver. It is the responsibility of the application to organize how the data is written to the disk partition.
[top]
Q:  2. How can a raw device be recognised?
A:All hardware devices look like regular files; they can be opened, closed, read and written using the same, standard, system calls that are used to manipulate files. Every device in the system is represented by a device special file, for example the first IDE disk in the system is represented by /dev/hda. For block (disk) and character devices, these device special files are created by the mknod command and they describe the device using major and minor device numbers.
All devices controlled by the same device driver have a common major device number.
The minor device numbers are used to distinguish between different devices and their controllers, for example each partition on the primary IDE disk has a different minor device number. So, /dev/hda2, the second partition of the primary IDE disk has a major number of 3 and a minor number of 2. Linux maps the device special file passed in system calls (say to mount a file system on a block device) to the device’s device driver using the major device number and a number of system tables, for example the character device table, chrdevs .
Linux supports three types of hardware device: character, block and network.
1. Character devices are read and written directly without buffering.
2. Block devices can only be written to and read from in multiples of the block size, typically 512 or 1024 bytes. Block devices are accessed via the buffer cache and may be randomly accessed, that is to say, any block can be read or written no matter where it is on the device. Block devices can be accessed via their device special file but more commonly they are accessed via the file system. Only a block device can support a mounted file system.
3. Network devices are accessed via the BSD socket interface and the networking subsytems described in the Networking chapter.
The Raw devices are character devices (major number 162).
The first minor number (i.e. 0) is reserved as a control interface and is usually found at /dev/rawctl.
A sequence of commands listing the raw devices:
# ls -lR /dev/rawctl
crw-rw----    1 root     disk     162,   0 Mar  19  2002  /dev/rawctl
# ls -lR /dev/raw[1-4]
crw-rw----    1 root     disk     162,   1 Mar  19  2002  /dev/raw1
crw-rw----    1 root     disk     162,   2 Mar  19  2002  /dev/raw2
crw-rw----    1 root     disk     162,   3 Mar  19  2002  /dev/raw3
crw-rw----    1 root     disk     162,   4 Mar  19  2002  /dev/raw4
[top]
Q: 3. What are the benefits of raw devices?
A:A raw device can be bound to an existing block device (e.g. a disk) and be used to perform "raw" IO with that existing block device.
Such "raw" IO bypasses the caching (Linux buffer cache) that is normally associated with block devices and eliminates the file system overheads such as inodes or free lists. Hence a raw device offers a more "direct" route to the physical device and allows an application more control over the timing of IO to that physical device. This makes raw devices suitable for complex applications like Database Management Systems that typically do their own caching.
If there is no I/O bottleneck, raw devices will not help. Note that the overall amount of I/O is not reduced; it is just done more efficiently.
[top]
Q: 4. Are there circumstances when raw devices have to be used?
A:If you are using the Oracle Parallel Server (OPS) or Oracle Real Application Cluster (RAC) without Oracle Cluster File System (OCFS), all data files, control files, and redo log files must be placed on raw partitions so they can be shared between nodes. Also if you use List I/O or Asynchronous I/O, these facilities allow a program to issue multiple write operations without having to wait for the return of the previous write, to take advantage of this data files will need to be on raw devices.
[top]
Q: 5. Can I use the entire raw partition for Oracle?
A:No. You should specify a tablespace slightly smaller in size than the raw partition size, specifically at least two Oracle block sizes smaller.
[top]
Q: 6. How many raw devices I have in Linux by default and how many raw can I have?
A: The number of raw devices that Linux can access is limited to 255.
By default there are 128 raw devices under /dev/raw:
# ls -l /dev/raw*
crw-rw----    1 root     disk     162,   1 Mar  19  2002  /dev/raw1
(...)
crw-rw----    1 root     disk     162,   3 Mar  19  2002  /dev/raw128
Linux cannot handle more than a limited number of partitions per drive. So in Linux you have 4 primary partitions (3 of them useable, if you are using logical partitions) and at most 15 partitions altogether on an SCSI disk (63 altogether on an IDE disk).
[top]
Q: 7. How can I create new  raw devices?
A: If it’s necessary create others raw devices the following command must be done as root user (see man mknod):
# mknod -m 660 /dev/raw/rawXXX c 162 XXX
# chown root:disk /dev/raw/rawXXX
(where XXX= 128    i.e.:
# mknod -m 660 /dev/raw/raw130 c 162 130
# chown root:disk /dev/raw/raw130
# ls -l /dev/raw/raw130
crw-rw----    1 root     disk     162,   130 Dec  23  18:57  /dev/raw130
[top]
Q:  8. Who should own the raw device?
A:You will need to create the raw devices as root, but the ownership should be changed to the ’oracle’ account afterwards. The group must also be changed to the ’dba’ group (usually called dba).
[top]
Q:  9. How can I use a raw device for Oracle RDBMS?
A:We suppose to have a SCSI disk drivers - 9 Gbytes. The steps are:
a. Partition the disk driver (/dev/sdb)
b. Binding raw device with partition on new SCSI disk
c. Change the ownership of the raw device
d. Create a new Oracle datafile on raw device
- Partition the disk driver, fdisk command (see man fdisk):
1. As user root, type
# fdisk /dev/sdb
2. Type ’p’ to see the list of existing partitions on your disk drive:
command (m for help): p
Disk /dev/sdb: 255 heads, 63 sectors, 1174 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot    Start        End    Block    ID    System
3.a. In order to create a partition, choose ’n’ command and then choose an extended partition with the ’e’ option.
You will need extended partition, because this disk will contains more than 4 partitions.
Create partition number 1 first, so choose number 1.
command (m for help): n
command action
e    extended
p    primary partition (1-4)
e
Partition Number (1-4): 1
First cylinder (1-1115, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1115, default 1115):
Using default value 1115
3.b. Now within the extended partition,
I will have to create 6 logical partition of equal sizes: each should be 257Mb large (256Mb+1Mb for the headers).
Press ’n’ and ’l’ and , and write the size of the partition (begin with a +) +257M.
Repeat these steps 6 times
command (m for help): n
command action
l    logical (5 or over)
p    primary partition (1-4)
l
Partition Number (1-4): 1
First cylinder (1-1115, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1115, default 1115): +257M
(...repeat 5 time...)
command (m for help): p
Disk /dev/sdb: 255 heads, 63 sectors, 1174 cylinders
Units = cylinders of 16065 * 512 bytes
Device         Boot    Start        End         Block     ID      System
/dev/sdb1                  1       1115       8956206      5      Extended
/dev/sdb5                  1         33       265009+     83      Linux
/dev/sdb6                 34         66       265041      83      Linux
(...)
/dev/sdb10               166        198       265041      83      Linux
3.c. Now press ’w’ this will write the partition table to the disk and quit the fdisk programm
- Binding raw device with partition on new SCSI disk
A utility called raw (see man raw) can be used to bind a raw device to an existing block device:
# raw /dev/raw/raw1    /dev/sdb5
/dev/raw/raw1:  bound to major 8, minor 3
(...)
# raw /dev/raw/raw6    /dev/sdb10
/dev/raw/raw6:  bound to major 8, minor 3
The last details regarding this is that the assignement of raw device drivers to partitions should be done after each startup.
For this reason, as user root, edit the /etc/sysconfig/rawdevices and  put the following raw command into it:
raw /dev/raw/raw1    /dev/sdb5
raw /dev/raw/raw2    /dev/sdb6
raw /dev/raw/raw3    /dev/sdb7
raw /dev/raw/raw4    /dev/sdb8
raw /dev/raw/raw5    /dev/sdb9
raw /dev/raw/raw6    /dev/sdb10
- Change the ownership of the raw device
As root user type:
# cd /dev/raw
# chown oracle:dba raw[1-4]
- Create a new Oracle datafile on raw device
When using a raw device you need to specify the full pathname in single quotes, and use the REUSE parameter.
When creating the oracle tablespace on the raw partition a slightly smaller size than the actual partition size needs to be specified.
This size can be calculated as follows:
Size of Redo Log   = Raw Partition Size - 1*512 byte block
Size of Data File    = Raw Partition Size - 2* Oracle Block Size
e.g. (db_block_size=8192):
create tablespace tablespace_on_raw datafile ’/dev/raw/raw1’ size 246784K REUSE,
datafile ’/dev/raw/raw2’ size 246784K REUSE,
datafile ’/dev/raw/raw3’ size 246784K REUSE,
datafile ’/dev/raw/raw4’ size 246784K REUSE,
datafile ’/dev/raw/raw5’ size 246784K REUSE,
datafile ’/dev/raw/raw6’ size 246784K REUSE;
[top]
Q: 10. Does the Oracle block size have any relevance on a raw device?
A:It is of less importance than for a UNIX file; the size of the Oracle block can be changed, but it must be a multiple of the physical block
size as it is only possible to seek to physical block boundaries and hence write only in multiples of the physical block size.
[top]
Q: 11. How can I back up my database files if they are on raw devices?
A:You cannot use utilities such as ’tar’ or ’cpio’, which expect a filesystem to be present.
Usually people move Oracle datafiles from filesystem to raw devices using the ’dd’ command. Using dd is the fastest method to accomplish it. However, it is necessary to know how many blocks to skip in the raw device (e.g. on Tru64 Unix you have to skip 64K), so that you do not overwrite information necessary for the Operating System. The information on how many blocks to skip is different on the different platforms. On linux you do not need to specify a skip displacement. Using RMAN there’s no necessity to know such platform specific information. With the RMAN copy command datafiles can be copied from filesystem files to raw devices.
An example using ’dd’ command:
# dd if=/dev/raw/raw1 of=/u01/oradata/test_ts.dbf’  bs=16K
(Keep the Block size to multiple of the Oracle Block Size)
See the UNIX man page on dd for further details.
You can use RMAN.
From filesystem to raw device:
RMAN> run {
2> allocate channel c1 type disk;
3> copy datafile ’/u01/oradata/test_ts.dbf’ to ’/dev/raw/raw1’;
4> }
From raw device to filesystem:
RMAN> run {
2> allocate channel c1 type disk;
3> copy datafile ’/dev/raw/raw1’ to ’/u01/oradata/test_ts.dbf’;
4> }
[top]
Q: 12. Providing I am not using Parallel Server or Real Application Cluster, can I use a mixture of raw?
A:Yes. The drawback is that this makes your backup strategy more complicated.
[top]
Q: 13. Should I store my redo log files on raw partitions?
A:Redo logs are particularly suitable candidates for being located on raw partitions, as they are write-intensive and in addition are written to
sequentially. If OPS or RAC is being used, redo logs must be stored on raw partitions.
[top]
Q: 14. Can I use raw partitions for archive logs?
A:No. Archive logs must be stored on a partition with a UNIX filesystem.
[top]
Q:  15. Can I have more than one data file on a raw partition?
A:No. This means you should be careful when setting up the raw partition. Too small a size will necessitate reorganisation when you
run out of space, whereas too large a size will waste any space the file does not use.
[top]
Q: 16. Should my raw partitions be on the same disk device?
A:This is inadvisable, as there is likely to be contention. You should place raw devices on different disks, which should also be on different
controllers.
[top]
Q: 17. Do I need to make my raw partitions all the same size?
A:This is not essential, but it provides flexibility in the event of having to change the database configuration.
[top]
Q: 18. Do I need to change any UNIX kernel parameters if I decide to use raw devices?
A:No
[top]
Q: 19. What other UNIX-level changes could help to improve I/O performance?
A:RAID and disk mirroring can be beneficial, depending on the application characteristics, especially whether it is read or write-intensive, or a
mixture.
[top]
Q: 20. How can I gain further performance benefits, after considering all of the above?
A:You will need to buy more disk drives and controllers for your system, to spread the I/O load between devices.
linux下裸设备的使用-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 视频压缩编码的新发展-H.264(转贴)-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 [图]Linux更新工具Yumex&yum揭秘-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 Resin服务器的使用(一篇不错的文章,如果想使用resin做服务器建议看看)-JSP编程-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 硬盘安装+游戏功能 虚拟机XP-80分钟打造娱乐型ubuntu7.10[转]-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务器租赁,为7万用户提供服务 [转载]gdb中的信号-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务... 2.6下的内核模块编译-Linux -华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,... 用C语言编写CGI程式-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟主机,服务... Shell编程入门:Linux解释器原理-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,... “笑”傲流媒体―SMIL基础教程-源码天堂-华夏名网资讯中心 虚拟主机,域名注册,双线虚拟... linux vi使用手册-Linux -华夏名网 讯游数码代理资讯中心 虚拟主机,域名注册... 2G网络向3G平滑演进的若干关键技术探讨-硬件技术-华夏名网资讯中心 虚拟主机,域名注册,... 视窗系统 XP 转移和文件设置-windows操作系统-华夏名网资讯中心 虚拟主机,域名注... 域名注册虚拟主机注册服务提供商-新网互联 软件技巧 / Powerpoint - 西部数码站长资讯中心|虚拟主机|域名注册|主机租用 软件技巧 / Powerpoint - 西部数码站长资讯中心|虚拟主机|域名注册|主机租用 公司主要从事于域名注册、虚拟主机 虚拟主机 linux下远程传送文件,通过ssh协议传输文件命令-Linux -华夏名网资讯中心 虚拟... Vmware--虚拟主机的利器 网页设计中标志设计技巧 网络营销趋势 -深圳网站建设-深圳虚拟主机-深圳网页设计-域名注册... 外国虚拟主机空间评测网 | 不断追踪最好最便宜的虚拟主机空间 Kaitoo.com的房产搜索为用户提供一站式服务 基于IP,基于port和基于域名的三种虚拟主机的配置方法(原创)