Skip to content

Commit

Permalink
Prepare switch from legacy network interfaces to systemd-networkd
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkirk committed Jul 24, 2018
1 parent 242470a commit 58b9a23
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions grml-debootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 <file> 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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
# }}}
Expand Down

0 comments on commit 58b9a23

Please sign in to comment.