Skip to Content

ロールバック戦略

Ubuntu の do-release-upgrade はネイティブ ダウングレードをサポートしていません。アップグレード後に重大な問題が発生した場合は、事前に準備したロールバック計画に頼る必要があります。この記事では、いくつかの実用的なロールバック戦略について説明します。

ロールバック オプションの比較

オプション回復速度準備の複雑さユースケース
タイムシフト速い(数分)低いデスクトップおよび小規模サーバー
LVMスナップショット速い(数分)中LVMを使用したシステム
Btrfs スナップショット非常に速い中Btrfs ファイルシステム
dd ディスクイメージ遅い (ディスクのサイズによって異なります)低いユニバーサルオプション
バックアップ復元+再インストール遅い高最後の手段
クラウドプラットフォームのスナップショット速い低いクラウドサーバー

タイムシフトスナップショットの復元

Timeshift は、RSYNC モードと Btrfs モードの両方をサポートする、最もユーザーフレンドリーなシステム スナップショット ツールです。

アップグレード前のスナップショットの作成

# Install Timeshift sudo apt install timeshift -y # Create a snapshot sudo timeshift --create --comments "Pre-upgrade backup" --tags D # List snapshots sudo timeshift --list

スナップショットからの復元

方法 1: システムはまだ起動可能です

# 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 reboot

方法 2: システムが起動できない

  1. Ubuntu Live USB から起動する
  2. ライブ環境で Timeshift をインストールして実行します。
# 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 reboot

タイムシフトノート

  • Timeshift は、デフォルトでは (RSYNC モードの場合) /home をバックアップしません。ユーザーデータは別途バックアップする必要がある
  • スナップショットには十分なディスク容量が必要です
  • RSYNC モードのスナップショットのサイズは時間の経過とともに増加します (増分)
  • Btrfs モードはより効率的ですが、Btrfs ファイルシステムが必要です

LVM スナップショットのロールバック

システムが LVM (Ubuntu Server のインストール時のデフォルト オプション) を使用している場合は、LVM スナップショットを使用して迅速なロールバックを行うことができます。

アップグレード前の LVM スナップショットの作成

# 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 lvs

LVM スナップショットからのロールバック

# 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 reboot

空き容量がない場合

# 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-lv

Btrfs スナップショットのロールバック

Btrfs ファイルシステムを使用している場合、スナップショット操作はほぼ瞬時に行われます。

Btrfs スナップショットの作成

# 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 snapshot

Btrfs スナップショットからの復元

# 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 reboot

dd ディスクイメージの回復

最も単純だが最も普遍的なアプローチは、どのファイルシステムでも機能します。

ディスクイメージの作成

# 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=progress

dd イメージからの復元

# 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 reboot

クラウドサーバーのスナップショットリカバリ

各種クラウドプラットフォームの運用

# 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 console

部分的なロールバック: アップグレードの問題の修正

完全なロールバックが必要ない場合もあります。特定の問題を修正するだけで十分な場合があります。

壊れたパッケージの修正

# 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*.deb

古いカーネルでの起動

# 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-grub

リカバリーモード

# 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 reboot

予防措置の概要

アップグレード前の準備によって、ロールバックの実現可能性が直接決まります。

  1. 必ず行うこと: データ全体のバックアップ (データベース、構成、ユーザー ファイル)
  2. 強く推奨: システム スナップショット (タイムシフト、LVM、Btrfs)
  3. クラウド サーバー: ディスク スナップショットを作成する
  4. 仮想マシン: VM スナップショットを作成する
  5. 重要なシステム: 検証のために最初にテスト環境でアップグレードします。

ロールバック決定フロー

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 backup

最も重要なポイント: アップグレードする前に必ずバックアップしてください。ロールバックのみに依存しないでください。