Constraints
Becouse I want a solution that is more of a general backup, these are the requirements for the ideal soution:- it should preceive GPT, ESP, and the OS root partition filesystems;
- it should support atleast EXT4(for linux root partition), FAT(for ESP), NTFS(for windows home partition);
Raw copy
The naive aproch, I call it so because despite of beeing one of the easyest solution it has some disadvantages like:- it is nerry slow
- the size of the backup is equal to the size of initial disk
- it is not verry flexible(the backup can't be restored only partialy)
Backup of each partition
This is a slightly more advanced approach because comes with the following advantages:- takes way less space
- it runs faster
- allows us to exclude specific files or directoryes from the bckup
- allows us to restore the backup on a smaller1 drive
#archive command for ext4 partition
sudo fsarchiver savefs /mnt/kesu/backup_ubuntu/ubuntu_ext4rootfs.fsa /dev/nvme0n1p2 -v -j4
#exclude some dirs/files
# --exclude
#restore command for ext4 partition
sudo fsarchiver restfs /mnt/kesu/backup_ubuntu/ubuntu_ext4rootfs.fsa id=0,dest=/dev/nvme0n1p2 -v -j4
#backup/restore esp partition
sudo dd if=/dev/nvme0n1p1 of=/mnt/kesu/backup_ubuntu/esp_boot status=progress
sudo dd of=/dev/nvme0n1p1 if=/mnt/kesu/backup_ubuntu/esp_boot status=progress
#backup GPT partition table
sudo sgdisk --backup=/mnt/kesu/backup_ubuntu/gpt_part_table.backup /dev/nvme0n1
#restore GPT partition table
sgdisk --load-backup=/mnt/kesu/backup_ubuntu/gpt_part_table.backup /dev/nvme0n1
More details about how to install and run fsarchiver can be found on their website. Nonetheless don't forgoet to edit the NVRAM Variables to point to your secondary bootloader located on the ESP partition, to do that you can use tools like efibootmgr or UEFI shell.
Footnotes
- as long as the used space of the backedud drive si <= the size of the drive used for restore↩