OpenWrt: upgrading from older OpenWrt versions to 19.x

If you have neglected to upgrade your OpenWrt router from an older version (such as 15.x) to the latest 19.x release, there are manual steps that must be taken to ensure persistence of any custom configurations and package installations.

This article will take you through a manual sysupgrade to 19.x.

The reason we are upgrading only to 19.x and not the latest 21+ release is because Distributed Switch Architecture (DSA) was introduced for multiple target platforms in 21+ and it may not be possible to auto-convert the configuration in this case [1].

Sysupgrade to 19.x

I’m going to assume you have logged into OpenWrt via ssh as root (same credentials used for the LuCI web interface).

If you want to use serial access instead, read my article here.

Identify router hardware

The current version of the firmware can be determined using:

cat /etc/banner
cat /tmp/sysinfo/board_name
cat /tmp/sysinfo/model

Use this information when choosing the correct sysupgrade binary and also for validating that the upgrade was successful.

Verify Package Manager repository

Before moving on, make sure opkg is working properly.

opkg update

If you have any messages that look like “opkg_download: Failed to download http://downloads.openwrt.org/snapshots/trunk/mvebu/generic/packages/base/Packages.gz, wget returned 8”, then you need to edit your opkg repository URL.

Modify “/etc/opkg/distfeeds.conf” so that it points to your current releases packages. For example, for Chaos Calmer here is the URL for package management. Use ‘http’ instead of ‘https’ unless you are prepared to install the correct certificates.

When complete, you should have no errors when running ‘opkg update’.

Save list of user-installed packages

Identify any custom packages that need to be reinstalled after the upgrade.

The listuserpackages.awk script will list which packages have been user installed by checking for a timestamp after the initial flash.

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 script
chmod +x /tmp/listuserpackages.awk
/tmp/listuserpackages.awk /usr/lib/opkg/status > /etc/opkg-beforeupgrade

# save list of user installed packages, will persist after upgrade
echo "/etc/opkg-beforeupgrade" >> /etc/sysupgrade.conf

Custom Configurations

Identify the list of configuration files that sysupgrade will preserve which consists of the files from three locations:

1. Content of files in ‘keep.d’:

