Recently I bought a Helios64 NAS and now I am playing around with it. My intention is to set it up as I need it, but I also want to understand how the system works. The last weeks I did a huge effort to read everything about what armbian exactly is, how it works, and also how the boot process works. I would say I have a good overview of the topics right now, but now I am at a point where I need your help.
My intention right now is the following: I want to make an automatic backup system, which runs regularly and saves the backups incrementally on an external HDD. The idea is: When I am messing up my system (which I certainly will when playing around), I can copy one of the working backups onto another SD card and boot from that instead. And have a working system again.
I had already a look at the nand-sata-install script, and based on that I already have the commands ready to copy the root filesystem. (I am using parted mklabel and parted mkpart for preparing the partition table, then using mkfs.ext4 to create the filesystem, and then the rsync command from the nand-sata-install script (+x option to stop at file system boundaries) to copy the root file system). This is the first step for now. Later, I want to include another step: I will backup my root file system with borg backup into a borg repository. This can store incremental backups very well. And then, when I need a backup, I rsync from one of the borg backups onto my SD card.
But even after a exhausting research how the boot process works in general (loading the MBR -> jumping to the boot sector or boot partition -> loading the boot file -> loading the kernel), and trying to understand how the nand-sata-install script handles the U-Boot install, I don't understand how to make my SD card bootable. With
hexdump -C -n 512 /dev/mmcblk0
I can see the MBR with the signature "55 aa" as the last two bytes, which tells the BIOS that this card is bootable. Then I see with
parted /dev/mmcblk0 unit s print
that the first and only partition (primary ext4) starts at sector 32768, where one sector equals 512 bytes. With hexdump, I see that the sectors before the first partition contain actually some data. But I am not sure, if this is garbage, or if this is the boot code from Das U-Boot. Reading this tutorial (https://linux-sunxi.org/Bootable_SD_card) it actually seams that the first sectors of the SD card is the U-Boot binary code written to the SD card with dd. However, I didn't find any *.bin file on armbian in /boot/ directory. Based on this tutorial (https://neosmart.net/wiki/mbr-boot-process/ ) I actually understood how the boot process is working, and that also the first sector(s) of a partition can contain boot code. However, with hexdump on /dev/mmcblk0p1, I saw that the first 1024 bytes of the partition are zero.
So my question now is: How can I make my cloned SD card bootable, by either backing up the boot code from the original card and copying it onto the new card, or by re-creating the boot code freshly on the cloned SD card (from my personal PC). I also like to understand, what I am actually doing and why, not just copying commands blindly.
Thanks a lot for your help!