Skip to content

Instantly share code, notes, and snippets.

@craigtracey
Created August 15, 2013 21:29
Show Gist options
  • Save craigtracey/6245105 to your computer and use it in GitHub Desktop.
Save craigtracey/6245105 to your computer and use it in GitHub Desktop.
Preseed udev rules. Run these in a late command...especially useful when you want to bond devices.
#!/bin/bash
# this sucks, but I want my devices enumerated the way I want them
declare -A mac_devices
mac_devices["aa:bb:cc:dd:ee:f1"]="eth0"
mac_devices["aa:bb:cc:dd:ee:f2"]="eth1"
mac_devices["aa:bb:cc:dd:ee:f3"]="eth2"
mac_devices["aa:bb:cc:dd:ee:f4"]="eth3"
UDEV_NET_RULES="/etc/udev/rules.d/70-persistent-net.rules"
echo "# This file was at least partially configured via pressed late command" > $UDEV_NET_RULES
for MAC in `ifconfig -a | grep HWaddr | awk '{print $5}'`; do
for i in "${!mac_devices[@]}"; do
if [ "$MAC" == "$i" ]; then
echo "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$i\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"${mac_devices[$i]}\"" >> $UDEV_NET_RULES
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment