Rate this page del.icio.us  Digg slashdot StumbleUpon

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

by The editorial team

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.redhat.com/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.

5 responses to “Tips and tricks: How do I add raw device mapping in Red Hat Enterprise Linux 5?”

  1. pc2 says:

    I wonder how to create a (shadow) raw device for lvm (/dev/mapper/*) block devices? Do you think if it is possible to solve this with udev a similar automated way?

  2. Frank says:

    “Unfortunately it is not possible to write udev rules for creating raw devices on multipath devices (/dev/dm-*) without manipulating existing udev rules.”

    Actually, it can be done. In 50-udev.rules, Red Hat has an OPTIONS+=”ignore_device” rule for dm-* devices, which would normally completely ignore them. But if you place your dm-* rules in a file which executes prior to 50-udev (use 49 or lower). Then create the raw device (Note that you can’t add a raw0, so you can’t just create /dev/raw/raw$MINOR…so add one to the minor number first):
    RUN+=”/bin/sh -c ‘/bin/raw /dev/raw/raw$((MINOR + 1)) $MAJOR $MINOR’”

    Finally, add add OPTIONS+=”last_rule” at the end of your rules, it will bypass future rules.

    This creates a /dev/raw/raw# node, but in order to make raw device names “prettier”, you can add another set of rules to execute on: ACTION==”add”, KERNEL==”raw[0-9]*” to determine the vg and lv names and add a /dev/raw-mapper/* symlink (“$vg-$lv”, or the WWID for example): SYMLINK+=”raw-mapper/%c{1}”

    I have discovered a truly marvelous demonstration of this proposition that this textarea is too narrow to contain.

  3. Tailladaura says:

    Есть возможность просмотреть фотогалерею секси скромные и голые девушки, всегда обворожительные девочки, возможно сексуальные девочки.

  4. PibiaMine says:

    Complimenti per idea del sito. Anche noi siamo amanti del trekking. Perche non organizziamo un incontro di appassionati per delle escursioni insieme? Magari non piu di 6-8 in tutto? Un saluto.
    mastasia
    nicole kidman in
    crock pot recipe
    in cartongesso

  5. How To Add Raw Device Mapping In Red Hat Enterprise Linux 5? says:

    [...] opening block device with O_DIRECT flag. How to create raw device mapping in RHEL 5? According to Red Hat Magazine article, here is the simplified step for my reference when our infrastructure team decides to go ahead with [...]

Leave a reply