linux 配置udev修改权限

举报
snowofsummer 发表于 2022/01/23 11:16:34 2022/01/23
【摘要】 本次介绍使用udev修改磁盘权限。参考模板位置:/usr/share/doc/device-mapper-1.02.170/12-dm-permissions.rules#编写规则:(任选一条即可)/etc/udev/rules.d/99-oracle-asm.rules​ENV{DM_UUID}=="mpath-?*", OWNER:="grid", GROUP:="asmadmin", ...

本次介绍使用udev修改磁盘权限。

参考模板位置:/usr/share/doc/device-mapper-1.02.170/12-dm-permissions.rules

#编写规则:(任选一条即可)

/etc/udev/rules.d/99-oracle-asm.rules
​
ENV{DM_UUID}=="mpath-?*", OWNER:="grid", GROUP:="asmadmin", MODE:="660"*
​
ENV{DM_UUID}=="mpath-?*", OWNER:="grid", GROUP:="asmadmin", MODE:="660",SYMLINK+="asmdisk_%k"*
​
*ENV{DM_UUID}=="mpath-?*", OWNER:="grid", GROUP:="asmadmin", MODE:="660",SYMLINK="asmdisk_%k"

#重新加载规则

udevadm control -R
​
udevadm trigger

测试步骤和结果:

[root@hecs-66a2 ~]# ll /usr/share/doc/device-mapper-1.02.170/12-dm-permissions.rules
-rw-r--r-- 1 root root 3186 Mar 25  2020 /usr/share/doc/device-mapper-1.02.170/12-dm-permissions.rules
​
[root@hecs-66a2 ~]# multipath -l
mpathb (36001405a8111ea8e7e54c8fb25613092) dm-1 LIO-ORG ,disk02
size=20G features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
  `- 2:0:0:1 sdb 8:16 active undef running
mpatha (360014054170ebd76f8b4cd69600e1ba9) dm-0 LIO-ORG ,disk01
size=10G features='0' hwhandler='0' wp=rw
`-+- policy='service-time 0' prio=0 status=active
  `- 2:0:0:0 sda 8:0  active undef running
  
[root@hecs-66a2 ~]# cat /etc/udev/rules.d/99-oracle-asm.rules
ENV{DM_UUID}=="mpath-?*", OWNER:="grid", GROUP:="asmadmin", MODE:="660",SYMLINK+="asmdisk_%k"
​
[root@hecs-66a2 ~]# udevadm admin -R
udevadm: missing or unknown command
[root@hecs-66a2 ~]# udevadm control -R
[root@hecs-66a2 ~]# udevadm trigger
[root@hecs-66a2 ~]# ll /dev/asmdisk_dm-*
lrwxrwxrwx 1 root root 4 Oct 30 09:32 /dev/asmdisk_dm-0 -> dm-0
lrwxrwxrwx 1 root root 4 Oct 30 09:32 /dev/asmdisk_dm-1 -> dm-1
[root@hecs-66a2 ~]# ll /dev/dm-*
brw-rw---- 1 grid asmadmin 252, 0 Oct 30 09:32 /dev/dm-0
brw-rw---- 1 grid asmadmin 252, 1 Oct 30 09:32 /dev/dm-1
​
​

# SYMLINK+与 SYMLINK区别?

SYMLINK+
create a symbolic link 。
SYMLINK:
instead of calling it 。
​
* SYMLINK - a list of symbolic links which act as alternative names for the device node
As hinted above, udev only creates one true device node for one device. If you wish to provide alternate names for this device node, you use the symbolic link functionality. With the SYMLINK assignment, you are actually maintaining a list of symbolic links, all of which will be pointed at the real device node. To manipulate these links, we introduce a new operator for appending to lists: +=. You can append multiple symlinks to the list from any one rule by separating each one with a space.
KERNEL=="hdb", NAME="my_spare_disk"
The above rule says: match a device which was named by the kernel as hdb, and instead of calling it hdb, name the device node as my_spare_disk. The device node appears at /dev/my_spare_disk.
KERNEL=="hdb", DRIVER=="ide-disk", SYMLINK+="sparedisk"
The above rule says: match a device which was named by the kernel as hdb AND where the driver is ide-disk. Name the device node with the default name and create a symbolic link to it named sparedisk. Note that we did not specify a device node name, so udev uses the default. In order to preserve the standard /dev layout, your own rules will typically leave the NAME alone but create some SYMLINKs and/or perform other assignments.
KERNEL=="hdc", SYMLINK+="cdrom cdrom0"
The above rule is probably more typical of the types of rules you might be writing. It creates two symbolic links at /dev/cdrom and /dev/cdrom0, both of which point at /dev/hdc. Again, no NAME assignment was specified, so the default kernel name (hdc) is used.
​

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。