cat /lib/upgrade/keep.d/*

2. Files listed in ‘syupgrade.conf’

cat /etc/sysupgrade.conf

3. Files listed by opkg as configuration files

opkg list-changed-conffiles

ACTION: Probably none, but add any known custom files not recognized by the methods above to /etc/sysupgrade.conf

Download the sysupgrade image

You will need to download the 19.x sysupgrade binary that is compatible with your hardware chipset.   The easiest way is to use the firmware selector available here as shown below.

But you can also browse the 19.x download site and manually choose the sysupgrade binary for your chipset. Or you can choose a bleeding-edge snapshot version from the download site.

If the router does not have public internet access, you could use either scp or tftp as described here to copy it to the router.

Download the identified sysupgrade binary to the /tmp directory, which is a temporary RAM disk.

# ideally, your free memory is 2x the sysupgrade binary size
free -m

# wget requirements
opkg install wget ca-bundle ca-certificates
# package name for <=19
opkg install libustream-openssl

# download sysupgrade binary
cd /tmp
wget --no-check-certificate https://downloads.openwrt.org/releases/19.07.10/targets/mvebu/cortexa9/openwrt-19.07.10-mvebu-cortexa9-linksys_wrt1900acv2-squashfs-sysupgrade.bin

There is a full script to verify the checksum if you wanted to be extra diligent.

Run sysupgrade

Run sysupgrade with the 19.x binary image now located in /tmp.

sysupgrade -v /tmp/openwrt-19.07.10-mvebu-cortexa9-linksys_wrt1900acv2-squashfs-sysupgrade.bin

The system will reboot and you will need to give it a minute and then ssh back in. Upon entry, you should see a new version embedded in the banner “OpenWrt 19.yy.zz”.

BusyBox v1.30.1 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 19.07.10, r11427-9ce6aa9d8d
 -----------------------------------------------------

Reinstall custom user packages

We saved the user-installed packages to the file “/etc/opkg-beforeupgrade” before the sysupgrade, and now we can reinstall them.

cat /etc/opkg-beforeupgrade | xargs opkg install

The collected errors will be shown at the bottom. More than likely you will get a few ‘Cannot install package xxxxx’, which could be a result of the package no longer being available on the newer kernel. Retry those manually.

And where a new conf file created, you will be warned and the newer one will be created as ‘/etc/config/<filename>-opkg’. You will need to manually review and merge these files.

 

REFERENCES

OpenWrt, 15.x release chaos calmer

OpenWrt, 18.x release the first for reunified OpenWrt/LEDE merge

OpenWrt, 19.x release page

openwrt forums, required switch and switch_vlan so wan gets DHCP from upstream

OpenWrt, upgrading to 21.x which includes DSA

OpenWrt, DSA (distributed switch architecture) tutorial change from older swdist

OpenWrt, converting to DSA

OneMarcFifty on youtube, VLANs in OpenWrt 21

OpenWrt forums, network settings got my 22.x working with new DSA

github, Attended sysupgrade server

OpenWrt snapshot binaries download site

OpenWrt, avoid upgrading core packages with opkg

NOTES:

Do you have a musl libraries or uClibc?

ls -l /lib | grep libc

useful packages for opkg

# diff and watch
opkg install diffutils procps-ng-watch

Example /etc/config/network for 19.x on Linksys WRT1900ACv2 (Cobra)

config interface 'loopback'                                                                                 
        option ifname 'lo'                                                                                  
        option proto 'static'                                                                               
        option ipaddr '127.0.0.1'                                                                           
        option netmask '255.0.0.0'                                                                          
                                                                                                            
config globals 'globals'
        option ula_prefix 'fc04:2119:3479::/48'
                                                                                                            
config interface 'lan'                                                                                      
        option type 'bridge'                                                                                
        option ifname 'eth0.1'                                                                              
        option proto 'static'                                                                               
        option ipaddr '192.168.1.1'                                                                         
        option netmask '255.255.255.0'                                                                      
        option ip6assign '60'                                                                               
                                                                                                            
config interface 'wan'                                                                                      
        option ifname 'eth1.2'                                                                              
        option proto 'dhcp'                                                                                 
                                                                                                            
config interface 'wan6'                                                                                     
        option ifname 'eth1.2'                                                                              
        option proto 'dhcpv6'                                                                               
                                                                                                            
config switch                                                                                               
        option name 'switch0'                                                                               
        option reset '1'                                                                                    
        option enable_vlan '1'                                                                              
                                                                                                            
config switch_vlan                                                                                          
        option device 'switch0'                                                                             
        option vlan '1'                                                                                     
        option ports '0 1 2 3 5t'                                                                           
                                                                                                            
config switch_vlan                                                                                          
        option device 'switch0'                                                                             
        option vlan '2'                                                                                     
        option ports '4 6t'

example /etc/config/wireless for 19.x on Linksys WRT1900ACv2 (Cobra)

config wifi-device 'radio0'
	option type 'mac80211'
	option hwmode '11a'
	option path 'soc/soc:pcie/pci0000:00/0000:00:01.0/0000:01:00.0'
	option htmode 'VHT80'
	option country 'US'
	option channel '64'
	option disabled '1'

config wifi-iface 'default_radio0'
	option device 'radio0'
	option network 'lan'
	option mode 'ap'
	option macaddr '17:92:63:2d:a3:2f'
	option key '**REDACTED**'
	option ssid 'mywireless5'
	option encryption 'psk2'
	option disabled '1'

config wifi-device 'radio1'
	option type 'mac80211'
	option hwmode '11g'
	option path 'soc/soc:pcie/pci0000:00/0000:00:02.0/0000:02:00.0'
	option htmode 'HT20'
	option country 'US'
	option channel '3'

config wifi-iface 'default_radio1'
	option device 'radio1'
	option network 'lan'
	option mode 'ap'
	option macaddr '26:94:24:3f:b4:2f'
	option key '**REDACTED**'
	option encryption 'psk2'
	option ssid 'mywireless'