From e7162cbba6161ea316f9415b672d842074bafd4a Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Wed, 28 Oct 2020 13:27:09 -0300 Subject: Fix: kvmx-create: netplan-based systems --- kvmx-create | 74 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 15 deletions(-) (limited to 'kvmx-create') diff --git a/kvmx-create b/kvmx-create index 7137060..51aa0e4 100755 --- a/kvmx-create +++ b/kvmx-create @@ -246,10 +246,11 @@ function kvmx_create_custom { tac $WORK/etc/hosts | $SUDO tee $WORK/etc/hosts.new > /dev/null kvmx_sudo_run mv $WORK/etc/hosts.new $WORK/etc/hosts - # Ubuntu needs this fix so we can continue - if [ "$distro" == "ubuntu" ]; then + # Systems using netplan needs this temporary fix so we can continue + #if [ "$distro" == "ubuntu" ]; then + if [ -d "$WORK/etc/netplan" ]; then # Points to ../run/systemd/resolve/stub-resolv.conf - kvmx_sudo_run rm $WORK/etc/resolv.conf + kvmx_sudo_run mv $WORK/etc/resolv.conf $WORK/etc/resolv.conf.dist # Temporary resolver: OpenNIC cat <<-EOF | $SUDO tee $WORK/etc/resolv.conf > /dev/null @@ -372,28 +373,65 @@ EOF # Second stage procedure function __kvmx_create_custom_second_stage { if [ ! -z "$net_ip" ] && [ ! -z "$net_mask" ] && [ ! -z "$net_gateway" ]; then - # Networking - # See #799253 - virtio ens3 network interface - # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253 - for net_dev in eth0 ens3 ens4; do - cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/$net_dev > /dev/null + if [ -d "$WORK/etc/network/interfaces.d" ]; then + # Networking + # See #799253 - virtio ens3 network interface + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253 + for net_dev in eth0 ens3 ens4; do + cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/$net_dev > /dev/null auto $net_dev iface $net_dev inet static address $net_ip netmask $net_mask gateway $net_gateway EOF - done + done + elif [ -d "$WORK/etc/netplan" ]; then + cat <<-EOF | $SUDO tee $WORK/etc/netplan/99_config.yaml > /dev/null +network: + version: 2 + renderer: networkd + ethernets: +EOF + # Using OpenNIC + for net_dev in eth0 ens3 ens4; do + cat <<-EOF | $SUDO tee -a $WORK/etc/netplan/99_config.yaml > /dev/null + $net_dev: + addresses: + - $net_ip + gateway4: $net_gateway + nameservers: + addresses: [172.98.193.42, 142.4.204.111] +EOF + done + fi else - # Networking - # See #799253 - virtio ens3 network interface - # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253 - for net_dev in eth0 ens3 ens4; do - cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/$net_dev > /dev/null + if [ -d "$WORK/etc/network/interfaces.d" ]; then + # Networking + # See #799253 - virtio ens3 network interface + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=799253 + for net_dev in eth0 ens3 ens4; do + cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/$net_dev > /dev/null allow-hotplug $net_dev iface $net_dev inet dhcp EOF - done + done + elif [ -d "$WORK/etc/netplan" ]; then + cat <<-EOF | $SUDO tee $WORK/etc/netplan/99_config.yaml > /dev/null +network: + version: 2 + renderer: networkd + ethernets: +EOF + + for net_dev in eth0 ens3 ens4; do + cat <<-EOF | $SUDO tee -a $WORK/etc/netplan/99_config.yaml > /dev/null + $net_dev: + dhcp4: true +EOF + done + + fi fi # DNS config @@ -485,6 +523,12 @@ EOF kvmx_sudo_run chroot $WORK/ chown -R $user.$user /home/$user echo "$user:$password" | kvmx_sudo_run chroot $WORK/ chpasswd + + # Restore /etc/resolv.conf + if [ -e "$WORK/etc/resolv.conf.dist" ]; then + kvmx_sudo_run rm -f "$WORK/etc/resolv.conf" + kvmx_sudo_run mv "$WORK/etc/resolv.conf.dist" "$WORK/etc/resolv.conf" + fi } # Load config file -- cgit v1.2.3