分享

Red Hat Magazine | Tips and tricks: How do I add raw device mapping in Red Hat Enterprise Linux?5?

 fort 2009-01-19

Answer:

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=="", 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 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./show_bug.cgi?id=452534

Red Hat’s customer service and support teams receive technical support questions from users all over the world. Red Hat technicians add the questions and answers to Red Hat Knowledgebase on a daily basis. Access to Red Hat Knowledgebase is free. Red Hat Magazine offers a preview into the Red Hat Knowledgebase by highlighting some of the most recent entries. The information provided in this article is for your information only. The origin of this information may be internal or external to Red Hat. While Red Hat attempts to verify the validity of this information before it is posted, Red Hat makes no express or implied claims to its validity.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多