From e56284b489f44bee9acf606a2c140d01e6d912ed Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Tue, 24 Jul 2018 10:38:47 +0200 Subject: [PATCH 1/4] 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 target system. This might have been ok, when grml-debootrap was primarily run form a Grml live system. But this might expose to much unwanted information about the host system when run without it. If the user really needs to copy any files from the host to the target system, she should use a post-script. While at it we also removed copying the interfaces.examples functionality. If no networking option is given, the --defaultinterfaces option will be the new default. We now provide a systemd-networkd configuration enabling DHCP on all ethernet 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). NOTE: systemd-networkd is currently not enabled by default. --- grml-debootstrap | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index 103946cd..5acd60d5 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" [ -n "$GRUB_INSTALL" ] || GRUB_INSTALL='yes' @@ -141,11 +142,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). @@ -449,10 +448,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 @@ -1713,6 +1712,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 @@ -1753,33 +1762,16 @@ iface ${interface} inet dhcp fi 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." mkdir -p "${MNTPOINT}/etc/network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? - elif [ -n "$VIRTUAL" ] ; then - einfo "Setting up Virtual Machine, installing default /etc/network/interfaces" - mkdir -p "${MNTPOINT}/etc/network" - echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" - eend $? - elif [ -r /etc/network/interfaces ] ; then - einfo "Copying /etc/network/interfaces from host to target system" - mkdir -p "${MNTPOINT}/etc/network" - cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces" + 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" eend $? - else - ewarn "Couldn't read /etc/network/interfaces, installing default /etc/network/interfaces" - mkdir -p "${MNTPOINT}/etc/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 - mkdir -p "${MNTPOINT}/etc/network" - cp /etc/network/interfaces.examples "$MNTPOINT/etc/network/interfaces.examples" fi if [ -n "${SSHCOPYID}" ] ; then From 4e1cd1c6b949c4754041a410f599e4a491df48c0 Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Wed, 25 Jul 2018 11:08:24 +0200 Subject: [PATCH 2/4] Update NEWS file (using systemd-networkd by default) --- debian/NEWS | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/debian/NEWS b/debian/NEWS index 244817a1..8c4f27b9 100644 --- a/debian/NEWS +++ b/debian/NEWS @@ -1,3 +1,16 @@ +grml-debootstrap (0.82+nmu1) UNRELEASED; urgency=medium + + Starting with this release grml-debootstrap enables systemd-networkd by + default on Debian/stretch systems. + + The old default behaviour where the host /etc/network/interfaces was used to + deploy the target network configuration was dropped in favor of using the + --defaultinterfaces option where all ethernet devices are configured to use + DHCP via systemd-networkd. For legacy reasons we also provide a + /etc/network/interfaces where `eth0` is configured to use DHCP. + + -- Darshaka Pathirana Wed, 25 Jul 2018 11:02:01 +0200 + grml-debootstrap (0.70) unstable; urgency=medium The 'contrib' and 'non-free' repositories are no longer From 3a8e642768096085fd6c88a043569e064731b094 Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Wed, 25 Jul 2018 11:21:30 +0200 Subject: [PATCH 3/4] Update documenatation and output for networking options --- grml-debootstrap | 5 ++--- grml-debootstrap.8.txt | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index 5acd60d5..cd57ae07 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -143,8 +143,7 @@ Configuration options: /etc/debootstrap/packages --nokernel Skip installation of default kernel images. --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) + --defaultinterfaces Install default network configuration. (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). @@ -1762,7 +1761,7 @@ iface ${interface} inet dhcp fi if [ -n "$NOINTERFACES" ] ; then - einfo "Not installing /etc/systemd/network/80-dhcp.network as requested via --nointerfaces option" + einfo "Not installing default network configuration as requested via --nointerfaces option" eend 0 elif [ -n "$USE_DEFAULT_INTERFACES" ] ; then einfo "Installing default /etc/network/interfaces as requested via --defaultinterfaces options." diff --git a/grml-debootstrap.8.txt b/grml-debootstrap.8.txt index 5f909bc3..3053eae5 100644 --- a/grml-debootstrap.8.txt +++ b/grml-debootstrap.8.txt @@ -155,9 +155,12 @@ Options and environment variables Skip debootstrap, only do configuration to the target. + *--nointerfaces*:: - Do not copy /etc/network/interfaces from host system to the target. + Skip installation of a default network configuration. + Does not provide a default /etc/systemd/network/80-dhcp.network and + /etc/network/interfaces on the target system. *--nokernel*:: @@ -255,7 +258,7 @@ Options and environment variables Set up a Virtual Machine using a regular file instead of installing to a partition/block device or directory. This allows deployment of a Virtual - Machine. The options needs to be combined with the --target option + Machine. ('qemu-img create -f raw ...' is executed on the specified target). This option automatically enables the --defaultinterfaces option. Usage example: --vmfile --target /mnt/sda1/qemu.img From 3289386ad50fb1851a04f341daf97c67976f58b7 Mon Sep 17 00:00:00 2001 From: Darshaka Pathirana Date: Thu, 31 Oct 2019 16:56:14 +0100 Subject: [PATCH 4/4] Add new configuration option --hostinterfaces The new option --hostinterfaces imitates to old default behavior of grml-debootstrap where the host network configuration was copied from the host to target system. We now default to --defaultinterfaces where /etc/network/interfaces and /etc/network/systemd/80-dhcp.network are installed. The option conflicts with --defaultinterfaces and --nointerfaces. --- grml-debootstrap | 45 +++++++++++++++++++++++++++++++++++++----- grml-debootstrap.8.txt | 32 +++++++++++++++++------------- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/grml-debootstrap b/grml-debootstrap index cd57ae07..393380e1 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -144,6 +144,7 @@ Configuration options: --nokernel Skip installation of default kernel images. --nointerfaces Skip installation of default network configuration. --defaultinterfaces Install default network configuration. (default) + --hostinterfaces Copy host network configuration from host to target system. --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). @@ -345,7 +346,7 @@ fi # }}} # cmdline handling {{{ -CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs,sshcopyid +CMDLINE_OPTS=mirror:,iso:,release:,target:,mntpoint:,debopt:,defaultinterfaces,hostinterfaces,interactive,nodebootstrap,nointerfaces,nokernel,nopackages,filesystem:,config:,confdir:,packages:,chroot-scripts:,scripts:,post-scripts:,pre-scripts:,debconf:,vm,vmfile,vmsize:,keep_src_list,hostname:,password:,nopassword,grmlrepos,backportrepos,bootappend:,grub:,efi:,arch:,insecure,verbose,help,version,force,debug,contrib,non-free,remove-configs,sshcopyid _opt_temp=$(getopt --name grml-debootstrap -o +m:i:r:t:p:c:d:vhV --long \ $CMDLINE_OPTS -- "$@") @@ -447,9 +448,12 @@ while :; do --password) # Use specified password as password for user root shift; _opt_password="$1" ;; - --defaultinterfaces) # Install a default /etc/systemd/network/80-dhcp.network file + --defaultinterfaces) # Install a default network configuration _opt_defaultinterfaces=T ;; + --hostinterfaces) # Copy host network configuration from host to target system + _opt_hostinterfaces=T + ;; --nointerfaces) # Skip installation of default network configuration. _opt_nointerfaces=T ;; @@ -560,6 +564,7 @@ done [ "$_opt_password" ] && ROOTPASSWORD=$_opt_password [ "$_opt_nopassword" ] && NOPASSWORD='yes' [ "$_opt_defaultinterfaces" ] && USE_DEFAULT_INTERFACES="true" +[ "$_opt_hostinterfaces" ] && USE_HOST_INTERFACES="true" [ "$_opt_nointerfaces" ] && NOINTERFACES="true" [ "$_opt_nokernel" ] && NOKERNEL="true" [ "$_opt_sshcopyid" ] && SSHCOPYID="true" @@ -598,6 +603,24 @@ if [ -n "$ISO" ] && [[ "$DEBOOTSTRAP" =~ mmdebstrap$ ]] ; then bailout 1 fi +if [ "$_opt_defaultinterfaces" ] && [ "$_opt_hostinterfaces" ] ; then + eerror "The options --defaultinterfaces and --hostinterfaces conflict with each other, please drop one option from your command line." + eend 1 + bailout 1 +fi + +if [ "$_opt_defaultinterfaces" ] && [ "$_opt_nointerfaces" ] ; then + eerror "The options --defaultinterfaces and --nointerfaces conflict with each other, please drop one option from your command line." + eend 1 + bailout 1 +fi + +if [ "$_opt_nointerfaces" ] && [ "$_opt_hostinterfaces" ] ; then + eerror "The options --nointerfaces and --hostinterfaces conflict with each other, please drop one option from your command line." + eend 1 + bailout 1 +fi + if [ "$DEBUG" = "true" ] ; then set -x fi @@ -1764,18 +1787,30 @@ iface ${interface} inet dhcp einfo "Not installing default network configuration 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/network/interfaces as requested via --defaultinterfaces option" mkdir -p "${MNTPOINT}/etc/network" echo "$DEFAULT_INTERFACES" > "${MNTPOINT}/etc/network/interfaces" eend $? - einfo "Installing default /etc/systemd/network/80-dhcp.network as requested via --defaultinterfaces options." + einfo "Installing default /etc/systemd/network/80-dhcp.network as requested via --defaultinterfaces option" + mkdir -p "${MNTPOINT}/etc/systemd/network" echo "$DEFAULT_SYSTEMD_NETWORKD" > "${MNTPOINT}/etc/systemd/network/80-dhcp.network" eend $? + elif [ -n "$USE_HOST_INTERFACES" ] ; then + if [ -r /etc/network/interfaces ] ; then + einfo "Copying /etc/network/interfaces from host to target system as requested via --hostinterfaces option" + mkdir -p "${MNTPOINT}/etc/network" + cp $VERBOSE /etc/network/interfaces "${MNTPOINT}/etc/network/interfaces" + elif ls /etc/systemd/network/* &>/dev/null ; then + einfo "Copy /etc/systemd/network/* from host to target system as requested via --hostinterfaces option" + mkdir -p "${MNTPOINT}/etc/systemd/network" + cp $VERBOSE /etc/systemd/network/* "${MNTPOINT}/etc/systemd/network" + fi + eend $? fi if [ -n "${SSHCOPYID}" ] ; then if ssh-add -L >/dev/null 2>&1 ; then - einfo "Use locally available public keys to authorise root login on the target system as requested via --sshcopyid option." + einfo "Use locally available public keys to authorise root login on the target system as requested via --sshcopyid option" mkdir -p "${MNTPOINT}"/root/.ssh chmod 0700 "${MNTPOINT}"/root/.ssh if ssh-add -L >> "${MNTPOINT}"/root/.ssh/authorized_keys ; then diff --git a/grml-debootstrap.8.txt b/grml-debootstrap.8.txt index 3053eae5..68a9a786 100644 --- a/grml-debootstrap.8.txt +++ b/grml-debootstrap.8.txt @@ -80,16 +80,16 @@ Options and environment variables *--debug*:: - Execute in very verbose way. Useful for debugging possible problems - with grml-debootstrap or identify what's actually executed. + Execute in very verbose way. Useful for debugging possible problems + with grml-debootstrap or identify what's actually executed. *--defaultinterfaces*:: - Install a default /etc/network/interfaces file (enabling DHCP for all local - Ethernet, WLAN and WWAN interfaces using predictable network interface names - and using eth0 as traditional interface name for backward compatibility) - instead of taking over config from host system. - This option is automatically enabled when using --vm or --vmfile. + Install a default network configuration, that is a default + /etc/network/interfaces file (enabling DHCP for the first detected Ethernet + interfaces using predictable network interface names and using eth0 as + traditional interface name for backward compatibility). + This is the default and conflicts with --hostinterfaces and --nointerfaces. *--efi* _device_:: @@ -130,6 +130,13 @@ Options and environment variables Show summary of options and exit. +*--hostinterfaces*:: + + Copy host network configuration from host to target system, copying + /etc/network/interfaces and/or /etc/systemd/network/* if they exists. + This behavior used to be the default till grml-debootstrap v0.90. + Conflicts with --defaultinterfaces and --nointerfaces. + *--hostname* _hostname_:: Use specified hostname instead of the default (being $HOSTNAME or if unset 'grml'). @@ -155,12 +162,12 @@ Options and environment variables Skip debootstrap, only do configuration to the target. - *--nointerfaces*:: Skip installation of a default network configuration. - Does not provide a default /etc/systemd/network/80-dhcp.network and + Does neither provide a default /etc/systemd/network/80-dhcp.network nor /etc/network/interfaces on the target system. + Conflicts with --defaultinterfaces and --hostinterfaces. *--nokernel*:: @@ -251,7 +258,6 @@ Options and environment variables partitioned. This allows deployment of a Virtual Machine. The options needs to be combined with the --target option. - This option automatically enables the --defaultinterfaces option. Usage example: --vm --target /dev/mapper/your-vm-disk *--vmfile*:: @@ -260,7 +266,6 @@ Options and environment variables partition/block device or directory. This allows deployment of a Virtual Machine. ('qemu-img create -f raw ...' is executed on the specified target). - This option automatically enables the --defaultinterfaces option. Usage example: --vmfile --target /mnt/sda1/qemu.img *--vmsize* _size_:: @@ -281,9 +286,8 @@ docs and /etc/debootstrap/config for further information. Networking ---------- -By default (that is, if none of the options *--nointerfaces*, -*--defaultinterfaces*, *--vmfile* or *--vm* are given) /etc/network/interfaces -will be copied from the host to the target system. +By default a default network configuration is installed, see *--defaultinterfaces*. +To change the behavior, see *--nointerfaces* and *--hostinterfaces*. Usage examples ---------------