Skip to main content

OpenWrt Firmware Update (without losing installed packages)

Contents

Whether you have reinstalled OpenWrt or updated it, even though you have backed up your settings, any additionally installed packages have not (will not) been preserved, so restoring the settings will not make everything as it was. For now, this is normal behavior with OpenWrt. Therefore, you need to think about how to approach this so that the update and restore of settings will proceed as expected, i.e. together with the packages.

Therefore, before updating the router, you need to generate a list of installed packages that we will need to restore (install) before restoring our settings from a backup.

Installing a clean OpenWrt firmware is not a problem. The trouble begins when we want to update the currently installed one to the latest available version. In this case, we have the option of installing the latest software along with preserving the settings (but not the packages) or restoring the default settings.

I personally encourage you to install (update) without saving the settings and start from scratch. This is because if we have installed a package, even the one described here: DNS over HTTPS, after restarting, our internet will not work, because the current settings in the router will try to redirect traffic through a package that is not in the system and everything will start to fall apart.

So how do we do everything correctly? Well, we’ll do it in the following steps.

Since I recently managed to replace my ASUS RT-AC57U router with the very powerful Linksys WRT3200ACM, I wanted to transfer everything I already have set up on the ASUS to the Linksys. Unfortunately, the differences in hardware and configuration files mean that everything is not so easy. There is no way to make a copy on one and restore (after uploading packages) on the other. The solution is to make a copy on two routers and compare the files from the old one and add what is missing to the new one. A laborious solution, but it also works.

Within the same device, everything will proceed according to the below diagram.

A small note. If you are using only the pure OpenWrt firmware and do not add any additional packages, you do not need to go any further into my post. Then you install the new firmware while preserving the current settings or simply restore the settings from a saved backup and everything works. The next steps are primarily for people who use OpenWrt in its extended capabilities.

Let’s begin.


Even though 22.03 is based on Firewall4, we can successfully upgrade from 21.02.x to 22.03.x using the following method. The Firewall package will be skipped (along with other incompatible packages) and replaced by the existing Firewall4. You don’t have to worry about getting any errors while restoring packages.

Due to the change of the cryptographic package in version 23.05 from wolfssl to mbedtls, when upgrading from version 22.03 to 23.05 with restoring packages from the previous version, I recommend making a few changes to avoid unnecessarily installing this package in our system.

In the case of a software version jump, such as from 23.05 to 24.10, in theory everything should go smoothly, however, as with any major change, there is a possibility that our router will not turn on. As I had with my Askey RT4230W REV6 (RAC2V1K) router. Although from version 21.02 to 22.03 and 23.05, there were no problems, the project maintainers introduced a lot of changes in 24.10, which may be incompatible with the current settings.

In my case, I had to reset the router to factory settings and start from scratch. Fortunately, the generated backup file allowed me to save my settings, which, step by step, I was able to restore.

After a deeper analysis, I noticed that my interfaces (network ports) had changed their name, for example option device 'eth0.2' changed to option device 'wan'. In the future, this makes sense when transferring package configurations between different devices. There were more changes, so I decided to restore everything manually and at the same time check the validity of my posts regarding OpenWrt.

As for the update within 24.10.0, everything should be as described below.

In the my_installed_packages file, which we will generate before starting the update and which we will create a backup copy of on our computer, I recommend opening it in Notepad (or another such program) and searching for all entries with wolfssl and deleting them. If any package needs it, it will install it automatically anyway.

We install the packages as described below, and then restore the configuration.

Since each major update brings a lot of changes, I recommend taking some time and manually installing the packages we use, freshly loading OpenWrt and then using a backup restore. Then, updating from version 23.05.0 to the next in the series, which will be released in the future, should be problem-free as described.


Backup of current settings

First, go to the administration panel via a web browser.

There we select System > Backup / Flash firmware

OpenWrt - System Backup - Flash Firmware OpenWrt > System > Backup / Flash Firmware

To make a backup copy of your settings, simply click the Generate archive button in the Backup section.

OpenWrt - System Backup - Flash Firmware - Generate Archive OpenWrt > System > Backup / Flash Firmware > Generate Archive

Before we do that, I personally recommend changing the settings to extend the backup scope to additional folders. If you have used my guide, including how to add a VPN server to your router, in the Configuration tab we add additional folders.

/etc/ssl/
/etc/wireguard/
/etc/config/
/root/

OpenWrt - System Backup - Flash Firmware - Configuration OpenWrt > System > Backup / Flash Firmware > Configuration

Although by default the backup copies modified files to the /etc/config folder, I personally prefer to have a complete copy of this folder.

What we have defined at this stage is stored by default in the /etc/sysupgrade.conf file during a standard software update.

Next, we click the Save button and go back to the Actions tab and generate our backup archive (Generate archive).


Generating a list of installed packages

With the settings backed up, it’s time to generate a list of packages that we have installed on the system. Notice that in the previous step I added the /root/ folder to include in the settings backup scope. In this folder I have a file saved that contains, among other things, a list of packages, which we will save in a moment.

