Bug#860246: [PATCH] udev.postinst: preserve virtio interfaces names on upgrades, on s390x.

Dimitri John Ledkov xnox at ubuntu.com
Thu Apr 13 14:46:00 BST 2017


New udev generates stable interface names on s390x kvm instances, however, upon
upgrades existing ethX names should be preserved to prevent breaking networking
and software configurations.

Closes: #860246
LP: #1682437
---
 debian/extra/write_persistent_net_s390x_virtio | 40 ++++++++++++++++++++++++++
 debian/udev.install                            |  1 +
 debian/udev.postinst                           |  6 ++++
 3 files changed, 47 insertions(+)
 create mode 100755 debian/extra/write_persistent_net_s390x_virtio

diff --git a/debian/extra/write_persistent_net_s390x_virtio b/debian/extra/write_persistent_net_s390x_virtio
new file mode 100755
index 000000000..bbeb25085
--- /dev/null
+++ b/debian/extra/write_persistent_net_s390x_virtio
@@ -0,0 +1,40 @@
+#!/bin/sh
+set -e
+
+#
+# udevd since 232-20 learned to generate stable interface names for network
+# interfaces in kvm/qemu. However, existing machines upgrading will be using
+# the ethX names instead. The most risk-averse action is to encode
+# "persistent-net-rules" like rules to keep the ethX names on upgrades, since
+# the interface names (ethX) may be in use not only in /etc/network/interfaces
+# but in other configurations too (daemons, firewalls, etc).
+#
+# This is a one time action, and can be removed after the next stable & LTS
+# releases. (~ May 2018)
+#
+
+rulesfile=/etc/udev/rules.d/70-persistent-net.rules
+
+if [ `uname -m` != 's390x' ]
+then
+    exit 0
+fi
+
+if [ `systemd-detect-virt` != 'kvm' ]
+then
+    exit 0
+fi
+
+if [ -f $rulesfile ]
+then
+    exit 0
+fi
+
+for interface in /sys/class/net/eth*
+do
+    name=$(basename $interface)
+    address=$(cat $interface/address)
+    cat <<EOF >>$rulesfile
+SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="$address", KERNEL=="eth*", NAME="$name"
+EOF
+done
diff --git a/debian/udev.install b/debian/udev.install
index b0ab649fb..e5aae4daf 100644
--- a/debian/udev.install
+++ b/debian/udev.install
@@ -22,3 +22,4 @@ usr/share/pkgconfig/udev.pc
 ../../extra/rules/*.rules lib/udev/rules.d/
 #../../extra/*.hwdb lib/udev/hwdb.d/
 ../../extra/fbdev-blacklist.conf lib/modprobe.d/
+../../extra/write_persistent_net_s390x_virtio usr/share/systemd/
diff --git a/debian/udev.postinst b/debian/udev.postinst
index 651727994..8e69e35c2 100644
--- a/debian/udev.postinst
+++ b/debian/udev.postinst
@@ -90,6 +90,12 @@ Driver=virtio_net
 NamePolicy=onboard kernel
 EOF
   fi
+
+  # 232-20 introduced predicable interface names on s390x for virtio
+  # However, we should preserve ethX names on upgrade.
+  if dpkg --compare-versions "$2" lt-nl "232-23~"; then
+      /usr/share/systemd/write_persistent_net_s390x_virtio
+  fi
 }
 
 update_hwdb() {
-- 
2.11.0




More information about the Pkg-systemd-maintainers mailing list