HOW TO: Keep packages & settings AFTER upgrading

HOW TO: Keep packages & settings AFTER upgrading.

Hi,

many of you (like me) had troubles / work after each UPGRADE.

  • REINSTALL our personal packages, other than what comes as a default.
  • COPY specific files / configurations after an upgrade.

Most is done by OpenWRT automatically, however some needs a little tweaking.

So, if you did NOT CHANGE, add some packages or configuration, than just leave everything as is ... OpenWRT works like a charm out of the box :slight_smile:

For everyone else here are some suggestions:

What to do:

Make a LIST of all currently install packages:

opkg list-installed > /etc/config/my_installed_packages

You might want to put the command into a CRON ... depending on how much you keep changing the packages on your router :slight_smile:

EDIT this file, which keeps track of what to SAVE during image upgrades:

/etc/sysupgrade.conf

Here is a SAMPLE of such a file:

## This file contains files and directories that should
## be preserved during an upgrade.

## Info about packages THIS FILE
/etc/sysupgrade.conf

# LIST of all installed packages
# CREATED using: "opkg list-installed > /etc/config/installed.packages"
# RUN this after you install NEW packages!
/etc/config/installed.packages

# RESTORE suing: "opkg update 
#			   && opkg list-installed | cut -f 1 -d ' ' | sort -u > /tmp/currentpkg 
#              && cat /etc/config/my_installed_packages | cut -f 1 -d ' ' | sort -u > /tmp/oldpkg 
#			   && grep -v -F -x -f /tmp/currentpkg /tmp/oldpkg > /tmp/inst 
#			   && opkg install $(cat /tmp/inst | sort -u)
#			   && rm /tmp/currentpkg /tmp/oldpkg /tmp/inst"
#
# "opkg update && opkg list-installed | cut -f 1 -d ' ' | sort -u > /tmp/currentpkg && cat /etc/config/my_installed_packages | cut -f 1 -d ' ' | sort -u > /tmp/oldpkg && grep -v -F -x -f /tmp/currentpkg /tmp/oldpkg > /tmp/inst && opkg install $(cat /tmp/inst | sort -u) && rm /tmp/currentpkg /tmp/oldpkg /tmp/inst"
#

## FOLDERS
# /etc/example/
/etc/crontabs/
/etc/dropbear/
/etc/openvpn/
/etc/profile
/etc/samba/
/etc/unbound/
/root/

## FILES
# /etc/example.conf
/etc/TZ
/etc/banner

AFTER an upgrade run this command:

opkg update && opkg list-installed | cut -f 1 -d ' ' | sort -u > /tmp/currentpkg && cat /etc/config/my_installed_packages | cut -f 1 -d ' ' | sort -u > /tmp/oldpkg && grep -v -F -x -f /tmp/currentpkg /tmp/oldpkg > /tmp/inst && opkg install $(cat /tmp/inst | sort -u) && rm /tmp/currentpkg /tmp/oldpkg /tmp/inst

This will compare your current (after upgrade) list of packages and compares them to the one you previously saved in /etc/config/installed.packages and copies all missing items. OpenWRT is smart enough to not copy things which are NOT compatible with the current version you have installed.

A few common hurdles:

Can NOT access the CLI with SSH remotely:

check your SSH client and see if it wants to start a SHELL (other than the default ash). In my setup, using PuTTY I have PuTTY execute (setting under connection/SSH/Remote command:

/bin/bash -l

SAMBA does not work anymore

check your NETWORK SHARES, you might need to recreate them.

UPDATES:

@jeff was pointing out that in version 19.x of OpenWRT there is a NEW option of sysupgrade -k

include in backup a list of current installed packages at
/etc/backup/installed_packages.txt

This option does what I suggested to be done on the CLI above. Theoption -k is set / or not depending on where you get your OpenWRT images from.

I CHANGED the name of the file containing the installed packes to avoid any confusion with what sysupgrade does.

githubrobbi

You might want to consider looking at what is available on master and openwrt-19.07 and revise your script appropriately to take advantage of sysupgrade -k

Edit: Removing busybox sh will cause many things to fail, including boot. Changing the shell of the primary superuser, typically root, is generally not recommended on OpenWrt, or any other `nix distribution. Adding a user with, for example bash as their shell, is a safer approach.

2 Likes

Good feedback.

How do I know that the LuCI- command for backing up the setting uses this option -k by default? Mine does NOT (KongPRO 19.07 06-17-2019)

It might be redundant, to create the installed packages list using my way; regardless if the LuCI command is doing it too. However the generated files are tiny.

Thanks for the feedback though.

Robert

PS:

Regarding the 'superuser access': You are TOTALLY correct to use a USER rather then ROOT for your daily dealings with *nix and that is what I do ... use SUDO to do the heavy lifting.

Regarding the shell: Removing any core items from any OpenWRT installation should almost ALWAYS be avoided ... I still have 'busybox sh' etc.

... thanks for the heads up though.

No idea what "KongPRO" is, and I don't know if it has been integrated into LuCI, but if I were tackling it, I'd use the same code to generate the "list of packages" and then provide the valuable script that tries its best to restore the user-installed packages that aren't in the just-installed ROM. By using the same format, it would benefit those using your script on older releases, as well as those that might be using a newer release and the in-built feature.

1 Like

... this is NOT an issue ... its pretty much the same way I do it ... using opkg

The approach above is MORE than just the packages. It shows people how to also include other files and folders. So people end up to do some CLI work anyhow.

I think the same way like you ... why re-invent the wheel ...

The approach above is non-dependent other than the core tools of OpenWRT. Its self contained and thus should NOT do any harm.

Will UPDATE the NAME of the file containing the installed packages ... its too similar to the one they started using with the -k option.

As an alternative, I build openwrt from sources and keep the .config file. I just add all the packages I need into the upgrade file using menuconfig so when I upgrade, I have everything ready. This is obviously only good if you are building your own images.

If there are files I modify outside standard configs, I add them to backup paths and when I create a backup file they come with it. I can simply restore it after an upgrade.