How to add raw device mapping in Red Hat Enterprise Linux 5
Environment
- Red Hat Enterprise Linux 5
- RAW devices
Issue
- How to add raw device mapping in Red Hat Enterprise Linux 5.
- After rebooting my server, some of my Oracle ASM disks have disappeared.
- Use udev to create raw device with multipath
Resolution
-
Previously (Red Hat Enterprise Linux 5.0 through Red Hat Enterprise Linux 5.3), support for
rawdevices in the upstream kernel was deprecated. However, this support has been returned to the kernel. Consequently, in Red Hat Enterprise Linux 5.4, support for raw devices has also been returned. Additionally, theinitscriptspackages have been updated, adding the previously dropped functionality of raw devices. -
So in the Red Hat Enterprise Linux 5, there are two methods to configure RAW device.
Method 1. Using rawdevices service (Not available on RHEL5.0 -- RHEL5.3)
-
Edit the file /etc/sysconfig/rawdevices
$ service rawdevices start # raw device bindings # format: <rawdev> <major> <minor> # <rawdev> <blockdev> # example: /dev/raw/raw1 /dev/sda1 # /dev/raw/raw2 8 5 /dev/raw/raw1 /dev/hda5 /dev/raw/raw2 /dev/sdc /dev/raw/raw3 /dev/VolGroup3/LogVol3Note:
/dev/raw/raw0is not allowed because minor number cannot be zero. -
Start the rawdevices service
# service rawdevices start # chkconfig rawdevices on
Method 2. Using udev to configure RAW device
-
Creating the raw devices using udev:
Nevertheless, to create raw devices, add entries to
/etc/udev/rules.d/60-raw.rulesin 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"Note: 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. -
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"Note: Set the RESULT value to the output of
scsi_id -g -u -s /block/sdX(wheresdXis the current path to the LUN). This will create the raw device/dev/raw/raw1that will be persistently bound to the LUN withWWID3600601601bd2180072193a9242c3dc11.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"Note: Set
RESULTto the output ofscsi_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 withWWID3600601601bd2180072193a9242c3dc11. -
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.rulesin the following format:ACTION=="add", KERNEL=="raw*", OWNER="root", GROUP="disk", MODE="0660" -
Testing and implementing the udev rules:
Before implementing them, use the
udevtestcommand to verify theudevrules 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_udevcommand:
Note: Please note thatstart_udevcommand should not run on a production server. For more details please refer to Under what conditions should start_udev be run?
[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 - To check ownership/permission settings for a particular raw device, eg.
-
Creating persistent raw devices for multipathed LUNs or LVM device:
Unfortunately it is not possible to write
udevrules for creating raw devices on multipath devices (/dev/dm-*) without manipulating existingudevrules. 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 beforerc.localis executed. For example:/bin/raw /dev/raw/raw1 /dev/mpath/mpath1p1 /bin/raw /dev/raw/raw2 /dev/mpath/mpath1p2 /bin/chmod 660 /dev/raw/raw1 /bin/chown root:disk /dev/raw/raw1 /bin/chmod 660 /dev/raw/raw2 /bin/chown root:disk /dev/raw/raw2If absolutely want to create raw devices for multipathed LUNs using
udev, can add the followingudevrules in the file /etc/udev/rules.d/60-raw.rules# Device mapper raw rules KERNEL!="dm-[0-9]*", GOTO="skip_dm" ACTION!="change", GOTO="skip_dm" PROGRAM!="/sbin/dmsetup ls --exec /bin/basename -j %M -m %m", GOTO="skip_dm" RESULT=="mpath2", RUN+="/bin/raw /dev/raw/raw2 /dev/mapper/mpath2" RESULT=="mpath1", RUN+="/bin/raw /dev/raw/raw1 /dev/mapper/mpath1" LABEL="skip_dm" KERNEL=="raw1", ACTION=="add", OWNER="root", GROUP="disk", MODE="0660" KERNEL=="raw2", ACTION=="add", OWNER="root", GROUP="disk", MODE="0660"
Comments
-
The first three rules makes sure we are only using
dmdevices with change actions, whendmsetupreturns success. If not, we skip down to theskip_dmlabel. After that, the rules look at the result of runningdmsetup, and do fire off the appropriate command. -
Raw device support is not enabled on the s390 architecture.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments