Last active
October 9, 2025 15:09
-
-
Save PedroCavaleiro/351ed56d7d8caf4b7bc1b6a621f344be to your computer and use it in GitHub Desktop.
Debian 13 upgrade script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # A sequence of scripts to safely upgrade from Debian 12 to Debian 13 | |
| # This is based of this guide https://linuxconfig.org/how-to-upgrade-debian-to-latest-version | |
| # This script ONLY executes the commands, some commands require user input for confirmations | |
| # EMERGENCY RECOVERY | |
| # If the upgrade fails and your system becomes unbootable, use a Debian 13 live USB to access recovery tools and restore your system from backups or fix package conflicts. | |
| # Run as root (by logging in as root) | |
| # Use the flag --no-reboot to prevent the system from rebooting after completing the configuration | |
| # Pre-Upgrade System Preparation | |
| echo "Pre-Upgrade System Preparation" | |
| sleep 1 | |
| tar -czf /backup/etc-backup-$(date +%Y%m%d).tar.gz /etc | |
| dpkg --get-selections > /backup/package-selections-$(date +%Y%m%d).txt | |
| apt update | |
| apt upgrade -y | |
| apt dist-upgrade -y | |
| apt clean | |
| apt autoremove -y | |
| apt --fix-broken install | |
| dpkg --configure -a | |
| # Repository Configuration Update | |
| echo "" | |
| echo "Repository Configuration Update" | |
| sleep 1 | |
| cp /etc/apt/sources.list /etc/apt/sources.list.bookworm-backup | |
| cp -r /etc/apt/sources.list.d /etc/apt/sources.list.d.bookworm-backup | |
| sed -i 's/bookworm/trixie/g' /etc/apt/sources.list | |
| find /etc/apt/sources.list.d -name "*.list" -exec sed -i 's/bookworm/trixie/g' {} \; | |
| apt update | |
| # Debian 13 Upgrade Process | |
| echo "" | |
| echo "Debian 13 Upgrade Process" | |
| sleep 1 | |
| apt upgrade --without-new-pkgs -y | |
| apt full-upgrade -y | |
| # Post-Upgrade Verification | |
| echo "" | |
| echo "Post-Upgrade Verification" | |
| sleep 1 | |
| cat /etc/debian_version | |
| cat /etc/os-release | |
| apt autoremove -y | |
| apt autoclean | |
| apt update | |
| apt list --upgradable | |
| # --- Reboot handling --- | |
| if [[ "$1" == "--no-reboot" ]]; then | |
| echo "No Reboot flag detected. Manual reboot is required." | |
| else | |
| echo "Upgrade completed, rebooting..." | |
| sleep 3 | |
| systemctl reboot | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment