Linux udev: Difference between revisions
From Lolly's Wiki
Jump to navigationJump to search
No edit summary |
m (Text replacement - "[[Kategorie:" to "[[Category:") |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[ | [[Category:Linux|udev]] | ||
==Persistent network interface names== | ==Persistent network interface names== | ||
If you have no <i>/etc/udev/rules.d/70-persistent-net.rules</i> just create one: | If you have no <i>/etc/udev/rules.d/70-persistent-net.rules</i> just create one: | ||
< | <syntaxhighlight lang=bash> | ||
# lshw -C network | awk '/logical name:/{iface=$NF;}/serial:/{mac=$NF;printf "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"%s\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"%s\"\n",mac,iface;}' >> /etc/udev/rules.d/70-persistent-net.rules | # lshw -C network | awk '/logical name:/{iface=$NF;}/serial:/{mac=$NF;printf "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"%s\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"%s\"\n",mac,iface;}' >> /etc/udev/rules.d/70-persistent-net.rules | ||
</ | </syntaxhighlight> | ||
or add a specific interface to <i>/etc/udev/rules.d/70-persistent-net.rules</i>: | or add a specific interface to <i>/etc/udev/rules.d/70-persistent-net.rules</i>: | ||
< | <syntaxhighlight lang=bash> | ||
# MATCHADDR="00:50:56:a1:20:22" INTERFACE=eth2 /lib/udev/write_net_rules | # MATCHADDR="00:50:56:a1:20:22" INTERFACE=eth2 /lib/udev/write_net_rules | ||
</ | </syntaxhighlight> | ||
Change order with: | Change order with: | ||
< | <syntaxhighlight lang=bash> | ||
# vi /etc/udev/rules.d/70-persistent-net.rules | # vi /etc/udev/rules.d/70-persistent-net.rules | ||
</ | </syntaxhighlight> | ||
Then let udev reread the file: | Then let udev reread the file: | ||
< | <syntaxhighlight lang=bash> | ||
# udevadm trigger --action=add --subsystem-match=net --verbose | # udevadm trigger --action=add --subsystem-match=net --verbose | ||
</ | </syntaxhighlight> | ||
Line 25: | Line 25: | ||
===Make your rule=== | ===Make your rule=== | ||
< | <syntaxhighlight lang=bash> | ||
root@mysql:~# cat /etc/udev/rules.d/99-lvm-mysql-permissions.rules | root@mysql:~# cat /etc/udev/rules.d/99-lvm-mysql-permissions.rules | ||
# udevadm info --query=all --name /dev/vg-data/lv-rawdisk-innodb01 | # udevadm info --query=all --name /dev/vg-data/lv-rawdisk-innodb01 | ||
Line 31: | Line 31: | ||
# DM_LV_NAME=lv-rawdisk-innodb01 | # DM_LV_NAME=lv-rawdisk-innodb01 | ||
ENV{DM_VG_NAME}=="vg-data" ENV{DM_LV_NAME}=="lv-rawdisk-innodb*" OWNER="mysql" GROUP="mysql" | ENV{DM_VG_NAME}=="vg-data" ENV{DM_LV_NAME}=="lv-rawdisk-innodb*" OWNER="mysql" GROUP="mysql" | ||
</ | </syntaxhighlight> | ||
===Test your rule=== | ===Test your rule=== | ||
< | <syntaxhighlight lang=bash> | ||
root@mysql:~# ls -al /dev/vg-data/lv-rawdisk-innodb01 | root@mysql:~# ls -al /dev/vg-data/lv-rawdisk-innodb01 | ||
lrwxrwxrwx 1 root root 7 Aug 12 14:45 /dev/vg-data/lv-rawdisk-innodb01 -> ../dm-0 | lrwxrwxrwx 1 root root 7 Aug 12 14:45 /dev/vg-data/lv-rawdisk-innodb01 -> ../dm-0 | ||
Line 43: | Line 43: | ||
specified user 'mysql' unknown | specified user 'mysql' unknown | ||
... | ... | ||
</ | </syntaxhighlight> | ||
OK user mysql unknown... maybe I should install MySQL ;-). | OK user mysql unknown... maybe I should install MySQL ;-). | ||
After that: | After that: | ||
< | <syntaxhighlight lang=bash> | ||
root@mysql:~# id -a mysql | root@mysql:~# id -a mysql | ||
uid=108(mysql) gid=114(mysql) groups=114(mysql) | uid=108(mysql) gid=114(mysql) groups=114(mysql) | ||
Line 58: | Line 58: | ||
set permissions /dev/dm-0, 060660, uid=108, gid=114 | set permissions /dev/dm-0, 060660, uid=108, gid=114 | ||
... | ... | ||
</ | </syntaxhighlight> | ||
===Trigger your rule=== | ===Trigger your rule=== | ||
< | <syntaxhighlight lang=bash> | ||
root@mysql:~# udevadm trigger | root@mysql:~# udevadm trigger | ||
root@mysql:~# ls -alL /dev/vg-data/lv-rawdisk-innodb01 | root@mysql:~# ls -alL /dev/vg-data/lv-rawdisk-innodb01 | ||
brw-rw---- 1 mysql mysql 252, 0 Aug 12 15:07 /dev/vg-data/lv-rawdisk-innodb01 | brw-rw---- 1 mysql mysql 252, 0 Aug 12 15:07 /dev/vg-data/lv-rawdisk-innodb01 | ||
</ | </syntaxhighlight> |
Latest revision as of 05:32, 26 November 2021
Persistent network interface names
If you have no /etc/udev/rules.d/70-persistent-net.rules just create one:
# lshw -C network | awk '/logical name:/{iface=$NF;}/serial:/{mac=$NF;printf "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"%s\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"%s\"\n",mac,iface;}' >> /etc/udev/rules.d/70-persistent-net.rules
or add a specific interface to /etc/udev/rules.d/70-persistent-net.rules:
# MATCHADDR="00:50:56:a1:20:22" INTERFACE=eth2 /lib/udev/write_net_rules
Change order with:
# vi /etc/udev/rules.d/70-persistent-net.rules
Then let udev reread the file:
# udevadm trigger --action=add --subsystem-match=net --verbose
udev for MySQL on LVM with InnoDB on raw devices
Make your rule
root@mysql:~# cat /etc/udev/rules.d/99-lvm-mysql-permissions.rules
# udevadm info --query=all --name /dev/vg-data/lv-rawdisk-innodb01
# DM_VG_NAME=vg-data
# DM_LV_NAME=lv-rawdisk-innodb01
ENV{DM_VG_NAME}=="vg-data" ENV{DM_LV_NAME}=="lv-rawdisk-innodb*" OWNER="mysql" GROUP="mysql"
Test your rule
root@mysql:~# ls -al /dev/vg-data/lv-rawdisk-innodb01
lrwxrwxrwx 1 root root 7 Aug 12 14:45 /dev/vg-data/lv-rawdisk-innodb01 -> ../dm-0
root@mysql:~# udevadm test /class/block/dm-0
...
read rules file: /etc/udev/rules.d/99-lvm-mysql-permissions.rules
specified user 'mysql' unknown
...
OK user mysql unknown... maybe I should install MySQL ;-).
After that:
root@mysql:~# id -a mysql
uid=108(mysql) gid=114(mysql) groups=114(mysql)
root@mysql:~# udevadm test /class/block/dm-0
...
OWNER 108 /etc/udev/rules.d/99-lvm-mysql-permissions.rules:4
GROUP 114 /etc/udev/rules.d/99-lvm-mysql-permissions.rules:4
handling device node '/dev/dm-0', devnum=b252:0, mode=0660, uid=108, gid=114
set permissions /dev/dm-0, 060660, uid=108, gid=114
...
Trigger your rule
root@mysql:~# udevadm trigger
root@mysql:~# ls -alL /dev/vg-data/lv-rawdisk-innodb01
brw-rw---- 1 mysql mysql 252, 0 Aug 12 15:07 /dev/vg-data/lv-rawdisk-innodb01