- A+
Version:1.0 StartHTML:000000249 EndHTML:000048496 StartFragment:000007013 EndFragment:000048434 StartSelection:000007247 EndSelection:000048404 SourceURL:https://unix.stackexchange.com/questions/39370/how-to-reload-udev-rules-without-rebootkernel - How to reload udev rules without reboot? - Unix & Linux Stack Exchange
Udev uses the inotify mechanism to watch for changes in the rules directory, in both the library and in the local configuration trees (typically located at /lib/udev/rules.d
and /etc/udev/rules.d
). So you don't need to do anything when you change a rules file.
You only need to notify the udev daemon explicitly if you're doing something unusual, for example if you have a rule that includes files in another directory. Then you can use the usual convention for asking daemons to reload their configuration: send a SIGHUP (pkill -HUP udevd
). Or you can use the udevadm
command: udevadm control --reload-rules
.
The udev rules are only applied when a device is added. If you want to reapply the rules to a device that is already connected, you need to do this explicitly, by calling udevadm trigger
with the right options to match the device(s) whose configuration has changed, e.g. udevadm trigger --attr-match=vendor='Yoyodyne' --attr-match=model='Frobnicator 300'
.
I'm adding this because some day I will need it... again.
Sometimes you get an incorrect matching of ethernet device numbers and MAC addresses. Sometimes this is really important, like when running in a VM and each device is assigned to a different VLAN.
- Bring the network interfaces down, then
- modify
/etc/udev/rules.d/70-persistent-net.rules
(or its equivalent) - re-load with
udevadm control --reload-rules
- re-trigger with
udevadm trigger --attr-match=subsystem=net
- bring the network interfaces up.
I was surprised how well this worked.
-
5on Red Hat:
service network stop && udevadm control --reload-rules; udevadm trigger --attr-match=subsystem=net; service network start
– Alexander Torstling Feb 19 '15 at 12:40 -
1On Debian testing 'udevadm trigger --attr-match=subsystem=net' does not work. I had to unplug and plug usb ethernet card only then udev triggered new rule. – Trismegistos Jun 6 '17 at 12:55
-
I'd be willing to bet, Trismegistos, that the unplug/plug is akin to removing and reloading the network driver, as per Clayton Dukes' answer. – Mike S Nov 28 '17 at 23:58
I am not sure if this applies, and this is definitely an older post but it came up pretty high my web search for udev info so I thought I might share some knowledge.
You can trigger udev rules manually for specific devices. This applies only to redhat-related distros (centos fedora etc etc etc)
Once you make the relevant changes in your rules file (/etc/udev/rules.d/whateveryoucalledyourrules
), you can echo change
in to the device's uevent.
echo change > /sys/block/devname/partname1/uevent
This will force a udev rule reading for ONLY this device. Much better, and more targeted in my opinion.
Please note that more recent versions of udev have dropped the inotify support so the reloading of the rules on change is needed more often these days.
-
15
For me, below command sequence has worked as it is desired.
I have done modifications in /etc/udev/rules.d/70-persistent-net.rules
to change the eth
number and to reload them without rebooting.
/etc/init.d/networking stop
/etc/init.d/udev stop
udevadm control --reload-rules
/etc/init.d/udev start
/etc/init.d/networking start
By following this, It was successfully loaded in run time without rebooting the machine.
Any suggestion or recommendations on this are welcome, as I have discovered this on my own by reading the man pages.
I'm adding the correct answer here because it took me a while to notice it in the comment from @enthusiasticgeek. All you need to do (assuming you are on the console of the server - clearly this is bad to do if you are ssh'd in!):
- Get a list of the interface module(s) being used:
cat /etc/udev/rules.d/70-persistent-net.rules | grep "PCI device" | perl -pe 's/.*\((\w+)\).*/$1/g'| uniq
In my case, it's igb
, so it prints just that.
- type
sudo rmmod igb
(replaceigb
with your card driver obtained from step 1.
next, edit /etc/udev/rules.d/70-persistent-net.rules
as needed, then load the module again using modprobe igb
, again replacing igb
with yours.
-
This, combined with Otheus' answer, was the secret sauce that enabled me to fix my Mellanox network card config without a machine reboot. I believe the loading of the driver and the udevadm read of the persistent-net.rules file is roughly akin to what the system does when it's booting. – Mike S Nov 29 '17 at 0:00
- 我的微信
- 这是我的微信扫一扫
- 我的电报
- 这是我的电报扫一扫
udevtrigger
afterwards? – Nils May 26 '12 at 20:28udevtrigger
(or ratherudevadm trigger
on most distributions) instead (that, or plug the device out and back it).--reload-rules
is almost always useless as it happens automatically. – Gilles Mar 5 '13 at 10:28udevadm trigger
did the trick on CentOS 6 for me. – astrostl Aug 7 '13 at 18:19udevtrigger
orudevadm trigger
did not work for me. I found some devices will work after unloading and loading the module for the same (assuming it is loadable module). What I found out is one does not necessarily have to reboot the system. Example for a network device, I dormmod ixgbe
,rmmod tg3
,rmmod e1000
thenmodprobe ixgbe
,modprobe tg3
,modprobe e1000
depending on type of network driver. – enthusiasticgeek Jan 22 '15 at 20:25