I have my own scripts, but they are highly customised to the way I do things.
Basically I have another block device (actually nvme) with a ext4 partition matching root. The other block device also has a EFI partition.
I tend to use labels, so they’re labelled altroot
and ALTROOTEFI
(uppercase because of msdos, plus it should be noted the EFI label cannot be EFI
or it will be confused with the EFI directory - another msdos thing). My backup script mounts them as follows:
mount -o noatime,acl,user_xattr /dev/disk/by-label/altroot /mnt/altroot
mount -o umask=0002,utf8=true /dev/disk/by-label/ALTROOTEFI /mnt/altroot/boot/efi
The rsync commands I use are:
rsync -ax -HAX --delete --devices --sparse / /mnt/altroot/
rsync -ax -HAX --delete --devices --sparse /boot/efi/ /mnt/altroot/boot/efi/
That’s all that’s needed for a backup. I can restore by using rsync in the other direction (most likely from a rescue disk or a booted altroot). Plus I can use the altroot for doing diff’s to investigate/check what’s changed after a dup.
Making the altroot bootable requires changing the altroot fstab and grub.cfg so that the existing real root osprober will include the altroot as an separate boot option. It’s actually fairly simple, but scripting it requires extracting uuids, and that what gets a bit convoluted. If you do make changes to the altroot to make it bootable, you cannot just restore by copying back everything - the fstab and grub.cfg will no longer be correct (but you could easily keep backup copies). The basic steps are:
- Update /mnt/altroot/etc/fstab so the root volume is now altroot.
- Update /mnt/altroot/etc/fstab so the the /boot/efi UUID is the UUID of /mnt/altroot/boot/efi.
- Update /mnt/altroot/boot/grun2/grub.cfg by replacing root UUID with the altroot UUID.
- Run
grub2-mkconfig -o /boot/grub2/grub.cfg
to have osprober find the alt system and include it as a boot item.
Making altroot bootable is not something I have normally done in the past, but I’m experimenting with it as a emergency fallback in case I ever somehow zap the root partition. I got driven to doing this bootable experiment by KDE6 - if things turned out badly, I wanted to be able to go back to KDE5 quickly (but all in all KDE6 is quite livable).
BTW - if you do need to extract a UUID, blkid and awk is probably the easiest way to script it:
blkid /dev/disk/by-label/root -o export | awk -F= '$1 == "UUID" {print $2}'
save_uuid="$(blkid /dev/disk/by-label/root -o export | awk -F= '$1 == "UUID" {print $2}')"