Skip to content

Instantly share code, notes, and snippets.

@rwanyoike
Created July 23, 2022 14:46
Show Gist options
  • Save rwanyoike/a3a319c943e14c73f9f23ce915c6c854 to your computer and use it in GitHub Desktop.
Save rwanyoike/a3a319c943e14c73f9f23ce915c6c854 to your computer and use it in GitHub Desktop.

OpenWrt/LEDE opkg Tips and Tricks

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M

I use an OperWrt router that has 12MB of root disk storage. It makes me conscious of disk space on those occasions I log onto it; especially when handling packages using opkg.

$ df -h /
Filesystem                Size      Used Available Use% Mounted on
overlayfs:/overlay       11.8M     10.2M      1.6M  86% /
                                         # ¯\_(ツ)_/¯

Here are a few of commands I use to identify packages, and remove them together with orphaned dependencies. These work on OpenWrt 18.06.1.

Listing Packages

List all explicitly installed native packages (i.e. present in the opkg database) that are not dependencies [src]:

for i in $(opkg list-installed | sed "s/ - .*//"); do
  if ! (grep -q "Package: ${i}" < /rom/usr/lib/opkg/status) && \
      ! (opkg whatdepends "${i}" | grep -q "depends on ${i}"); then
    echo "${i}"
  fi
done

As a one-liner:

$ for i in $(opkg list-installed | sed "s/ - .*//"); do if ! (grep -q "Package: ${i}" < /rom/usr/lib/opkg/status) && ! (opkg whatdepends "${i}" | grep -q "depends on ${i}"); then echo "${i}"; fi; done
block-mount
btrfs-progs
chattr
curl
ip-tiny
iperf3
kmod-fs-btrfs
kmod-usb-storage
lsattr
luci-app-aria2
luci-app-hd-idle
luci-app-sqm
luci-app-vnstat
luci-app-wireguard
nfs-kernel-server
openssh-sftp-server
rsync

Removing Packages

Remove a target package including all of its dependencies, provided that they are not required by other packages:

$ opkg remove --force-removal-of-dependent-packages --autoremove rsync
Removing package rsync from root...
libpopt was autoinstalled and is now orphaned, removing.
Removing package libpopt from root...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment