Showing posts with label udev. Show all posts
Showing posts with label udev. Show all posts

udev part1

Udev was created to respond to hotplug type of events. Much documentation refers to creating devices in response to new devices that have appeared. But, udev is more general; it can run arbitrary userspace commands in response to a new device appearing - or to whatever events it receives from the kernel.

udev 's main purpose is to act upon peripheral detection and hot-plugging, including actions that return control to the kernel, e.g., loading kernel modules or device firmware.

we can assign particular name to any interface name e.g based on pci address or mac address

here ill assign based on pci address. first query the device information

root@myserver:/etc/udev/rules.d# udevadm info -a /sys/class/net/eth0



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/pci0000:00/0000:00:03.0/net/eth0':

KERNEL=="eth0"

SUBSYSTEM=="net"

DRIVER==""

ATTR{ifindex}=="2"

ATTR{addr_assign_type}=="0"

ATTR{address}=="08:00:27:19:4c:c3"

ATTR{carrier}=="1"

ATTR{gro_flush_timeout}=="0"

ATTR{operstate}=="up"

ATTR{carrier_up_count}=="1"

ATTR{proto_down}=="0"

ATTR{tx_queue_len}=="1000"

ATTR{dev_port}=="0"

ATTR{flags}=="0x1003"

ATTR{link_mode}=="0"

ATTR{carrier_changes}=="2"

ATTR{netdev_group}=="0"

ATTR{duplex}=="full"

ATTR{carrier_down_count}=="1"

ATTR{dormant}=="0"

ATTR{dev_id}=="0x0"

ATTR{type}=="1"

ATTR{mtu}=="1500"

ATTR{broadcast}=="ff:ff:ff:ff:ff:ff"

ATTR{addr_len}=="6"

ATTR{iflink}=="2"

ATTR{ifalias}==""

ATTR{speed}=="1000"



looking at parent device '/devices/pci0000:00/0000:00:03.0':

KERNELS=="0000:00:03.0"

SUBSYSTEMS=="pci"

DRIVERS=="e1000"

ATTRS{local_cpus}=="f"

ATTRS{enable}=="1"

ATTRS{dma_mask_bits}=="32"

ATTRS{msi_bus}=="1"

ATTRS{subsystem_vendor}=="0x8086"

ATTRS{revision}=="0x02"

ATTRS{ari_enabled}=="0"

ATTRS{class}=="0x020000"

ATTRS{driver_override}=="(null)"

ATTRS{device}=="0x100e"

ATTRS{subsystem_device}=="0x001e"

ATTRS{local_cpulist}=="0-3"

ATTRS{vendor}=="0x8086"

ATTRS{consistent_dma_mask_bits}=="32"

ATTRS{broken_parity_status}=="0"

ATTRS{numa_node}=="-1"

ATTRS{d3cold_allowed}=="1"

ATTRS{irq}=="19"



looking at parent device '/devices/pci0000:00':

KERNELS=="pci0000:00"

SUBSYSTEMS==""

DRIVERS==""





root@myserver:/home/support# cat /etc/udev/rules.d/70-persistent-net.rules



ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:08.0", NAME:="eth0"





ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:03.0", NAME:="eth1"





ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:0a.0", NAME:="eth2"





ACTION=="add",DRIVERS=="e1000", SUBSYSTEMS=="pci", KERNELS=="0000:00:09.0", NAME:="backup"





If rules fail to reload automatically:

# udevadm control --reload
To manually force udev to trigger your rules:


# udevadm trigger
update-initramfs -u -k all






https://wiki.archlinux.org/title/udev#udev_rule_example

https://wiki.debian.org/udev