您的位置:首页 > 运维架构 > Linux

How do I add raw device mapping in Red Hat Enterprise Linux 5?

2008-12-24 09:44 751 查看
How do I add raw device mapping in Red Hat Enterprise Linux 5?

Resolution:

The raw devices interface has been deprecated in Red Hat Enterprise Linux 5. The rawdevices service and /etc/sysconfig/rawdevices file no longer exist and raw devices are now configured via udev rules. However the preferred method for performing raw I/O (ie. bypassing filesystem caching) is to open EXT3/EXT2 files with the O_DIRECT flag.

This is an excerpt from the raw command's man page:

Although  Linux  includes  support  for rawio, it is now a deprecated interface. If your application performs device access using this
interface, Red Hat encourages you to modify your application to open the block device with the O_DIRECT flag. The rawio interface will
exist for the life of Red Hat Enterprise Linux 5, but is a candidate for removal from future releases.


Creating the raw devices:

Nevertheless, to create raw devices, add entries to /etc/udev/rules.d/60-raw.rules in the following formats:

For device names:

ACTION=="add", KERNEL=="<device name>", RUN+="raw /dev/raw/rawX %N"

For major / minor numbers:

ACTION=="add", ENV{MAJOR}="A", ENV{MINOR}="B", RUN+="raw /dev/raw/rawX %M %m"

Replace <device name> with the name of the device needed to bind (such as /dev/sda1). "A" and "B" are the major / minor numbers of the device needed for binding, an "X" is the raw device number that the system wants to use.

If there is a large, pre-existing /etc/sysconfig/rawdevices file, convert it with the following script:

#!/bin/sh
grep -v "^ *#" /etc/sysconfig/rawdevices | grep -v "^$" | while read dev major
minor ; do
if [ -z "$minor" ]; then
echo "ACTION==//"add//", KERNEL==//"${major##/dev/}//",
RUN+=//"/usr/bin/raw $dev %N//""
else
echo "ACTION==//"add//", ENV{MAJOR}==//"$major//",
ENV{MINOR}==//"$minor//", RUN+=//"/usr/bin/raw $dev %M %m//""
fi
done


Creating persistent raw devices for single path LUNs:

If using unpartitioned LUNs, to create a single raw device for the whole LUN use this rule format:

ACTION=="add", KERNEL=="sd*[!0-9]", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="3600601601bd2180072193a9242c3dc11", RUN+="/bin/raw /dev/raw/raw1 %N"

Set the RESULT value to the output of scsi_id -g -u -s /block/sdX (where sdX is the current path to the LUN). This will create the raw device /dev/raw/raw1 that will be persistently bound to the LUN with WWID 3600601601bd2180072193a9242c3dc11.

If using partitioned LUNs, where raw devices are created for each of the partitions on the LUN, use this rule format:

ACTION=="add", KERNEL=="sd*[0-9]", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="3600601601bd2180072193a9242c3dc11", RUN+="/bin/raw /dev/raw/raw%n %N"

Again, set RESULT to the output of scsi_id -g -u -s /block/sdX. This will create the raw device(s) /dev/raw/raw1, /dev/raw/raw2, etc. for each partition on the LUN and they will be persistently bound to the LUN with WWID 3600601601bd2180072193a9242c3dc11.

Setting ownership and permissions on the raw devices:

To set specific ownership and/or permissions for the raw devices, add entries to /etc/udev/rules.d/60-raw.rules in the following format:

ACTION=="add", KERNEL=="raw*", OWNER=="root", GROUP=="disk", MODE=="0660"


Testing and implementing the udev rules:

Before implementing them, use the udevtest command to verify the udev rules work as expected. To verify that the raw device is created for a specific disk or partition, eg /dev/sdb1:

[root@rhel5 rules.d]# udevtest /block/sdb/sdb1 | grep raw
main: run: '/bin/raw /dev/raw/raw1 /dev/.tmp-8-17'

To check ownership/permission settings for a particular raw device, eg /dev/raw/raw1:

[root@rhel5 rules.d]# udevtest /class/raw/raw1 | grep mode
udev_node_add: creating device node '/dev/raw/raw1', major = '162', minor = '1', mode = '0600', uid = '0', gid = '0'

Finally, to actually create the raw device(s), use the start_udev command:

[root@rhel5 rules.d]# start_udev
Starting udev:                                             [  OK  ]

Check that the raw device(s) have been created:

[root@rhel5 rules.d]# raw -qa
/dev/raw/raw1:  bound to major 8, minor 17
[root@rhel5 rules.d]# ls -l /dev/raw
total 0
crw-rw---- 1 root   disk 162,  1 Jan 29 02:47 raw1


Creating persistent raw devices for multipathed LUNs:

Unfortunately it is not possible to write udev rules for creating raw devices on multipath devices (/dev/dm-*) without manipulating existing udev rules. Modifying existing rules for this purpose could cause unforeseen problems and is not supported by Red Hat Global Support Services. If absolutely necessary, an alternate method for creating raw devices on top of multipath devices could be to create the raw devices in /etc/rc.d/rc.local, so long as the raw device is not required before rc.local is executed. For example:
/bin/raw /dev/raw/raw1 /dev/mpath/mpath1p1
/bin/raw /dev/raw/raw2 /dev/mpath/mpath1p2


Note: Raw device support is not enabled on the s390 architecture.

https://bugzilla.redhat.com/show_bug.cgi?id=452534

#ll /dev/sd*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