Skip to content

Instantly share code, notes, and snippets.

@slowpeek
Last active February 12, 2024 04:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slowpeek/b808a4c5ccf2b29803e51d652d512203 to your computer and use it in GitHub Desktop.
Save slowpeek/b808a4c5ccf2b29803e51d652d512203 to your computer and use it in GitHub Desktop.
Clean up netplan stuff after dropbear-initramfs
#!/bin/sh
: <<'README'
This is a fix for a well-known problem [1] with dropbear-initramfs+netplan
combo.
When dropbear starts, it enables networking [2]. This results in netplan configs
for available ifaces created under /run/netplan. After unlocking, the configs
are still there preventing networkmanager from picking ifaces up: by default,
ifaces matched by the IFDOWN variable are only put down. So to make it clean, we
have to explicitly drop the netplan stuff.
Put this script under /etc/initramfs-tools/scripts/init-bottom/ and update
initramfs.
[1] https://bugs.launchpad.net/ubuntu/+source/dropbear/+bug/1813394
[2] configure_networking() from /usr/share/initramfs-tools/scripts/functions
README
PREREQ="dropbear"
prereqs() {
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0 ;;
esac
IFDOWN="*"
CONF=/etc/dropbear/dropbear.conf
[ ! -e "$CONF" ] || . "$CONF"
if [ "$BOOT" != nfs ] && [ "$IFDOWN" != none ]; then
for IFACE in /sys/class/net/$IFDOWN; do
[ -e "$IFACE" ] || continue
PLAN="/run/netplan/${IFACE##*/}.yaml"
[ ! -e "$PLAN" ] || rm "$PLAN"
done
fi
@pannal
Copy link

pannal commented Feb 11, 2024

Awesome, works flawlessly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment