From: Michael Prokop Date: Fri, 31 May 2019 14:41:50 +0000 (+0200) Subject: Fix detection of predictable network interface names X-Git-Tag: v0.89~2 X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=commitdiff_plain;h=2860f131b65664467209350e16f39f75b7b27af0 Fix detection of predictable network interface names E.g. virtio drivers might have the properties ID_NET_NAME_PATH=enp0s18 and ID_NET_NAME_SLOT=ens18. If we check only for ID_NET_NAME_PATH, then we end up with a network configuration for enp0s18, while the actual network interface name will be ens18. So instead look at all present network devices, iterate over them (ignoring the virtual interfaces like bridges + vboxnet) and check for present ID_NET_NAME_* settings, using the following precedence (as defined in link_config_apply() of systemd/src/udev/net/link-config.c): * ID_NET_NAME_FROM_DATABASE * ID_NET_NAME_ONBOARD * ID_NET_NAME_SLOT * ID_NET_NAME_PATH * ID_NET_NAME_MAC Closes: #929810 --- diff --git a/grml-debootstrap b/grml-debootstrap index d5c3f70..7953e0f 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -1730,12 +1730,28 @@ iface eth0 inet dhcp # add dhcp setting for Predictable Network Interface Names if [ -x /bin/udevadm ]; then - for interface in $(udevadm info -e | sed -n -e 's/E: ID_NET_NAME_PATH=\([^$*]\)/\1/p'); do - DEFAULT_INTERFACES="${DEFAULT_INTERFACES} + tmpfile=$(mktemp) + for interface in /sys/class/net/*; do + udevadm info --query=all --path="${interface}" > "${tmpfile}" + # skip virtual devices, like bridges, vboxnet,... + if grep -q 'P: /devices/virtual/net/' "${tmpfile}" ; then + continue + fi + + # iterate over possible naming policies by precedence (see udev/net/link-config.c), + # use and stop on first match to have same behavior as udev's link_config_apply() + for property in ID_NET_NAME_FROM_DATABASE ID_NET_NAME_ONBOARD ID_NET_NAME_SLOT ID_NET_NAME_PATH ID_NET_NAME_MAC ; do + if grep -q "${property}" "${tmpfile}" ; then + interface=$(grep "${property}" "${tmpfile}" | sed -n -e "s/E: ${property}=\([^\$*]\)/\1/p") + DEFAULT_INTERFACES="${DEFAULT_INTERFACES} allow-hotplug ${interface} iface ${interface} inet dhcp " + break + fi + done done + rm -f "${tmpfile}" fi if [ -n "$NOINTERFACES" ] ; then