Sysupgrade >>auto reinstall<< packages


I've written a script to automatically reinstall packages when doing a sysupgrade. This needs to run once before sysupgrade and bob's your uncle. The script itself will figure out what it needs to reinstall =)

I could spend hours figuring out where to put that call in sysupgrade but i thought it was easier to just ask someone who knows.

  1. Where in sysupgrade can i put this call ?
  2. How do i propose a patch ? (this is my first)

What it would look like: (start 6.00)


Saw no video, only heard music (might be my script blocker).

A request is probably easiest:

Your software seems promising, I may use it in the future. Currently, I simply do the following (just upgraded a router today from 18.01.0 to 18.01.1). The below device had wireguard, tcpdump and snmpd installed:


10 16 * * * opkg update                                                                                                                                                
12 16 * * * opkg install kmod-udptunnel4 kmod-udptunnel6 kmod-wireguard wireguard-tools wireguard luci-proto-wireguard luci-app-wireguard tcpdump snmpd                
14 16 * * * sleep 70 && touch /etc/banner && reboot

Also, if you're still developing - as another option, perhaps you could just have your software simply make the needed cron entries?

Not trying to disparage you from your effort that seems to work, at least for you. But how about showing us something ... anything? Your code, a description of your process? You are asking us to comment on something you don't show.

Edit: We had a brief conversation about your undertaking on IRC the other day. As I said there, I can think of a number of circumstances where an automatic installation of packages could lead to problems, ranging from race conditions to a setup that will not boot anymore. I am genuinely curious how you tackle these problems, but again, "did you see it? Of course you didn't, there was nothing to see" is preciously little to base an opinion on, let alone an educated analysis.

Every afternoon, you are installing all the necessary packages, then rebooting? Why?

Edit: To clarify, I believe that cron is the worst possible place to trigger an automatism after sysupgrade.


:laughing: Gracious, no!

As I said:

I simply add this to cron before flashing an upgrade on a remote router (18.06.1). I remove it after success. I access this router via Wireguard. The only other workaround would be to build a custom firmware with Wireguard included.

Yea...I have no other choice in this instance, except driving a great distance when security updates are needed on the device (save flashing a custom firmware). I agree the safest option in my case would probably be flashing a custom firmware.

1 Like

FYI: "[OpenWrt-Devel] [PATCH v3 0/4] base-files: add new backup options"



Through you i found:
Pull Request submitted:

Thanks, it was really helpful and educational =)

1 Like

I dont know how i missed you post, but i did :confused:

Thanks, it helped a lot. I thought i could put a couple of hours in a simple patch, but that turned out to be more complicated :grin:

I opened a new PR:

sysupgrade backup will now contain a list of packages
sysupgrade will restore these package from this list
sysupgrade will restore these packages after firmware upgrade

How do your proposed changes handle when packages are obsoleted, have name changes, or dependency changes across releases?

Edit: Additional comments on the PR including handling of permanent and transient failures, as well as package repo not being available during first boot.

That is handled by opkg, it saves "only" user installed packages.
So if you install fdisk, only fdisk will be saved to the packagelist not any of its dependencies.

I replace rc.local before so it can execute later after reboot when the system is up after S95done. Only on proper executing it will then put back the old one and remove itself.

Name changes, you have a point there. I wonder how frequently that occurs though ?

Obsolete, got to take a look at that. I dont know.

Points taken

I would ignore the name change aspect for now. When we change a fundamental part in base, or split it into variants, we usually try to let it provide its former name as virtual provider, this way opkg will still find it when requesting the old name for install.

At least from what I've seen, opkg doesn't discriminate between "installed by direct user request" and "installed as a dependency". Ideally, the reinstall would be driven only by the "direct user request" packages, with their now-current dependencies installed, as appropriate.

1 Like

Would it be safer if this feature had an option to only save the list and then user could run opkg after upgrade with the list.
This would be helpful in cases that not enough space is available for all the packages.

1 Like

Sorry about that, it already filters "direct user request" packages only.

The system stays the same until rc.local is executed through S95done.
By then the system is already up. It would be the same as doing a firmware upgrade, and then login and run opkg update and opkg install .

If there is not enough space, opkg will not install all the packages. Thats a problem, although not a different result, unless i'm missing something ?

1 Like

Added commandline options:

Idea's/comments/insights are welcome. (1310 comment updated)

	-a           attempt to reinstall "direct user request" packages

	-a           attempt to reinstall "direct user request" packages
	             on restore. (requires internet access)
	-k           list "direct user request" packages. Does not create
	             a backup file.

Well, I don't know what to say other than, its done. I need people to start testing. Preferably on hardware (make sure you have the skills to recover), but if you can at least test your configuration in a VM I'm happy too.

If you want to watch:

If you want to test, follow the instructions in PR1310

I created three testing branches:


VM testing procedure: (no compiling needed, unless you want to)

  1. Create a VM with OpenWRT

  2. Download sysupgrade for your version ^^ and overwrite /sbin/sysupgrade

  3. Start monkeying around =)
    a) install your packages, check them (-k)
    b) set upgrade url (-U)
  1. c) check for update (-w)
    d) autoupgrade (-Zzz)

Report any issues here.

Have fun.

1 Like

Wow these look amazing, did these ever get merged? I kind of got shocked today when I had to revert to a backup and saw that the backups hadn't even been saving a list of the installed packages, which I just assumed they were, for some reason.

@stumper: Thanks for the share! I wonder what is the status of your work. This is rather interesting (I've searched for a good solution for my own routers for ages) but I saw that the pull request has been closed and the git branch deleted. I would be willing to test your changes actually.

See current master, including the following commit and those immediately prior

commit 5cb1dce542a6a13fd250e9ef9c8290568c610c39
Author: Luiz Angelo Daros de Luca <redacted>
Date:   Fri Aug 17 20:49:53 2018 -0300

    base-files: add sysupgrade -k to save list of pkgs
    When '-k' is used, sysupgrade inserts into backup a new file
    /etc/backup/installed_packages.txt which contains pkgname and origin (rom,
    overlay, unknown) without touching rootfs.
    It's mainly used to reinstall all extra packages:
     # opkg update
     # grep "\toverlay" /etc/backup/installed_packages.txt | cut -f1 | xargs -r opkg install
     # rm /etc/backup/installed_packages.txt
    Signed-off-by: Luiz Angelo Daros de Luca <redacted>
1 Like

I would say that this method is now pretty much obsolete. You can now use to generate image with all your currently included packages. This is not just more convenient, but all packages that have been included in initial image are in jffs2 partition and are compressed which means after making upgrade you will actually have more free space than before. All this is done automagically by just running simple command from cli or using luci.

You can use:
opkg install luci-app-attendedsysupgrade
to manage it using luci or

if you want to change branch or have more control over it:
opkg install auc