I have a cluster of riscv machines (LicheePI 4A
) whom I want to back up in case something goes terribly wrong and I need to restore them up from scratch but keeping changes made. I am using a hard drive connected to one of the machines (let’s call this machine backup_machine
).
Since we are porting some libraries and applications to riscv, we are making changes kernel modules and so this one and everything it calls must be backed up as well.
Referring to Arch docs ( since I didn’t manage to find better ways of doing so) I am using rsync to back up all non-boot-generated directories. Clonzilla is not an option since I would have to back up the files from an x86 machine and for now I don’t want to do so.
Arch’s docs:
rsync -aAXHSv --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found/' / /path/to/backup
Mine (as a difference I am using incremental backup and ssh to back up files through the network):
rsync -aAXHvv -e ssh
--rsync-path="sudo rsync"
--link-dest='${latest_link_path}'
--exclude='/dev/*'
--exclude='/media/*'
--exclude='/run/*'
--exclude='/mnt/*'
--exclude='/proc/*'
--exclude='/sys/*'
--exclude='/tmp/*'
--exclude='/lost+found/'
sipeed@${node}:$dir_to_back_up
$backup_node_dir
Backups are working correctly at the scheduled time (using cronjob).
What I want:Now I want to be able to restore a machine in case it completely dies using these backups. That is, building a new bootable image that I can flash into the board.
SIMPLE SOLUTION: flashing the board with an ubuntu and then rsync the backup files and directories. but I’d prefer having the bootable image.
PD: I provide the links to the scripts I made below
To build this image I need u-boot.bin
, OpenSBI firmware (build using u-boot.bin
), the Kernel Image (I have to use the one in the backup since it has custom modifications), and an ext4 filesystem (using the backup files).
I am testing this setup on qemu
before getting my hands dirty on the board. This is what I do:
-
I create an ext4 filesystem using the script (linked to my github). Since the firmware, kernel and bootloader are provided to qemu, they don’t have to be on a boot partition in the disk image. When flashing the board, I’ll build a complete disk image with 2 partitions (boot, containing kernel, bootloader and firmware and rootfs).
-
I launch
qemu
using the following command:
qemu-system-riscv64 -M virt -m 2G -nographic
-bios ~/restore/fw_jump.bin
-kernel ~/restore/Image
-drive file=rootfs.ext4,format=raw,id=hd0
-device virtio-blk-device,drive=hd0
-append "root=/dev/vda rw console=ttyS0"
Here comes the issue. After this, the system boots up, it correctly jumpts to the address 0x080200000 and loads the kernel. The kernel starts running processes (some of them fail to start up) until I get the message:
root account is locked
and here I can only go through the whole boot process again, no input option is given.
What I think is going on: rsync doesn’t have the necessary privileges to copy essential files needed by the kernel and root (because -A copies access lists and H copies hard links, so that should be aight). I’ve been looking into various full backup options but most already use rsync, and dd
is out of the equation.
More information: I didn’t test it on the board yet, since on qemu is still not working. When using qemu, I build u-boot and OpenSBI firmware following qemu’s documentation. When building for the board I’ll build using the board’s documentation.
BACKUP SCRIPT: https://github.com/guillemsenabre/ScriptsSh/blob/main/Snapshots/incr_backup.sh
EXT4 CREATION SCRIPT: https://github.com/guillemsenabre/ScriptsSh/blob/main/filesystem/create_ext4.sh
Thanks in advance! Any help, criticism or advice is suuper welcomed!