Tuesday, December 27, 2011

udev rules to change ownership of LVM partition (RHEL/OEL 5)

When a logical volume is used for ASM disk, the logical volume should be given ownership grid infrastructure user and group. This can be set simply by adding chown commands /etc/rc.local file (a dirty work around). The same thing can be accomplished even by using udev rules like below.

In this example, we are trying to use logical volume vol05 in volume group vg1 for grid infrastructure.


Add below line to /etc/udev/rules.d/91-lvm-
asmdisk.rules (entire content in single line)

SUBSYSTEM=="block", KERNEL=="dm-*", ACTION=="add|change", PROGRAM="/sbin/dmsetup info -c --noheadings -o name -j %M -m %m", RESULT=="vg1-vol05", RUN+="/bin/chown grid:asmadmin /dev/mapper/vg1-vol05"

Deactivate and activate logical volume to verify if udev rule is working fine.
# lvchange -an vg1/vol05
# lvchange -ay vg1/vol05
 
Now ownership is changed for logical volume.
# ls -l /dev/mapper/vg1-vol05
brw-rw---- 1 grid asmadmin 253, 4 Dec 14 22:33 /dev/mapper/vg1-vol05

7 comments:

  1. Excellent job, thanks!!

    ReplyDelete
    Replies
    1. Can this be completed with using a wildcard for multiple volumes.

      RUN+="/bin/chown grid:asmadmin /dev/mapper/vg1-vol*"

      Delete
  2. I think wild cards will not work here, as the udev rule mentioned checks for name of volume explicitly, you can see RESULT=="vg1-vol05" in the rule.

    For multiple volumes, the PROGRAM should be a script that verifies the logical volumes that needed to changed ownership instead of dmsetup command. And based on RESULT of the script RUN command should be "/bin/chown grid:asmadmin %p"

    So, roughly the udev rule will like this (I have not tested this, just giving like a hint)

    SUBSYSTEM=="block", KERNEL=="dm-*", ACTION=="add|change", PROGRAM="/usr/bin/check_vol.sh %M %m", RESULT=="YES", RUN+="/bin/chown grid:asmadmin %p"

    And create script /usr/bin/check_vol.sh like this

    #!/bin/bash
    volname=`/sbin/dmsetup info -c --noheadings -o name -j $1 -m $2`
    if [ *** write your logic to check if $volname should be changed ownership *** ]
    then
    echo YES
    else
    echo NO
    fi

    Please let me know if this works. I do not have this setup of LVM for ASM anymore. So, I can guess and give answers, but I could not test right now.

    ReplyDelete
  3. Hi Murty

    One question about this

    Are you saying that the following wont work?

    /etc/udev/rules.d/90-lvm.rules

    SUBSYSTEM=="block", KERNEL=="dm-*", ACTION=="add|change", PROGRAM="/sbin/dmsetup info -c --noheadings -o name -j %M -m %m", RESULT=="vg1-vol05", RUN+="/bin/chown grid:asmadmin /dev/mapper/vg1-vol05"
    SUBSYSTEM=="block", KERNEL=="dm-*", ACTION=="add|change", PROGRAM="/sbin/dmsetup info -c --noheadings -o name -j %M -m %m", RESULT=="vg1-vol04", RUN+="/bin/chown grid:asmadmin /dev/mapper/vg1-vol04"

    Thanks in advance

    Nacho

    ReplyDelete
    Replies
    1. Hey, it's not work for me !
      Every reboot I need to run lvchange -an /dev/mapper/vg1 ; lvchange -ay /dev/mapper/vg1 then it's work.
      someone ?

      Delete
  4. Hi Nacho,

    It works, but, if we have many volume groups, we need to add a line for each of them. What I was giving in my last reply, a way to write single rule that can be used for multiple logical volumes.

    Murty

    ReplyDelete