Figuring out x86 upgrade automation

I have a x86 router that I upgrade with the two partitions strategy: Sysupgrade help for x86_64 - #14 by frollic

In a third partition I made some scripts to automate the building of a custom image with the same installed packages. Download the rootfs archive and kernel and copy them to the other root and boot partitions. This works well.

So now I'm trying to figure out how to backup current configs and restore them on the reboot of the upgraded partition,

I've tried to copy them manually after changing the other rootfs. But they seems to get overwritten by the first boot procedure.

After that, I tried to use the sysupgrade restore mecanism (https://openwrt.org/docs/techref/sysupgrade#how_it_works) by generating the sysupgrade.tgz archive and copying it in the new rootfs manually before rebooting. But it seems the
/lib/preinit/80_mount_root do not get executed on my firstboot on the upgraded rootfs. There is a INITRAMFS env variable that is checked in the file, but I can't figured out where it is set.

Do someone knows the first boot procedure well enough to tell if this approach could work for automating the config files restore? Or has suggestions how to achieve a fully automated upgrade?

If you're already building custom images, you can use the UCI defaults mechanism to apply your custom configuration upon first boot. Quoting the wiki page for this function:

You can preload custom settings by adding batch scripts containing UCI commands into the /files/etc/uci-defaults directory.
...
The scripts will be run after the flashing process - in case of upgrading, that also includes appending the existing configuration to the JFFS2 partition (mounted as /overlay).

Of course, they don't have to be UCI calls specifically, you can write any arbitrary script.

1 Like