
Upgrading OpenWrt from the command line is a straightforward process that requires a few simple steps. Connect to your router using SSH and log in with your credentials.
To begin, you'll need to check the current version of OpenWrt installed on your router. This can be done by running the command `opkg list-installed | grep openwrt`. The output will show you the current version and other relevant information.
You can then check the available updates by running `opkg update`. This will download the latest package list from the OpenWrt repository and update the local cache.
The next step is to upgrade the system by running `opkg upgrade`. This command will install any available updates and upgrade the system to the latest version.
If this caught your attention, see: Update Openwrt
Preparation
Before diving into the upgrade process, it's essential to prepare your environment. You'll need a USB to TTL Serial, which should be connected to your computer and have the driver installed.
To ensure a smooth upgrade, review the release notes for any breaking changes. This will give you an idea of what to expect and help you plan accordingly. Review the upgrade path from your current release to the planned release for any additional breaking changes.
Have a USB terminal app installed, such as minicom, to communicate with your device. This will come in handy later when you're troubleshooting or verifying the upgrade process.
Plan
To create a solid plan for upgrading your system, let's take a look at the steps involved. The full plan requires installing script dependencies, but as the author notes, it's often unclear what dependencies to install at the start.
We need to do a few checks to see what version we're on, what's the newest release, and which partitions contain which. This involves using commands like lsblk with the -pPo flags to get full paths and key=value pairs.

The plan also includes getting a list of user-installed packages for the new version, building the custom image, and downloading and unzipping it to the target partition.
Here's a breakdown of the plan steps:
- Install script dependencies
- Do a few checks to see what version we’re on, what’s the newest release, and which partitions contain which.
- Get a list of user-installed packages for the new version
- Build the custom image, download, and unzip to the target partition
- Remove old kernel(s), install new kernel
- Update GRUB with new kernel and partition ID’s
- Copy config and files from current working version to new version
Keep in mind that the author usually does the first step "last" or adds to the list as they go, so it's not always a straightforward process.
Copy Config and Files
When copying config and files from the current to the new version, it's essential to keep the current working config(s) intact. This step ensures that any customizations you've made are preserved during the upgrade process.
Make sure to copy the contents of /etc and not the /etc directory itself by using the dot notation, like this: `cp -r /etc/. /new/etc/`. This will prevent you from ending up with a nested directory structure.
The sysupgrade.conf file, located in the System -> Backup -> Configuration section of the UI, should be kept intact as well. This file contains any customizations you've made to the system, and it's a good idea to preserve it during the upgrade process.
The sysupgrade.conf file is particularly important if you have installed user-installed applications, as it may not be included in the default configuration. To preserve the sysupgrade.conf file, you can use the following command: `cp -r /etc/sysupgrade.conf /new/etc/sysupgrade.conf`.
Related reading: Azure App Configuration Unique Keys
Upgrade Process
The upgrade process is quite straightforward. To upgrade OpenWrt from the command line, you can use the sysupgrade command.
You'll need to download the upgrade file to your router, which can be done using the wget command. For example, if you're upgrading a 256MB flash device, you can use the following command: cd /tmp; wget http://192.168.1.175/openwrt/imx6/gateworks-imx6-ventana-squashfs-nand_normal.ubi
Once the file is downloaded, you can upgrade your router using the sysupgrade command with the downloaded file: sysupgrade -v gateworks-imx6-ventana-squashfs-nand_normal.ubi
Alternatively, you can upgrade from a URL using the following command: sysupgrade -v http://192.168.1.175/openwrt/imx6/gateworks-imx6-ventana-squashfs-nand_normal.ubi
It's also worth noting that you can customize the sysupgrade process by configuring the files that get backed up and restored in /etc/sysupgrade.conf. This is especially useful if you want your init changes to persist across a sysupgrade.
Take a look at this: Golang Read File Line by Line
Potential Issues
When dealing with installed packages, you may encounter issues like running out of space or not being able to access the internet.
Installed packages like custom DNS software, IDS/IPS, DPI engines, and containers can be problematic during an upgrade.
For example, if you're using a custom DNS software like AdGuard Home, you won't have internet access during the upgrade process.
Some examples of installed packages that can cause issues include:
- Separate DNS server (Adblock, AdGuard Home, Pi-Hole, etc.)
- An IDS/IPS (Snort or otherwise)
- A DPI engine (Netify)
- Containers (Docker or Podman)
One option is to manually remove these packages before upgrading, but this can be time-consuming and error-prone.
Another option is to use the Attended Sysupgrade API to build the image, but keep custom-installed applications on a separate partition.
Update and Restore
To update OpenWrt from the command line, you'll need to upload the new firmware file to your router and decide whether to keep your current settings or not. Personally, I prefer not to keep them, as it can cause issues with DNS settings.
You can upload the file through the OpenWrt interface by navigating to System > Backup / Flash Firmware > Uploading file. Then, you'll need to navigate to System > Backup / Flash Firmware > flash image.
If you choose not to keep your settings, you'll need to 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.
You might enjoy: Rclone Update Hashes
After updating, it's a good idea to restart your router and check if everything works. If you're setting up your router from scratch, it's especially useful to connect to your router to easily restore individual files from a backup.
To restore packages from a previously generated list, you'll need to have an active internet connection on your router. You can do this by connecting to your router via terminal SSH, usually on a LAN cable since WiFi is often disabled.
To generate the file my_installed_packages, you'll need to click the “i” key to enter editing mode, then copy and paste the contents of your backup file. After successfully pasting the contents, click the Esc button and execute “:w” to save and “:q” to exit editing.
Finally, you can restore the packages by running a command that compares what's already in your system with what's in your file and installs what's missing. If there's a package in your list that's incompatible with your current OpenWrt software, it will be automatically skipped.
Broaden your view: Azure Cli Commands List
Frequently Asked Questions
What is OpenWrt sysupgrade?
OpenWrt sysupgrade is a process that updates the firmware on a device by backing up configuration files and upgrading the root file system. It's a safe and efficient way to upgrade your device's software
Featured Images: pexels.com


