Ubuntu LUKS LVM架构系统分区信息备份恢复方法及扩容前备份方案咨询
Hey friend, let's break down your situation and figure out the best backup approach before you expand your LUKS+LVM setup. First, let's recap your current disk layout to make sure we're on the same page:
nvme0n1 259:0 0 223.6G 0 disk ├─nvme0n1p1 259:1 0 487M 0 part /boot ├─nvme0n1p2 259:2 0 1K 0 part └─nvme0n1p5 259:3 0 118.8G 0 part └─sdb5_crypt 253:0 0 118.8G 0 crypt ├─ubuntu--nvme--vg-root 253:1 0 110.8G 0 lvm / └─ubuntu--nvme--vg-swap_1 253:2 0 8G 0 lvm └─cryptswap1 253:3 0 8G 0 crypt [SWAP]
You mentioned you've been using a live USB to take backups by unmounting the drive—smart move, since working on a mounted filesystem can lead to corruption. Let's cover solid backup strategies tailored to your encrypted LVM setup, plus key checks before you start the expansion:
Backup Options to Consider
Full Disk Image (Most Reliable)
Boot from your Ubuntu live USB, make sure the target drive (nvme0n1) is unmounted. Useddorpartcloneto create a full image of the entire disk. For example:# Using dd (slow but straightforward) sudo dd if=/dev/nvme0n1 of=/path/to/external/drive/ubuntu_backup.img bs=4M status=progressOr
partclonewhich is faster for used blocks:sudo partclone.dev -c -s /dev/nvme0n1 -o /path/to/external/drive/ubuntu_backup.imgPro tip: Compress the image to save space—pipe it through
gzip:sudo dd if=/dev/nvme0n1 bs=4M status=progress | gzip > /path/to/external/drive/ubuntu_backup.img.gzLUKS Container Backup
Since your root filesystem is inside a LUKS container, you can back up just the encrypted partition instead of the whole disk. Unlock the container first (from live USB):sudo cryptsetup luksOpen /dev/nvme0n1p5 sdb5_cryptThen back up the LUKS header separately—this is critical! If the header gets corrupted, you'll lose access to your data:
sudo cryptsetup luksHeaderBackup /dev/nvme0n1p5 --header-backup-file /path/to/external/drive/luks_header_backup.imgAfter that, you can back up the unlocked LVM volume group with
ddor create a snapshot withlvcreateif you prefer incremental backups later.File-Level Backup
If you don't want to deal with disk images, usersyncto copy all your files to an external drive. From the live USB, mount your root filesystem first:sudo cryptsetup luksOpen /dev/nvme0n1p5 sdb5_crypt sudo vgchange -ay ubuntu--nvme--vg sudo mount /dev/mapper/ubuntu--nvme--vg-root /mnt sudo rsync -aAXv /mnt/ /path/to/external/drive/backup/ --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"}This preserves permissions, symlinks, and extended attributes—great for restoring individual files if needed.
Pre-Expansion Checks
Before you start resizing, make sure:
- Your external backup is verified—try mounting the image or checking the rsync backup to confirm all files are present.
- You have the LUKS passphrase handy (obviously, but easy to overlook!).
- The live USB you're using is the same Ubuntu version (20.04) as your installed system to avoid compatibility issues with LVM/LUKS tools.
- Run
sudo fdisk -lfrom the live USB to confirm the unallocated space is available on/dev/nvme0n1after the existing partitions.
Once your backup is solid, you can proceed with expanding the partition, LUKS container, and LVM volume. But always prioritize that backup first—resizing encrypted volumes can go wrong if interrupted!
备注:内容来源于stack exchange,提问作者localhost

