Rollback-Strategien
Ubuntus do-release-upgrade unterstützt keine nativen Downgrades. Wenn nach einem Upgrade schwerwiegende Probleme auftreten, müssen Sie sich auf im Voraus erstellte Rollback-Pläne verlassen. In diesem Artikel werden mehrere praktische Rollback-Strategien behandelt.
Vergleich der Rollback-Optionen
| Option | Wiederherstellungsgeschwindigkeit | Komplexität der Vorbereitung | Anwendungsfall |
|---|---|---|---|
| Zeitverschiebung | Schnell (Minuten) | Niedrig | Desktop- und kleine Server |
| LVM-Snapshot | Schnell (Minuten) | Mittel | Systeme, die LVM verwenden |
| Btrfs-Snapshot | Sehr schnell | Mittel | Btrfs-Dateisystem |
| dd-Disk-Image | Langsam (abhängig von der Festplattengröße) | Niedrig | Universelle Option |
| Backup wiederherstellen + neu installieren | Langsam | Hoch | Letzter Ausweg |
| Snapshot der Cloud-Plattform | Schnell | Niedrig | Cloud-Server |
Timeshift-Snapshot-Wiederherstellung
Timeshift ist das benutzerfreundlichste System-Snapshot-Tool und unterstützt sowohl den RSYNC- als auch den Btrfs-Modus.
Erstellen eines Snapshots vor dem Upgrade
# Install Timeshift
sudo apt install timeshift -y
# Create a snapshot
sudo timeshift --create --comments "Pre-upgrade backup" --tags D
# List snapshots
sudo timeshift --listWiederherstellung aus einem Snapshot
Methode 1: Das System ist immer noch bootfähig
# List available snapshots
sudo timeshift --list
# Restore a specific snapshot
sudo timeshift --restore --snapshot "2026-03-24_10-00-00"
# You will be prompted to confirm; choose what to restore
# Reboot after restoration is complete
sudo rebootMethode 2: System kann nicht booten
- Booten Sie von einem Ubuntu Live USB
- Installieren Sie Timeshift und führen Sie es in der Live-Umgebung aus:
# In the live environment
sudo apt update
sudo apt install timeshift -y
# Timeshift will automatically detect snapshots on disk
sudo timeshift --list
# Restore a snapshot
sudo timeshift --restore --snapshot "2026-03-24_10-00-00"
sudo rebootTimeshift-Notizen
- Timeshift sichert
/homestandardmäßig nicht (im RSYNC-Modus); Benutzerdaten müssen separat gesichert werden - Snapshots erfordern ausreichend Speicherplatz
- Snapshots im RSYNC-Modus nehmen mit der Zeit an Größe zu (inkrementell)
- Der Btrfs-Modus ist effizienter, erfordert jedoch das Btrfs-Dateisystem
LVM-Snapshot-Rollback
Wenn das System LVM verwendet (die Standardoption während der Ubuntu Server-Installation), können Sie LVM-Snapshots für ein schnelles Rollback verwenden.
Erstellen eines LVM-Snapshots vor dem Upgrade
# View existing logical volumes
sudo lvs
sudo vgs # Confirm the volume group has enough free space
# Create a snapshot for the root partition (requires free space in the volume group)
sudo lvcreate -L 10G -s -n root-snap /dev/ubuntu-vg/ubuntu-lv
# If there is a separate /var partition
sudo lvcreate -L 5G -s -n var-snap /dev/ubuntu-vg/var-lv
# Verify the snapshot
sudo lvsRollback von einem LVM-Snapshot
# Method 1: Merge the snapshot (requires unmounting or operating from Live USB)
# If you can still access the system
# Mark the snapshot for merge (takes effect on next activation)
sudo lvconvert --merge /dev/ubuntu-vg/root-snap
# The merge will execute automatically after reboot
sudo reboot
# Method 2: Operate from Live USB
# Boot from Live USB
sudo apt install lvm2 -y
sudo vgchange -ay # Activate volume groups
# Execute the merge
sudo lvconvert --merge /dev/ubuntu-vg/root-snap
sudo rebootWenn kein freier Speicherplatz verfügbar ist
# View current LVM usage
sudo vgs
# If VFree is 0, you can shrink an existing logical volume (dangerous, proceed with caution)
# Shrink the filesystem first, then shrink the logical volume
# Recommended to do this from a Live USB
# Check the filesystem
sudo e2fsck -f /dev/ubuntu-vg/ubuntu-lv
# Shrink the filesystem to 15G
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv 15G
# Shrink the logical volume to 16G (leave some headroom)
sudo lvreduce -L 16G /dev/ubuntu-vg/ubuntu-lv
# Now there is space to create a snapshot
sudo lvcreate -L 10G -s -n root-snap /dev/ubuntu-vg/ubuntu-lvBtrfs-Snapshot-Rollback
Bei Verwendung des Btrfs-Dateisystems erfolgen Snapshot-Vorgänge nahezu augenblicklich.
Erstellen eines Btrfs-Snapshots
# View Btrfs subvolumes
sudo btrfs subvolume list /
# Create a read-only snapshot
sudo btrfs subvolume snapshot -r / /snapshots/pre-upgrade-$(date +%Y%m%d)
# List snapshots
sudo btrfs subvolume list / | grep snapshotWiederherstellung von einem Btrfs-Snapshot
# Boot from Live USB
# Mount the Btrfs partition
sudo mount /dev/sda2 /mnt
# View subvolumes
sudo btrfs subvolume list /mnt
# Rename the current root subvolume
sudo mv /mnt/@ /mnt/@broken
# Create a new root subvolume from the snapshot
sudo btrfs subvolume snapshot /mnt/snapshots/pre-upgrade-20260324 /mnt/@
# Reboot
sudo rebootdd Disk Image-Wiederherstellung
Der einfachste, aber universellste Ansatz funktioniert mit jedem Dateisystem.
Erstellen eines Disk-Images
# Recommended to create from Live USB to ensure partitions are unmounted
# Full disk image
sudo dd if=/dev/sda of=/mnt/external/full-disk.img bs=4M status=progress
# Compressed image
sudo dd if=/dev/sda bs=4M status=progress | gzip > /mnt/external/full-disk.img.gz
# Back up a specific partition only
sudo dd if=/dev/sda2 of=/mnt/external/root-partition.img bs=4M status=progressWiederherstellung von einem DD-Image
# Boot from Live USB
# Restore the full disk
sudo dd if=/mnt/external/full-disk.img of=/dev/sda bs=4M status=progress
# Restore a compressed image
gunzip -c /mnt/external/full-disk.img.gz | sudo dd of=/dev/sda bs=4M status=progress
# Restore a single partition
sudo dd if=/mnt/external/root-partition.img of=/dev/sda2 bs=4M status=progress
# Update GRUB after restoration
sudo mount /dev/sda2 /mnt
sudo mount /dev/sda1 /mnt/boot/efi
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
grub-install /dev/sda
update-grub
exit
sudo rebootCloud-Server-Snapshot-Wiederherstellung
Operationen für verschiedene Cloud-Plattformen
# Alibaba Cloud - create a snapshot using CLI
aliyun ecs CreateSnapshot --DiskId d-xxx --SnapshotName pre-upgrade
# Tencent Cloud
tccli cbs CreateSnapshot --cli-input-json '{"DiskId":"disk-xxx","SnapshotName":"pre-upgrade"}'
# AWS
aws ec2 create-snapshot --volume-id vol-xxx --description "pre-upgrade"
# To restore: use "Roll Back Disk" or "Create Disk from Snapshot" in each platform's consoleTeilweises Rollback: Behebung von Upgrade-Problemen
Manchmal ist ein vollständiges Rollback nicht erforderlich; Es kann ausreichen, bestimmte Probleme zu beheben.
Defekte Pakete reparieren
# Configure unconfigured packages
sudo dpkg --configure -a
# Fix dependencies
sudo apt --fix-broken install
# Reinstall a problematic package
sudo apt install --reinstall package-name
# Force reinstall
sudo dpkg -i --force-overwrite /var/cache/apt/archives/package-name*.debBooten mit einem älteren Kernel
# Select "Advanced options for Ubuntu" from the GRUB menu
# Choose an older kernel version to boot
# If the GRUB menu doesn't appear (countdown too short)
# Hold Shift during boot (BIOS) or press Esc (UEFI)
# After entering the system, fix kernel issues
sudo apt install --reinstall linux-image-$(uname -r)
sudo update-grubWiederherstellungsmodus
# Select Recovery Mode from GRUB
# Available options:
# - dpkg fix broken packages
# - fsck check filesystem
# - network enable networking
# - root enter root shell
# In the root shell
mount -o remount,rw /
apt --fix-broken install
dpkg --configure -a
rebootZusammenfassung der vorbeugenden Maßnahmen
Die Vorbereitung vor dem Upgrade bestimmt direkt die Durchführbarkeit eines Rollbacks:
- Muss durchgeführt werden: Vollständige Datensicherung (Datenbanken, Konfigurationen, Benutzerdateien)
- Dringend empfohlen: System-Snapshot (Timeshift, LVM, Btrfs)
- Cloud-Server: Erstellen Sie einen Festplatten-Snapshot
- Virtuelle Maschinen: Erstellen Sie einen VM-Snapshot
- Kritische Systeme: Führen Sie zur Validierung zunächst ein Upgrade in einer Testumgebung durch
Rollback-Entscheidungsfluss
Issue found after upgrade
|-- Is the issue fixable?
| |-- Yes -> Fix the specific issue (package repair, config adjustment)
| +-- No -> Continue assessment
|
|-- Is there a system snapshot?
| |-- Yes -> Restore snapshot (Timeshift/LVM/Btrfs)
| +-- No -> Continue assessment
|
|-- Is there a disk image?
| |-- Yes -> dd restore
| +-- No -> Continue assessment
|
+-- Last resort
+-- Reinstall system + restore data and configs from backupDie wichtigste Erkenntnis: Machen Sie vor dem Upgrade immer ein Backup – verlassen Sie sich nicht nur auf das Rollback.