Assuming your disk layout is as follows:
/boot
partition is on 1th partition (/dev/sdX1
)/
andswap
partitions are on LVM on LUKS partition which is on 2nd partition of the disk (/dev/sdX2
)
Given that, when you want to create a bootable backup disk, follow these steps:
-
Format a new disk and create appropriate disk layout (use a formatter script, target name is
zeytin
in this example) -
Sync
/
- Use
btrfs send | btrfs receive
orrsync
, according to your setup
- Use
-
Sync
/boot
mount /dev/sdX1 /mnt/target-boot rsync -avP /boot/ /mnt/target-boot/
-
Install GRUB to target disk:
sudo grub-install --boot-directory=/mnt/target-boot /dev/sdX
-
Change the configuration in
boot/grub/grub.cfg
:-
Change root partition UUID's and LVM names in "linux..." line accordingly
linux /vmlinuz-4.9.0-7-amd64 root=/dev/mapper/zeytin-root resume=/dev/mapper/zeytin-swap ro rootflags=subvol=rootfs cryptopts=source=UUID=HELLO,target=zeytin_crypt,lvm=zeytin-root
where
HELLO
is the output ofsudo blkid | grep sdX | grep crypto_LUKS
.-
change boot partition's UUID, where
HI_THERE
is the "UUID" value of output ofsudo blkid | grep sdX1
:--set=root HI_THERE
-
-
Change
etc/fstab
entries accordingly -
Change
etc/crypttab
entries accordingly -
Update
/etc/initramfs-tools/conf.d/resume
according togrep swap /etc/fstab
output -
Optional: If this will be a diverged clone, give-new-id.
-
Boot up with your new disk.
-
Continue from below Important section.
If everything above went well and you have booted up with your new disk, continue reading. If you haven't rebooted yet, do not continue, because some operations below rely on current kernel parameters.
Above procedure (till #10
) is sufficient for booting up from a newly formatted LUKS partition. However, when you directly or indirectly invoke update-grub
for some reason (system upgrades, changing initramfs static IP, etc.), you will be end up with unbootable system. It's highly recommended to take appropriate measures against /boot/grub/grub.cfg
overwrites:
-
Backup your current
grub.cfg
just in case:cp /boot/grub/grub.cfg /boot/grub/grub.cfg.failsafe
-
Be prepared to load above backup config file inside the grub shell manually. Remember the following to use backup config:
grub> configfile (hd0,msdos1)/boot/grub/grub.cfg.failsafe
-
Make above GRUB changes persistent:
-
Edit
/etc/default/grub
file to add the required arguments (cat /proc/cmdline | tr ' ' '\n'
):GRUB_CMDLINE_LINUX="\ resume=/dev/mapper/zeytin-swap \ rootflags=subvol=rootfs \ cryptopts=source=UUID=HELLO,target=zeytin_crypt,lvm=zeytin-root"
-
Update GRUB:
[[ -f /boot/grub/grub.cfg.failsafe ]] || echo "Check your failsafe!" && sudo update-grub
-
Optionally check the difference between newly created
grub.cfg
andgrub.cfg.failsafe
and verify your settings:git diff /boot/grub/grub.cfg.failsafe /boot/grub/grub.cfg
-
-
Reboot