{"id":2135,"date":"2023-05-22T10:29:25","date_gmt":"2023-05-22T14:29:25","guid":{"rendered":"https:\/\/lowtek.ca\/roo\/?p=2135"},"modified":"2023-05-22T10:29:25","modified_gmt":"2023-05-22T14:29:25","slug":"openwrt-21-02-to-22-03-upgrade","status":"publish","type":"post","link":"https:\/\/lowtek.ca\/roo\/2023\/openwrt-21-02-to-22-03-upgrade\/","title":{"rendered":"OpenWRT 21.02 to 22.03 upgrade"},"content":{"rendered":"<p>Here are my notes on upgrading OpenWRT, they are based on my <a href=\"https:\/\/lowtek.ca\/roo\/2021\/openwrt-19-07-to-21-02-0-upgrade\/\">previous post on upgrading<\/a>.<\/p>\n<p>In this case I\u2019m upgrading specifically <a href=\"https:\/\/openwrt.org\/toh\/tp-link\/archer_c7\">TP-Link Archer C7 v2<\/a> &#8211; the process will be similar for other OpenWRT devices but it&#8217;s always worth reviewing the device page. I&#8217;ve also got some v5 versions, and this means a slightly different firmware, but the same exact process.<\/p>\n<p>For a major version upgrade it is worth reading the release notes First start by reading the <a href=\"https:\/\/openwrt.org\/releases\/22.03\/start\">release notes<\/a> &#8211; nothing seems to be specific to my device that requires any special considerations, so I can just proceed.<\/p>\n<blockquote><p>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.<\/p><\/blockquote>\n<p>I personally prefer the cli based process, so we&#8217;ll be following that <a href=\"https:\/\/openwrt.org\/docs\/guide-user\/installation\/sysupgrade.cli\">documentation<\/a>.<\/p>\n<p><strong>Step 1.<\/strong> While I do nightly automated backups, I should also just do a <a href=\"https:\/\/openwrt.org\/docs\/guide-user\/troubleshooting\/backup_restore\">web UI based backup<\/a> &#8211; this is mostly for peace of mind<\/p>\n<p><strong>Step 2.<\/strong> Download the correct sysupgrade binary -the easy way to do this is by using the <a href=\"https:\/\/firmware-selector.openwrt.org\/\">firmware selector tool<\/a>. I recommend that you take the time to verify the <code>sha256sum<\/code> of your download, this is rarely an issue but I have experienced bad downloads and it&#8217;s hard to debug after the fact.<\/p>\n<p>It is recommend to check you have enough RAM free &#8211; thankfully the archer has a lot of RAM (which is used for the \/tmp filesystem too) so I have lots of space.<\/p>\n<p><strong>Step 3.<\/strong> Get ready to flash &#8211; if you review the post install steps, you\u2019ll see that while the sysupgrade will preserve all of our configuration files &#8211; it won\u2019t preserve any of the packages.<\/p>\n<p>This script will print out all of the packages you&#8217;ve installed.<\/p>\n<pre class=\"lang:default decode:true \">cat &lt;&lt; \"EOF\" &gt; \/tmp\/listuserpackages.awk\r\n#!\/usr\/bin\/awk -f\r\nBEGIN {\r\n    ARGV[ARGC++] = \"\/usr\/lib\/opkg\/status\"\r\n    cmd=\"opkg info busybox | grep '^Installed-Time: '\"\r\n    cmd | getline FLASH_TIME\r\n    close(cmd)\r\n    FLASH_TIME=substr(FLASH_TIME,17)\r\n}\r\n\/^Package:\/{PKG= $2}\r\n\/^Installed-Time:\/{\r\n    INSTALLED_TIME= $2\r\n    # Find all packages installed after FLASH_TIME\r\n    if ( INSTALLED_TIME &gt; FLASH_TIME ) {\r\n        cmd=\"opkg whatdepends \" PKG \" | wc -l\"\r\n        cmd | getline WHATDEPENDS\r\n        close(cmd)\r\n        # If nothing depends on the package, it is installed by user\r\n        if ( WHATDEPENDS == 3 ) print PKG\r\n    }\r\n}\r\nEOF\r\n \r\n# Run the script\r\nchmod +x \/tmp\/listuserpackages.awk\r\n\/tmp\/listuserpackages.awk<\/pre>\n<p>Save the list away so you can easily restore things post install. There is a flaw with this script as I&#8217;ll point out later, but in many cases it&#8217;ll work fine for you.<\/p>\n<p>On my dumb access points I get this list of packages<\/p>\n<pre class=\"lang:default decode:true\">prometheus-node-exporter-lua-netstat\r\nprometheus-node-exporter-lua-wifi\r\nprometheus-node-exporter-lua-openwrt\r\nprometheus-node-exporter-lua-wifi_stations\r\nrsync\r\nprometheus-node-exporter-lua-nat_traffic\r\nlibpcap1<\/pre>\n<p>Mostly I have the prometheus exporter (for metrics) and <code>rsync<\/code> (for backups) installed. My main gateway has a few more packages (<code>vnstat<\/code> and <code>sqm<\/code>) but it&#8217;s similar.<\/p>\n<p><strong>Step 4.<\/strong> Time to flash. Place the firmware you downloaded onto the openwrt router in <code>\/tmp<\/code> and run <code>sysupgrade<\/code>.<\/p>\n<pre class=\"lang:default decode:true \"># Flash firmware\r\nsysupgrade -v \/tmp\/openwrt-22.03.5-ath79-generic-tplink_archer-c7-v5-squashfs-sysupgrade.bin<\/pre>\n<p>This is a bit scary \u2014 because you lose your ssh connection as part of the upgrade.\u00a0 It took about a minute and a half of radio silence before the device came back.\u00a0 However, I was then greeted with the new web UI &#8211; and over ssh I get the 22.03.5 version splash.<\/p>\n<p><strong>Step 5.<\/strong> Check for any package updates &#8211; usually I leave things well enough alone, but we just did a full upgrade so it&#8217;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.<\/p>\n<pre class=\"lang:default decode:true \">opkg update\r\nopkg list-upgradable<\/pre>\n<p>If you get any packages listed, we can easily upgrade using <code>opkg upgrade &lt;pkg name&gt;<\/code><\/p>\n<p><strong>Step 6.<\/strong>\u00a0 Install packages captured in step 3. Do this by creating a simple script to <code>opkg install &lt;pkg name&gt;<\/code> for each package.<\/p>\n<pre class=\"lang:default decode:true \">opkg install prometheus-node-exporter-lua-netstat\r\nopkg install prometheus-node-exporter-lua-wifi\r\nopkg install prometheus-node-exporter-lua-openwrt\r\nopkg install prometheus-node-exporter-lua-wifi_stations\r\nopkg install rsync\r\nopkg install prometheus-node-exporter-lua-nat_traffic\r\nopkg install libpcap1<\/pre>\n<p>Post install, take a careful look at the output of the installs, and look for any <code>*-opkg<\/code> files in <code>\/etc\/config<\/code> or <code>\/etc<\/code>. These are config files which conflicted with local changes.<\/p>\n<p>Sometimes you will want to keep your changes &#8211; others you&#8217;ll want to replace your local copy with the new <code>-opkg<\/code> file version. Take your time working through this as it will avoid tricky problems to debug later.<\/p>\n<p>When I upgraded my main router, <code>vnstat<\/code> seems to have been busted in some way. The data file was no longer readable (and it&#8217;s backup) &#8211; I suspect that some code change caused the format to be incompatible. I had to <a href=\"http:\/\/www.torrycrass.com\/2011\/06\/19\/vnstat-database-load-failed-even-when-using-backup\/\">remove and recreated a new one<\/a>. Oh well.<\/p>\n<p>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 <code>\/root\/.ssh<\/code> directory was wiped out &#8211; I use this to maintain a key based <code>ssh\/scp<\/code> from each of my dumb AP to the main router.<\/p>\n<p><strong>Bonus.<\/strong> I found a new utility: <a href=\"https:\/\/openwrt.org\/docs\/guide-user\/installation\/attended.sysupgrade\">Attended Sysupgrade<\/a>. This is pretty slick as it makes it very easy to roll minor versions (so 22.03.02 -&gt; 22.03.05 for example) but it will not do a major upgrade (21.03 -&gt; 22.03). I&#8217;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 &#8216;glitch&#8217; in that <code>\/root\/.ssh<\/code> is wiped out. The other downside is that the custom firmware that is built, breaks the script in step 3 &#8211; since the flash install date is the same for all of the components. I&#8217;ll need to go refactor that script for my next upgrade.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here are my notes on upgrading OpenWRT, they are based on my previous post on upgrading. In this case I\u2019m upgrading specifically TP-Link Archer C7 v2 &#8211; the process will be similar for other OpenWRT devices but it&#8217;s always worth reviewing the device page. I&#8217;ve also got some v5 versions, and this means a slightly &hellip; <a href=\"https:\/\/lowtek.ca\/roo\/2023\/openwrt-21-02-to-22-03-upgrade\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;OpenWRT 21.02 to 22.03 upgrade&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,21],"tags":[],"class_list":["post-2135","post","type-post","status-publish","format-standard","hentry","category-computing","category-network"],"_links":{"self":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/2135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/comments?post=2135"}],"version-history":[{"count":2,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/2135\/revisions"}],"predecessor-version":[{"id":2137,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/posts\/2135\/revisions\/2137"}],"wp:attachment":[{"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/media?parent=2135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/categories?post=2135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lowtek.ca\/roo\/wp-json\/wp\/v2\/tags?post=2135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}