在Debian(可能还有您的发行版)上,所有LVM元数据都已加载到udev中(通过/lib/udev/rules.d中的某些规则)。因此,您可以使用以下规则文件:
$ 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"
您可以使用udevadm找出可以将udev规则作为基础的东西。所有E:
行都可以在udev的ENV中找到,例如,E: DM_LV_NAME=ora_data
符合上述规则之一的行:
# 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
另外,您可以在ATTR(仅设备)或ATTRS(也为父级)中匹配sysfs属性。您可以看到所有这样的属性:
# 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"
尽管该匹配对于非虚拟设备更有用(例如,如果在/ dev / sda1上尝试,则会得到很多输出)。