From 58b9a2327dd949eab1ef64f4fe16f22d2fb5dbad Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Tue, 24 Jul 2018 10:38:47 +0200 Subject: [PATCH] Prepare switch from legacy network interfaces to systemd-networkd By default grml-debootstrap used the host /etc/network/interfaces file to configure the network of the guest system. We now provide a systemd-networkd configuration enabling DHCP on all network devices next to the legacy /etc/network/interfaces which only enables DHCP on eth0 (which does not work when using the predictable devices names). If no networking option is given, this will be the new default. NOTE: systemd-networkd is currently not enabled by default. --- grml-debootstrap | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index 1c5d8b7e..b2511448 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -79,6 +79,7 @@ MNTPOINT="/mnt/debootstrap.$$" [ -n "$TIMEZONE" ] || TIMEZONE='Europe/Vienna' [ -n "$TUNE2FS" ] || TUNE2FS='tune2fs -c0 -i0' [ -n "$UPGRADE_SYSTEM" ] || UPGRADE_SYSTEM='yes' +[ -n "$USE_DEFAULT_INTERFACES" ] || USE_DEFAULT_INTERFACES="true" [ -n "$VMSIZE" ] || VMSIZE="2G" # inside the chroot system locales might not be available, so use minimum: @@ -140,11 +141,9 @@ Configuration options: --nopackages Skip installation of packages defined in /etc/debootstrap/packages --nokernel Skip installation of default kernel images. - --nointerfaces Do not copy /etc/network/interfaces from host system - to target system. - (This option is automatically enabled when using --vmfile.) - --defaultinterfaces Install a default /etc/network/interfaces file (enabling - DHCP for eth0) instead of taking over config from host system. + --nointerfaces Skip installation of default network configuration. + --defaultinterfaces Install a default /etc/systemd/network/80-dhcp.network file + (enabling DHCP for all network devices). (default) --debconf Pre-seed packages using specified pre-seed db file. --grmlrepos Enable Grml's Debian repository (deb.grml.org). --backportrepos Enable Debian's backports repository (backports.debian.org). @@ -441,10 +440,10 @@ while :; do --password) # Use specified password as password for user root shift; _opt_password="$1" ;; - --defaultinterfaces) # Install default /etc/network/interfaces + --defaultinterfaces) # Install a default /etc/systemd/network/80-dhcp.network file _opt_defaultinterfaces=T ;; - --nointerfaces) # Skip installation of /etc/network/interfaces + --nointerfaces) # Skip installation of default network configuration. _opt_nointerfaces=T ;; --nokernel) # Skip installation of default kernel images @@ -1673,6 +1672,16 @@ preparechroot() { [ -d "${CONFFILES}"/var ] && cp $VERBOSE -a -L "${CONFFILES}"/var/* "${MNTPOINT}"/var/ # network setup + + # systemd-networkd + DEFAULT_SYSTEMD_NETWORKD="# /etc/systemd/network/80-dhcp.network - generated by grml-debootstrap +[Match] +Name=en* + +[Network] +DHCP=yes +" + # legacy network interfaces DEFAULT_INTERFACES="# /etc/network/interfaces - generated by grml-debootstrap # Include files from /etc/network/interfaces.d when using @@ -1687,30 +1696,20 @@ iface eth0 inet dhcp " if [ -n "$NOINTERFACES" ] ; then - einfo "Not installing /etc/network/interfaces as requested via --nointerfaces option" ; eend 0 + einfo "Not installing /etc/systemd/network/80-dhcp.network as requested via --nointerfaces option" + eend 0 elif [ -n "$USE_DEFAULT_INTERFACES" ] ; then - einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options." + einfo "Installing default /etc/systemd/network/80-dhcp.network as requested via --defaultinterfaces options." + echo "$DEFAULT_SYSTEMD_NETWORKD" > "${MNTPOINT}/etc/systemd/network/80-dhcp.network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? elif [ -n "$VIRTUAL" ] ; then - einfo "Setting up Virtual Machine, installing default /etc/network/interfaces" - echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" - eend $? - elif [ -r /etc/network/interfaces ] ; then - einfo "Copying /etc/network/interfaces from host to target system" - cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces" - eend $? - else - ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces" + einfo "Setting up Virtual Machine, installing default /etc/systemd/network/80-dhcp.network" + echo "$DEFAULT_SYSTEMD_NETWORKD" > "${MNTPOINT}/etc/systemd/80-dhcp.network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? fi - # install config file providing some example entries - if [ -r /etc/network/interfaces.examples ] && [ ! -r "$MNTPOINT/etc/network/interfaces.examples" ] ; then - cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples" - fi - eend 0 } # }}}