Here are my notes on upgrading OpenWRT, they are based on my previous post on upgrading.
In this case I’m upgrading specifically TP-Link Archer C7 v2 – the process will be similar for other OpenWRT devices but it’s always worth reviewing the device page. I’ve also got some v5 versions, and this means a slightly different firmware, but the same exact process.
For a major version upgrade it is worth reading the release notes First start by reading the release notes – nothing seems to be specific to my device that requires any special considerations, so I can just proceed.
An upgrade from OpenWrt 21.02 or 22.03 to OpenWrt 22.03.5 is supported in many cases with the help of the sysupgrade utility which will also attempt to preserve the configuration.
I personally prefer the cli based process, so we’ll be following that documentation.
Step 1. While I do nightly automated backups, I should also just do a web UI based backup – this is mostly for peace of mind
Step 2. Download the correct sysupgrade binary -the easy way to do this is by using the firmware selector tool. I recommend that you take the time to verify the sha256sum
of your download, this is rarely an issue but I have experienced bad downloads and it’s hard to debug after the fact.
It is recommend to check you have enough RAM free – thankfully the archer has a lot of RAM (which is used for the /tmp filesystem too) so I have lots of space.
Step 3. Get ready to flash – if you review the post install steps, you’ll see that while the sysupgrade will preserve all of our configuration files – it won’t preserve any of the packages.
This script will print out all of the packages you’ve installed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
cat << "EOF" > /tmp/listuserpackages.awk #!/usr/bin/awk -f BEGIN { ARGV[ARGC++] = "/usr/lib/opkg/status" cmd="opkg info busybox | grep '^Installed-Time: '" cmd | getline FLASH_TIME close(cmd) FLASH_TIME=substr(FLASH_TIME,17) } /^Package:/{PKG= $2} /^Installed-Time:/{ INSTALLED_TIME= $2 # Find all packages installed after FLASH_TIME if ( INSTALLED_TIME > FLASH_TIME ) { cmd="opkg whatdepends " PKG " | wc -l" cmd | getline WHATDEPENDS close(cmd) # If nothing depends on the package, it is installed by user if ( WHATDEPENDS == 3 ) print PKG } } EOF # Run the script chmod +x /tmp/listuserpackages.awk /tmp/listuserpackages.awk |
Save the list away so you can easily restore things post install. There is a flaw with this script as I’ll point out later, but in many cases it’ll work fine for you.
On my dumb access points I get this list of packages
1 2 3 4 5 6 7 |
prometheus-node-exporter-lua-netstat prometheus-node-exporter-lua-wifi prometheus-node-exporter-lua-openwrt prometheus-node-exporter-lua-wifi_stations rsync prometheus-node-exporter-lua-nat_traffic libpcap1 |
Mostly I have the prometheus exporter (for metrics) and rsync
(for backups) installed. My main gateway has a few more packages (vnstat
and sqm
) but it’s similar.
Step 4. Time to flash. Place the firmware you downloaded onto the openwrt router in /tmp
and run sysupgrade
.
1 2 |
# Flash firmware sysupgrade -v /tmp/openwrt-22.03.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin |
This is a bit scary — because you lose your ssh connection as part of the upgrade. It took about a minute and a half of radio silence before the device came back. However, I was then greeted with the new web UI – and over ssh I get the 22.03.5 version splash.
Step 5. Check for any package updates – usually I leave things well enough alone, but we just did a full upgrade so it’s worth making sure we are fully current. Note, this may mess with the script in step 3 since the install dates will change for other components.
1 2 |
opkg update opkg list-upgradable |
If you get any packages listed, we can easily upgrade using opkg upgrade <pkg name>
Step 6. Install packages captured in step 3. Do this by creating a simple script to opkg install <pkg name>
for each package.
1 2 3 4 5 6 7 |
opkg install prometheus-node-exporter-lua-netstat opkg install prometheus-node-exporter-lua-wifi opkg install prometheus-node-exporter-lua-openwrt opkg install prometheus-node-exporter-lua-wifi_stations opkg install rsync opkg install prometheus-node-exporter-lua-nat_traffic opkg install libpcap1 |
Post install, take a careful look at the output of the installs, and look for any *-opkg
files in /etc/config
or /etc
. These are config files which conflicted with local changes.
Sometimes you will want to keep your changes – others you’ll want to replace your local copy with the new -opkg
file version. Take your time working through this as it will avoid tricky problems to debug later.
When I upgraded my main router, vnstat
seems to have been busted in some way. The data file was no longer readable (and it’s backup) – I suspect that some code change caused the format to be incompatible. I had to remove and recreated a new one. Oh well.
Things mostly went smoothly, it took about 30mins per openwrt device and I was going slowly and taking notes. There was one tiny glitch in the upgrade. The /root/.ssh
directory was wiped out – I use this to maintain a key based ssh/scp
from each of my dumb AP to the main router.
Bonus. I found a new utility: Attended Sysupgrade. This is pretty slick as it makes it very easy to roll minor versions (so 22.03.02 -> 22.03.05 for example) but it will not do a major upgrade (21.03 -> 22.03). I’ve installed this on all of my openwrt devices and will use it to stay current. It takes care of all of the upgrade steps above.. but it does suffer the same ‘glitch’ in that /root/.ssh
is wiped out. The other downside is that the custom firmware that is built, breaks the script in step 3 – since the flash install date is the same for all of the components. I’ll need to go refactor that script for my next upgrade.