I want to clone an existing Debian installation and restore on a new machine with a hard drive of different size.

The partioning is very easy - /dev/sda1 for EFI, /dev/sda2 for Linux and /dev/sda3 for swap.

On the machine where I'm creating the image, I mostly do:

fsarchiver savefs /images/${BACKUP_FILE_NAME}.fsa /dev/sda1 /dev/sda2 -e *.fsa -v -j4 -A -z 9

I also save the output of:

sfdisk -J /dev/sda

as well as


On the machine where I want to restore this, I basically do this:

echo "label: gpt" | sfdisk /dev/sda

FULL_DISK_SIZE=`sfdisk -s /dev/sda`

cat <<EOT > /tmp/sfdisk.txt
size=512M, type=${SFDISK_TYPE_BOOT}, uuid=${SFDISK_UUID_BOOT}

sfdisk /dev/sda < /tmp/sfdisk.txt

The main idea behind this being to preserve the original partition types as well as part uuids, but being flexible in terms of the size of the linux partition. I roughly say here full size minus 10 GB.

I then restore everything like this:

fsarchiver restfs sourceimage.fsa id=0,dest=/dev/sda1 id=1,dest=/dev/sda2

This works on machines with exactly the same hard drive. If the hard drive is different, I cannot boot from it.

If I install Linux regularly on these machines, save the partition info, wipe them, and try the procedure from above again, it still fails with the old partition info (not surprising), but it immediately starts to work if I use the new disk's part uuid for the EFI drive. This makes me believe that these part uuids are involved.

I then went back to just the old machine and restored the image on it, but I changed the part uuid of its EFI partition by one letter, just to see if that would mess with it - and it does. Also, letting sfdisk auto-generate the part uuids does not make the drive bootable after restoring the image.

I could not care less about whether the part uuids are preserved or new ones, but I do want to automate this. Any idea what I need to change to make this work?


I think I have figured it out. This part was missing at the end:

mount -o rw,remount /sys/firmware/efi/efivars
efibootmgr -c -g --disk /dev/sda --part 1 -l \\EFI\\debian\\grubx64.efi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.