Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I permanently change the ownership (or at least the group) of a LVM volume?

I figured that I have to use udev, but I don't know how the rule should look like?

Let's say I want to change the ownership of LVM/disk to user/group virtualbox, how would I do that?

share|improve this question
    
Which OS are you talking about? Which LVM (OS or Veritas?) –  Nils Nov 7 '11 at 21:04

2 Answers 2

up vote 7 down vote accepted

On Debian (and hopefully your distro as well) all the LVM metadata is already loaded into udev (by some of the rules in /lib/udev/rules.d). So you can use a rules file like this:

$ cat /etc/udev/rules.d/92-local-oracle-permissions.rules 
ENV{DM_VG_NAME}=="vgRandom" ENV{DM_LV_NAME}=="ora_users_*" OWNER="oracle"
ENV{DM_VG_NAME}=="vgRandom" ENV{DM_LV_NAME}=="ora_undo_*"  OWNER="oracle"
ENV{DM_VG_NAME}=="vgSeq"    ENV{DM_LV_NAME}=="ora_redo_*"  OWNER="oracle"

You can use udevadm to find out what kinds of things you can base your udev rules on. All the E: lines can be found in ENV in udev, e.g., the E: DM_LV_NAME=ora_data line matched by one of the above rules:

# udevadm info --query=all --name /dev/dm-2 
P: /devices/virtual/block/dm-2
N: dm-2
L: -100
S: block/253:2
S: mapper/vgRandom-ora_data
S: disk/by-id/dm-name-vgRandom-ora_data
S: disk/by-id/dm-uuid-LVM-d6wXWIzc7xWJkx3Tx3o4Q9huEG1ajakYr0SLSl5as3C6RoydA66sgNHxBZdpem89
S: disk/by-uuid/787651c2-e4c7-40e2-b0fc-1a3978098dce
S: vgRandom/ora_data
E: UDEV_LOG=3
E: DEVPATH=/devices/virtual/block/dm-2
E: MAJOR=253
E: MINOR=2
E: DEVNAME=/dev/dm-2
E: DEVTYPE=disk
E: SUBSYSTEM=block
E: DM_UDEV_PRIMARY_SOURCE_FLAG=1
E: DM_NAME=vgRandom-ora_data
E: DM_UUID=LVM-d6wXWIzc7xWJkx3Tx3o4Q9huEG1ajakYr0SLSl5as3C6RoydA66sgNHxBZdpem89
E: DM_SUSPENDED=0
E: DM_UDEV_RULES=1
E: DM_VG_NAME=vgRandom
E: DM_LV_NAME=ora_data
E: DEVLINKS=/dev/block/253:2 /dev/mapper/vgRandom-ora_data /dev/disk/by-id/dm-name-vgRandom-ora_data /dev/disk/by-id/dm-uuid-LVM-d6wXWIzc7xWJkx3Tx3o4Q9huEG1ajakYr0SLSl5as3C6RoydA66sgNHxBZdpem89 /dev/disk/by-uuid/787651c2-e4c7-40e2-b0fc-1a3978098dce /dev/vgRandom/ora_data
E: ID_FS_UUID=787651c2-e4c7-40e2-b0fc-1a3978098dce
E: ID_FS_UUID_ENC=787651c2-e4c7-40e2-b0fc-1a3978098dce
E: ID_FS_VERSION=1.0
E: ID_FS_TYPE=ext4
E: ID_FS_USAGE=filesystem
E: FSTAB_NAME=/dev/mapper/vgRandom-ora_data
E: FSTAB_DIR=/opt/oracle/oracle/oradata
E: FSTAB_TYPE=ext4
E: FSTAB_OPTS=noatime
E: FSTAB_FREQ=0
E: FSTAB_PASSNO=3

Also, you can match on sysfs attributes, in either ATTR (device only) or ATTRS (parents too). You can see all the attributes like this:

# udevadm info --attribute-walk --name /dev/dm-2 

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/virtual/block/dm-2':
    KERNEL=="dm-2"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{range}=="1"
    ATTR{ext_range}=="1"
    ATTR{removable}=="0"
    ATTR{ro}=="0"
    ATTR{size}=="41943040"
    ATTR{alignment_offset}=="0"
    ATTR{discard_alignment}=="0"
    ATTR{capability}=="10"
    ATTR{stat}=="36383695        0 4435621936 124776016 29447978        0 3984603551 342671312        0 191751864 467456484"
    ATTR{inflight}=="       0        0"

Though that matching is more useful for non-virtual devices (e.g., you'll get a lot of output if you try it on /dev/sda1).

share|improve this answer

From a quick glance at the udev documentation and existing rules on my system, the rule below (untested) should identify a particular logical volume, using the dmsetup program to retrieve the volume information. Replace gggggggg by the UUID of the volume group (vgdisplay VG_NAME) and lllllll by the UUID of the logical volume (lvdisplay VG_NAME/LV_NAME), or run the dmsetup command manually to find the UUID.

SUBSYSTEM=="block", KERNEL=="dm-[0-9]*", \
PROGRAM=="dmsetup info -c --noheadings -o uuid", \
RESULT=="LVM-ggggggggllllllll", \
OWNER=="letmebe", GROUP="vmusers", MODE="0660"
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.