Skip to content

Instantly share code, notes, and snippets.

@Blener
Created August 27, 2026 15:51
Show Gist options
  • Select an option

  • Save Blener/419126f67399aab97fb48bfdaf9e27b9 to your computer and use it in GitHub Desktop.

Select an option

Save Blener/419126f67399aab97fb48bfdaf9e27b9 to your computer and use it in GitHub Desktop.
Update LXC Debian 12 to 13 checking if the container can be upgraded
#!/bin/bash
set -euo pipefail
#based on https://gist.github.com/aerodomigue/0320ec3dffbc60caeaee8a6fc83cb470, thank you aerodomigue
# --- Safety check: only run on Debian 12 (bookworm) ---
if [ ! -r /etc/os-release ]; then
echo "ERROR: /etc/os-release not found, cannot verify OS. Aborting." >&2
exit 1
fi
. /etc/os-release
if [ "${ID:-}" != "debian" ]; then
echo "ERROR: This is not Debian (detected ID='${ID:-unknown}', PRETTY_NAME='${PRETTY_NAME:-unknown}')." >&2
echo "This script only supports upgrading Debian 12 (bookworm) to 13 (trixie). Aborting." >&2
exit 1
fi
if [ "${VERSION_CODENAME:-}" != "bookworm" ]; then
echo "ERROR: Expected Debian codename 'bookworm', found '${VERSION_CODENAME:-unknown}'." >&2
echo "This container is either already upgraded or on an unsupported version. Aborting." >&2
exit 1
fi
echo "Detected Debian 12 (bookworm). Proceeding with upgrade to Debian 13 (trixie)..."
# Update source from bookworm to trixie
sed -i 's/bookworm/trixie/g' /etc/apt/sources.list
[ -d /etc/apt/sources.list.d ] && sed -i 's/bookworm/trixie/g' /etc/apt/sources.list.d/*.list 2>/dev/null || true
apt-get update
# Upgrade to trixie
DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" dist-upgrade -y
# Disable services that break in LXC / containers (harmless if not present)
systemctl disable --now systemd-networkd-wait-online.service || true
systemctl disable --now systemd-networkd.service || true
systemctl disable --now ifupdown-wait-online || true
# Install ifupdown2 (better networking stack for LXC/VMs) — only if it's actually available
if apt-cache show ifupdown2 >/dev/null 2>&1; then
apt-get install -y ifupdown2
else
echo "WARNING: ifupdown2 not available in the repos — re-enabling systemd-networkd instead so networking still works." >&2
systemctl enable --now systemd-networkd.service || true
systemctl enable --now systemd-networkd-wait-online.service || true
fi
# Cleanup
apt-get autoremove --purge -y
apt-get clean
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment