[elbe-devel] [PATCH 2/2] init init-elbe.sh.mako: name network interface host0 and use dhcp on it

Torben Hohn torben.hohn at linutronix.de
Wed Apr 10 14:43:54 CEST 2019


the "persistent" naming of network interfaces is not persistent, when
different VM configurations come into play.

Somehow 33988ebe3d0b ("Enable initvm creation with newer qemu versions")
changed the network device name to enp4 during initvm installation in qemu.
When running with libvirt, it is enp3 again. That leaves the network
unconfigured.

Fix this once for all, by creating /etc/systemd/network/10-host.link
which matched the macaddr and renames the interface to host0.
Then use /etc/network/interfaces.d/host0 so that it gets configured using
dhcp.

This can potentially also fix a situation, where the initvm is run in
vmware or a different hypervisor.

Signed-off-by: Torben Hohn <torben.hohn at linutronix.de>
---
 elbepack/init/init-elbe.sh.mako | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/elbepack/init/init-elbe.sh.mako b/elbepack/init/init-elbe.sh.mako
index 8fb0e6d6..bad46bfe 100644
--- a/elbepack/init/init-elbe.sh.mako
+++ b/elbepack/init/init-elbe.sh.mako
@@ -19,6 +19,8 @@ if not opt.build_bin:
 
 if not opt.build_sources:
   buildrepo_opts += '--skip-build-source'
+
+nicmac = prj.text('buildimage/NIC/MAC', default=defs, key='nicmac')
 %>
 
 # First unset the variables which are set by the debian-installer
@@ -39,6 +41,23 @@ mkdir /buildenv/var/cache/elbe/installer
 cp initrd-cdrom.gz /buildenv/var/cache/elbe/installer
 cp vmlinuz /buildenv/var/cache/elbe/installer
 
+cat <<EOF > /buildenv/etc/systemd/network/10-host.link
+[Match]
+MACAddress=${nicmac}
+
+[Link]
+NamePolicy=
+Name=host0
+EOF
+
+cat <<EOF > /buildenv/etc/network/interfaces.d/host0
+# The primary network interface
+allow-hotplug host0
+iface host0 inet dhcp
+EOF
+
+in-target update-initramfs -u
+
 % if opt.devel:
    mkdir /buildenv/var/cache/elbe/devel
    tar xj -f elbe-devel.tar.bz2 -C /buildenv/var/cache/elbe/devel
-- 
2.11.0




More information about the elbe-devel mailing list