Hey! Listen! This post is part of a series on using OpenWrt. Check them all out!
|Beryl travel router with OpenWrt
|OpenWrt upgrade process
|OpenWrt with OpenVPN server on TP-Link Archer C7
|OpenWrt with OpenVPN client on TP-Link TL-MR3020
Typically, when a new version of OpenWrt is released, I completely wipe the router and start over. However, with the recent release of 15.05.1, I wanted to perform an in-place upgrade while preserving all of my data.
Before we begin, it’s important to understand how the OpenWrt upgrade process works. It’s best to quote the wiki on this one:
Both the LuCI and sysupgrade upgrade procedures work by saving specified configuration files, wiping the entire file system, installing the new version of OpenWrt and then restoring back the saved configuration files. This means that any parts of the file system that are not specifically saved will be lost.
In particular, any manually installed software packages you may have installed after the initial OpenWrt installation have to be reinstalled after an OpenWrt upgrade. That way everything will match, e.g. the updated Linux kernel and any installed kernel modules.
Any configuration files or data files placed in locations not specifically listed as being preserved below will also be lost in an OpenWrt upgrade. Be sure to check any files you have added or customized from a default OpenWrt install to back up these items before an upgrade.
This is important to note because OpenWrt doesn’t automatically preserve everything by default. You’ll need to tell OpenWrt which files and directories to preserve in a configuration file.
Check your release
Start by viewing the /etc/openwrt_release file to double-check the version you’re running. Here, you can see I’m on 15.05.
DISTRIB_DESCRIPTION='OpenWrt Chaos Calmer 15.05'
I would highly recommend you make a backup of any necessary configuration files. Also, it’s important to test your backups before you need them! 🙃
Next, you’ll need to determine what files will be preserved through the upgrade by using the command below.
If a file or directory is not in this list, it will not be preserved through the upgrade.
OpenWrt will preserve any files or directories listed in /lib/upgrade/keep.d/ (e.g., /lib/upgrade/keep.d/keep.me) or /etc/sysupgrade.conf. The easiest thing to do is list your needed files or directories in /etc/sysupgrade.conf. My file is shown below.
## This file contains files and directories that should
## be preserved during an upgrade.
You can see that I’m choosing to preserve the entire /etc/config directory, as well as all my crontabs, the certificate and key for LuCI, and my startup file.
I recommend using the sysupgrade utility, since it’s tailor-made for this process.
Start by downloading the new firmware. For upgrades, always use the firmware that ends in sysupgrade.bin, not the factory.bin firmware. In my case, I’m using a TP-Link Archer C7 v2 going from 15.05 to 15.05.1, so I’ll be using this file. Keep in mind, you’ll need enough space in RAM to download the files.
Next, I highly recommend checking the MD5 sum to make sure the file isn’t corrupt.
md5sum -c md5sums 2> /dev/null | grep OK
If the MD5 sum returns OK, you can proceed with the upgrade (the -v flag tells sysupgrade to be verbose.).
sysupgrade -v /tmp/openwrt-15.05.1-ar71xx-generic-archer-c7-v2-squashfs-sysupgrade.bin
Expect the upgrade to take a few minutes. The router should reboot when completed.
Verify you can SSH into your router (assuming you chose to preserve the correct configuration files), then view the /etc/openwrt_release file to check the new version you’re running.
DISTRIB_DESCRIPTION='OpenWrt Chaos Calmer 15.05.1'
Now, you’ll need to re-download all your previously installed packages (this is where that backup list comes in handy).
opkg install package1 package2 package3
I had to re-enable LuCI, you probably will too.
In addition, you’ll need to disable any unneeded services again.
Let me know how your upgrade went!