1

I backed up my SD card incorrectly. Instead of making a full copy of the SD card I backed up the boot and rootfs partitions separately. How do I recreate the SD card image with the separate files?

Backup Procedure

dd if=/dev/xxx of=rpi_boot.img
dd if=/dev/yyy of=rpi_rootfs.img
2
  • Do you still have the SD Card used for backup? Does it still boot?
    – Milliways
    Oct 1 at 6:06
  • Good point - if you still have the original SD card and the first 1MB of it is intact, you can restore your backup on its partitions, or copy the partition table from it to another SD card. Oct 1 at 7:25
2

While this would be possible it is not straightforward. Using dd to backup is a poor strategy.

I suggest you perform a fresh installation on a new SD Card then copy the files across (using rsync) from mounted images.

Even then, even if using the other approach suggested there are additional steps (adjusting PARTUUID) which can be avoided by not copying /etc/fstab and cmdline.txt.

6
  • Aren't PARTUUIDs the same on all systems flashed from a given image? Unless the OP changed them, the partition table restored from the installation image should have the correct ones IMO. And while I agree that dd is not the optimal backup tool, any other tool will fail just as well if you backup the wrong device. Oct 1 at 7:46
  • @DmitryGrigoryev If you flashed the original image they would be the same, BUT the OP does NOT have a partition table. If the original image was used, it should be OK, BUT each downloaded image has a different PARTUUID.
    – Milliways
    Oct 1 at 7:48
  • @DmitryGrigoryev I routinely give each SD Card a new PARTUUID so I can unambiguously mount, and it is not difficult to set a new PARTUUID.
    – Milliways
    Oct 1 at 7:50
  • I suppose you mean "each different release", I'm pretty sure if you download the same Pi OS release twice the images will be identical. Oct 1 at 7:51
  • 1
    @DmitryGrigoryev depends what you mean by "release". Each time the Foundation posts a new image it changes. Buster is unusual, it only has had 6 releases.
    – Milliways
    Oct 1 at 8:03
1

Find out the exact size of your partition images. Flash a fresh image of the OS you were using, open the SD card in the partition manager (e.g gparted or fdisk), and resize partitions to match your backups. Then roll your backups back to the SD card with dd on the partitions you have prepared (swap if and of in the commands you used for backup).

If you didn't keep the installation image, you can try to download it again. Assuming this is about Pi OS, the partition table is not identical between individual image releases, As Milliways points out. You can estimate the date of release you have installed using

tune2fs -l rpi_rootfs.img  | grep 'Filesystem created:'
3
  • "Flash a fresh image of the OS you were using, open the SD card in the partition manager (e.g gparted or fdisk), and resize partitions to match your backups." -> The former step seems a bit pointless in light of the second; if you are able to edit the partition table, you might as well just start with a fresh (empty) one, create the two partitions with the correct size and type (they don't actually need to be formatted), and dd the filesystems in...
    – goldilocks
    Oct 1 at 14:30
  • ...One thing to look out for with that, though, is that the starting offset of the first partition is bigger than the default used with eg., fdisk. In the images it's 8192 blocks. May not actually matter (it is a general practice with SD cards, I think, perhaps for apocryphal reasons) but I think I read somewhere the GPU needs or expects that at boot (a premise I've never tried to confirm).
    – goldilocks
    Oct 1 at 14:30
  • @goldilocks Sure, if the OP can create empty partitions with all the right settings, they don't need to get the partition table from anywhere, and there's no need for a backup of it. These settings include partition types, flags, UUIDs, start sectors, etc. Oct 2 at 9:08

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.