If we are transferring settings from one router to another, it is worth copying and writing down this list, which I will also write about.

So, to generate a list of installed packages, we execute the command in the SSH terminal:

opkg list-installed > /root/my_installed_packages

It is also a good idea to save this list to your local computer.

I will not describe here how to do it using various methods (different for different operating systems), because it is a waste of time.

The file you need will be saved in the freshly generated backup from earlier step. Go back one step and you’re done. Just unpack your backup with Keka (for macOS) or 7Zip (for Windows) and look for it in the /root/ folder. Easy!

We can also execute the command:

cat /root/my_installed_packages

And using the copy/paste method, copy the contents to a file on our computer.


OpenWrt Firmware Update with Restoring Default Settings

At this stage I will not go into detail on how to install the OpenWrt software on your router, as it depends on the hardware you are using (I refer you to here). I assume that your router already has the OpenWrt software installed - either clean or a different version that you will want to update.

The software update is performed from System > Backup / Flash firmware, in the Flash new firmware image section.

OpenWrt - System Backup - Flash Firmware OpenWrt > System > Backup / Flash Firmware

Of course, we choose the software prepared for our version of the router.

We upload the file to our router and at the appropriate step we choose WHETHER we want to keep our router settings or not (Keep settings and retain the current configuration). Personally, I prefer NOT to keep them, because in my case, with DoH set, my DNS will not work, so I will not be able to perform the next steps.

OpenWrt - System Backup - Flash Firmware - Uploading file OpenWrt > System > Backup / Flash Firmware > Uploading file

OpenWrt - System Backup - Flash Firmware - flash image OpenWrt > System > Backup / Flash Firmware > flash image

You can experiment with keeping your settings and restoring packages (next step), but keep in mind that after restoring previously installed packages, you may need to restore a backup anyway.


Restore packages from previously generated list

Upewniając się, że nasz router posiada działające połączenie z internetem, łączymy się z naszym routerem za pomocą terminala SSH (domyślnie musimy to zrobić na kablu LAN, gdyż WiFi z reguły jest wyłączone):

ssh root@192.168.1.1 -p 22

First of all, I would recommend updating the packages that are currently on the system before we attempt to restore them. We do this with the command:

opkg update; opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade

In some cases, the above command will display a download error (Failed to download) or return information that we do not have an internet connection (Check your network settings and connectivity).

Then you should run the command: opkg update separately, install the latest version of wget using opkg install wget and download the latest CA certificates wget --no-check-certificate -O /etc/ssl/certs/ca-certificates.crt http://curl.se/ca/cacert.pem.

Then, repeating the above command should make everything work.

Time to restore packages.

If we are starting from scratch, we need to generate the file my_installed_packages

touch /root/my_installed_packages

Then we move on to editing it.

vim /root/my_installed_packages

By clicking the “i” key we enter the editing mode. Now, using Copy/Paste we transfer the contents of our file from the backup copy (or in the file to which we saved the contents of my_installed_packages from the previous steps). After successfully pasting the contents, click the Esc button and then execute “:w” to save the contents, and “:q” to exit editing.

And so we have everything ready to restore the packages. The command below will compare what is already in our system with what we have in our file and install what is missing. If there is one in our package list that is incompatible with the current OpenWrt software, it will be automatically skipped.

opkg update && opkg list-installed | cut -f 1 -d ' ' | sort -u > /tmp/currentpkg && cat /root/my_installed_packages | cut -f 1 -d ' ' | sort -u > /tmp/oldpkg && grep -v -F -x -f /tmp/currentpkg /tmp/oldpkg > /tmp/inst && opkg install $(cat /tmp/inst | sort -u) && rm /tmp/currentpkg /tmp/oldpkg /tmp/inst

Uploading files via SFTP

It would be nice to connect to our router so that we could easily restore individual files. This is especially useful when we set up our router from scratch and restore individual files from a backup.

For this purpose, I recommend the SFTP protocol (SSH File Transfer Protocol).

However, before we can connect, we need to install an SFTP server from the terminal.

opkg update
opkg install openssh-sftp-server

Then, using an application such as Cyberduck on macOS or Filezilla, we can establish a connection and transfer the files we need.


Restoring settings from backup

The final step will be to restore our settings from a saved backup.

OpenWrt - System Backup - Flash Firmware - firmware restore OpenWrt > System > Backup / Flash Firmware > firmware restore

We go again to System > Backup / Flash firmware and from the restore item we select Upload archive, where we indicate our file saved on our computer, then confirm everything when we are asked whether to apply the changes (Apply backup?) by clicking Continue.

We restart the router (if this does not happen after restoring the settings) and check if everything works.

This way, everything should work 99% of the time. There is always a chance that something won’t work as it should. If anything, let me know in the comments.


Credits: forum.openwrt.org/t/how-to-keep-packages-settings-after-upgrading/38998

Share on Threads
Share on Bluesky
Share on Linkedin
Share via WhatsApp
Share via Email

Comments & Reactions

Categories