Skip to content

Instantly share code, notes, and snippets.

@kaz-tk
Last active August 29, 2015 14:10
Show Gist options
  • Save kaz-tk/40ecf50e5027e2f7e3ab to your computer and use it in GitHub Desktop.
Save kaz-tk/40ecf50e5027e2f7e3ab to your computer and use it in GitHub Desktop.
Generate udev rule for Ethernet Card in PCI Address Order
#!/bin/bash
echo "" > /etc/udev/rules.d/80-pci-order_net.rules
for dir in /sys/class/net/*
do
[ -e $dir/device ] && {
addr=$(readlink $dir| grep pci|tr "\/" " " | awk '{print $5}')
driver=$(ethtool -i $(basename $dir) | grep driver)
cat >> /etc/udev/rules.d/80-pci-order_net.rules << __EOF__
# ${driver}
ACTION=="add", SUBSYSTEM=="net", BUS=="pci", KERNELS=="${addr}",NAME="eth*"
__EOF__
idx=$(expr ${idx} + 1)
}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment