Last active
October 29, 2017 12:09
-
-
Save Tydus/5f2d98a399d6e7ae49a3cf2a277cf429 to your computer and use it in GitHub Desktop.
Rename ethx and wlanx to persistent names for OpenWrt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ifrename.sh: rename ethx and wlanx to persistent names | |
# Dependency: ip ethtool | |
# See also: https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-net_id.c | |
# TODO: currently only support pci-e devices | |
ip -br l | cut -d' ' -f1 | while read i; do | |
prefix=$(echo "$i" | cut -c-2) | |
if echo $i | grep -q '@' ; then | |
continue | |
fi | |
if [ "x$prefix" == "xet" ]; then | |
prefix="en" | |
elif [ "x$prefix" == "xwl" ]; then | |
prefix="wl" | |
else | |
continue | |
fi | |
echo "$i:$prefix:$(ethtool -i "$i" | grep bus-info | cut -d' ' -f2)" | sed 's@[:.]@ @g' | |
done | while read oldname prefix domain port slot function; do | |
newname=$( | |
printf "%sP%dp%ds%df%d\n" $prefix "0x$domain" "0x$port" "0x$slot" "0x$function" | | |
sed 's@[pP]0@@g' | |
) | |
echo "Rename $oldname to $newname" | |
ip link set $oldname down | |
ip link set $oldname name $newname | |
ip link set $newname up | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment