Permanently changing the ownership (or group) of LVM volume

Šimon Tóth

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?

derobert

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).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

reverse extending the LVM group volume

From Dev

LVM - Volume Group - What are Extents?

From Dev

LVM volume group is not activated at startup

From Dev

changing ownership of file as group user

From Dev

How to reduce Volume Group size in LVM?

From Dev

How to restore previous LVM volume group configuration?

From Dev

Changing group ownership of files - User management

From Dev

How do you rename the volume group that contains the root volume in LVM?

From Dev

Adding group permission to directory without changing group ownership?

From Dev

Is pvcreate destructive? Attempting to recover an lvm2 volume group

From Dev

Permanently mounting a directory with LVM

From Dev

Is there a simple way to move/copy a logical volume from one volume group to another? (LVM2)

From Dev

Map lvm volume to Physical volume

From Dev

How to mount this LVM volume?

From Dev

Issues zeroing an LVM volume

From Dev

Changing ownership of a directory

From Dev

How can I add a new physical volume to extend an existing LUKS-encrypted lvm (volume group) and maintain encryption?

From Dev

How can I create an LVM volume group spanning 2 hard drives?

From Dev

How to add a btrfs raid 1 to an encrypted lvm2 volume group under Solus OS (Linux)?

From Dev

Can multiple lvm2 volumes in a single volume group be bootable root volumes?

From Dev

LVM export and import: How to move a VG to another Machine with a equally named volume group

From Dev

Changing code on scroll permanently

From Dev

Changing the metric of an interface permanently

From Dev

Changing the metric of an interface permanently

From Dev

Blur changing bitmap permanently

From Dev

System contains LVM volume, but no LVM tools are installed

From Dev

Group ownership in linux

From Dev

Mounted lvm volume not passed to container

From Dev

LVM Mirrored Logical Volume Performance

Related Related

  1. 1

    reverse extending the LVM group volume

  2. 2

    LVM - Volume Group - What are Extents?

  3. 3

    LVM volume group is not activated at startup

  4. 4

    changing ownership of file as group user

  5. 5

    How to reduce Volume Group size in LVM?

  6. 6

    How to restore previous LVM volume group configuration?

  7. 7

    Changing group ownership of files - User management

  8. 8

    How do you rename the volume group that contains the root volume in LVM?

  9. 9

    Adding group permission to directory without changing group ownership?

  10. 10

    Is pvcreate destructive? Attempting to recover an lvm2 volume group

  11. 11

    Permanently mounting a directory with LVM

  12. 12

    Is there a simple way to move/copy a logical volume from one volume group to another? (LVM2)

  13. 13

    Map lvm volume to Physical volume

  14. 14

    How to mount this LVM volume?

  15. 15

    Issues zeroing an LVM volume

  16. 16

    Changing ownership of a directory

  17. 17

    How can I add a new physical volume to extend an existing LUKS-encrypted lvm (volume group) and maintain encryption?

  18. 18

    How can I create an LVM volume group spanning 2 hard drives?

  19. 19

    How to add a btrfs raid 1 to an encrypted lvm2 volume group under Solus OS (Linux)?

  20. 20

    Can multiple lvm2 volumes in a single volume group be bootable root volumes?

  21. 21

    LVM export and import: How to move a VG to another Machine with a equally named volume group

  22. 22

    Changing code on scroll permanently

  23. 23

    Changing the metric of an interface permanently

  24. 24

    Changing the metric of an interface permanently

  25. 25

    Blur changing bitmap permanently

  26. 26

    System contains LVM volume, but no LVM tools are installed

  27. 27

    Group ownership in linux

  28. 28

    Mounted lvm volume not passed to container

  29. 29

    LVM Mirrored Logical Volume Performance

HotTag

Archive