ロールバック戦略
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: システムが起動できない
- Ubuntu Live USB から起動する
- ライブ環境で 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 lvsLVM スナップショットからのロールバック
# 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-lvBtrfs スナップショットのロールバック
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 snapshotBtrfs スナップショットからの復元
# 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 ディスクイメージの回復
最も単純だが最も普遍的なアプローチは、どのファイルシステムでも機能します。
ディスクイメージの作成
# 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=progressdd イメージからの復元
# 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予防措置の概要
アップグレード前の準備によって、ロールバックの実現可能性が直接決まります。
- 必ず行うこと: データ全体のバックアップ (データベース、構成、ユーザー ファイル)
- 強く推奨: システム スナップショット (タイムシフト、LVM、Btrfs)
- クラウド サーバー: ディスク スナップショットを作成する
- 仮想マシン: VM スナップショットを作成する
- 重要なシステム: 検証のために最初にテスト環境でアップグレードします。
ロールバック決定フロー
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最も重要なポイント: アップグレードする前に必ずバックアップしてください。ロールバックのみに依存しないでください。