0

Here's one for the guru out there.. I use a Raspberry Pi 3B+. It has an SD card with two partitions. So the layout is:

mmcblk0     179:0    0  59.5G  0 disk
├─mmcblk0p1 179:1    0   256M  0 part /boot
└─mmcblk0p2 179:2    0  59.2G  0 part /

I have a USB HDD used as a backup disk. Would like to create an image file from my backup. My USB HDD contains a backup tree , viz:-

/dev/sda1 (ext4 partition)
|
+----------------+
|                |
root (dir name)  boot (dir name)
   |                |
   |                |____ seed.sfs (squashfs filesystem copy of '/boot')
   |                      
   |____seed.sfs (squashfs filesystem copy of root '/' )
   |
   |____rsync1 (rsync backup diff on top of seed.sfs)
   |
   |____rsync2 (rsync backup diff on top of seed.sfs)
   |
   |____ . . .
   |
   |____rsyncX (rsync backup diff on top of previous rsyncs + seed.sfs)

Using the overlay filesystem, I mount root/seed.sfs + rsync1 as the overlay lowerdirs and rsync2 as the overlay upper dir, and I mount the result over /mnt/backups/root. This gives me a read-writeable overlay filesystem that is a copy of the root (mmcblk0p2 partition) of the Pi's SD Card.

(NB: Each time I backup, a new rsync dir (rsyncX where X is just a running count number) is created and added to the lowerdirs/upperdirs as necessary)

So /mnt/backups/root is the full backup of the mmcblk0p2 partition.

The /boot dir on the USB HDD is also a squashfs filesystem file which I mount over /mnt/backups/boot.

So /mnt/backups/boot is the full backup of the mmcblk0p1 partition.

All this works perfectly, so no issues with the method and use.

But... How - if possible - can I create an image file using /mnt/backups/{root and boot} that I can flash to a new SD card and use this SD card to boot the Pi. So

  • /mnt/backups/root is the contents of mmcblk0p2 on an SD card.
  • /mnt/backups/boot is the contents of mmcblk0p1 on an SD card.

and of course mmcblk0 on the new card would need to have the bootable files on there , extracted from a live booted SD card I guess?

Ideas?

2
  • Welcome. I really just skimmed this, so I am not sure if you are asking, "How can I create a custom flashable image that can be used on an SD card?", or if you already understand that but feel there is a particular contextual problem here (WRT "Use Overlay, ext4 and squashfs filesystems"). I think it is probably the former and the latter (what the source of the data for the image is) is actually not very relevant, ie., if you could understand how to create an image, you would understand how to use what you have to do it...
    – goldilocks
    Nov 23, 2020 at 20:21
  • This is an XY problem
    – Milliways
    Nov 24, 2020 at 0:04

1 Answer 1

1

Question:

But... How - if possible - can I create an image file using /mnt/backups/{root and boot} that I can flash to a new SD card and use this SD card to boot the Pi

There may be good reasons for the stuff you've done; but TL;DR

My suggestion is this: use image-utils. You can read about it & d/l in this long-ish thread, or use git to clone the repo on your system:

$ git clone https://github.com/seamusdemora/RonR-RPi-image-utils
2
  • That'll do it @seamus , saved carving another wheel 😀 thanks
    – keratos
    Nov 24, 2020 at 21:41
  • ooos. nope. that's no good. i don't want to create rync images of filesystems. Other way round. But having looked at the code, the scanner is obvious and i was overcomplicating. All i need to do is mount an SD card on a reader, queue a bootstrap, create two partitions, mount the first one over /mnt/boot and rsync my boot backup to it, and do the same with my root backup to /mnt/root which is the 2nd partition. done
    – keratos
    Nov 24, 2020 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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