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?
Permanently changing the ownership (or group) of LVM volume
permissions;lvm;udev
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=oracleENV{DM_VG_NAME}==vgRandom ENV{DM_LV_NAME}==ora_undo_*  OWNER=oracleENV{DM_VG_NAME}==vgSeq    ENV{DM_LV_NAME}==ora_redo_*  OWNER=oracleYou 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-2N: dm-2L: -100S: block/253:2S: mapper/vgRandom-ora_dataS: disk/by-id/dm-name-vgRandom-ora_dataS: disk/by-id/dm-uuid-LVM-d6wXWIzc7xWJkx3Tx3o4Q9huEG1ajakYr0SLSl5as3C6RoydA66sgNHxBZdpem89S: disk/by-uuid/787651c2-e4c7-40e2-b0fc-1a3978098dceS: vgRandom/ora_dataE: UDEV_LOG=3E: DEVPATH=/devices/virtual/block/dm-2E: MAJOR=253E: MINOR=2E: DEVNAME=/dev/dm-2E: DEVTYPE=diskE: SUBSYSTEM=blockE: DM_UDEV_PRIMARY_SOURCE_FLAG=1E: DM_NAME=vgRandom-ora_dataE: DM_UUID=LVM-d6wXWIzc7xWJkx3Tx3o4Q9huEG1ajakYr0SLSl5as3C6RoydA66sgNHxBZdpem89E: DM_SUSPENDED=0E: DM_UDEV_RULES=1E: DM_VG_NAME=vgRandomE: DM_LV_NAME=ora_dataE: 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_dataE: ID_FS_UUID=787651c2-e4c7-40e2-b0fc-1a3978098dceE: ID_FS_UUID_ENC=787651c2-e4c7-40e2-b0fc-1a3978098dceE: ID_FS_VERSION=1.0E: ID_FS_TYPE=ext4E: ID_FS_USAGE=filesystemE: FSTAB_NAME=/dev/mapper/vgRandom-ora_dataE: FSTAB_DIR=/opt/oracle/oracle/oradataE: FSTAB_TYPE=ext4E: FSTAB_OPTS=noatimeE: FSTAB_FREQ=0E: FSTAB_PASSNO=3Also, 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 thenwalks up the chain of parent devices. It prints for every devicefound, all possible attributes in the udev rules key format.A rule to match, can be composed by the attributes of the deviceand 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        0Though 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).