System backup (简体中文)

From ArchWiki


使用 Btrfs 快照

详情请看 Btrfs#SnapshotsSystem backup#Snapshots and /boot partitionSnapper

使用 LVM 快照

详情请看 LVM#SnapshotsCreate root filesystem snapshots with LVMSystem backup#Snapshots and /boot partition

使用 rsync

详情请看 rsync#As a backup utility

使用 tar

详情请看 Full system backup with tar

使用 SquashFS

详情请看 Full system backup with SquashFS



附注: 请完成翻译。(在 Talk:System backup (简体中文)# 中讨论)

Having a bootable backup can be useful in case the filesystem becomes corrupt or if an update breaks the system. The backup can also be used as a test bed for updates, with the testing repo enabled, etc. If you transferred the system to a different partition or drive and you want to boot it, the process is as simple as updating the backup's /etc/fstab and your bootloader's configuration file.

This section assumes that you backed up the system to another drive or partition, that your current bootloader is working fine, and that you want to boot from the backup as well.

更新 fstab

Without rebooting, edit the backup's fstab by commenting out or removing any existing entries. Add one entry for the partition containing the backup like the example here:

/dev/sdaX    /             ext4      defaults                 0   1



对于 Syslinux,你只需复制当前项目,不过使其指向不同的磁盘或分区。

提示: Instead of editing syslinux.cfg, you can also temporarily edit the menu during boot. When the menu shows up, press the Tab key and change the relevant entries. Partitions are counted from one, drives are counted from zero.

对于 GRUB,建议你自动重新生成主配置文件。如果你想将 GRUB 文件全新安装到 /boot 以外的位置(例如 /mnt/newroot/boot),使用 --boot-directory 标志。

Also verify the new menu entry in /boot/grub/grub.cfg. Make sure the UUID is matching the new partition, otherwise it could still boot the old system. Find the UUID of a partition with lsblk:

$ lsblk -no NAME,UUID /dev/sdXY

where /dev/sdXY is the desired partition (e.g. /dev/sdb3). To list the UUIDs of partitions GRUB thinks it can boot, use grep:

# grep UUID= /boot/grub/grub.cfg


重启计算机并在引导程序中选择正确的项目。This will load the system for the first time. All peripherals should be detected and the empty folders in / will be populated.

你现在可以编辑 /etc/fstab,将之前删除的分区和挂载点重新加入。

快照与 /boot 分区

如果你的文件系统支持快照(例如 LVMBtrfs),这些快照将很可能不包含 /boot 分区或 EFI 系统分区

You can copy the boot partition automatically on a kernel update to your root partition with a pacman hook (make sure the hook file is owned by root):

Operation = Upgrade
Operation = Install
Operation = Remove
Type = Path
Target = usr/lib/modules/*/vmlinuz

Depends = rsync
Description = Backing up /boot...
When = PostTransaction
Exec = /usr/bin/rsync -a --delete /boot /.bootbackup