[Solved] How to remove unused dependencies from LEDE?

I did not found how to remove unused dependencies in opkg help or in the forum. I had installed some luci-app-xxx and then the space left was too little. I removed most of them but the space increased only about 100kb, now I have 744kb left.
I thought I should not use --force-removal-of-dependent-packages when I removed the packages, because this option maybe removes dependencies even if other packages use them too, was that right?
--autoremove without a package name does nothing, so what's the difference from --force-removal-of-dependent-packages?
What should I do to remove or list unused dependencies? Is there a way to list all packages sorted by size? (I wish there was package size at Luci installed packages and a remove option at the available packages.)
Model Netgear DGN3500|
Firmware Version LEDE Reboot 17.01.4 r3560-79f57e422d / LuCI lede-17.01 branch (git-17.336.23170-d2dc32a)
Kernel Version 4.4.92|

The command is:

opkg remove foo –force-removal-of-dependent-packages

...but, if that is not working, it's likely the package is a dependency of another package.

Not right. From the opkg command:

--force-removal-of-dependent-packages
Remove package and all dependencies

The dependency package(s) will not uninstall unless they're uneeded by other installed packages.

As I said, I removed some packages without the –force-removal-of-dependent-packages option at the end. So now do I have to reinstall them and removed them again with –force-removal-of-dependent-packages?
Is the next option:
--autoremove Remove packages that were installed automatically to satisfy dependencies
for removing all remaining dependencies, without removing the initial package at the same time? I mean if I removed it earlier.
At last, is there another package manager in LEDE repositories like apt that does:
apt-get autoremove
and all unused dependencies are removed?

Thanks for your help @lleachii !

Just reinstall them...how else would you remove dependencies of an installed package???

I recommend typing opkg at the command line, and reading the directions.

I usually use opkg to update remove list-upgradable upgrade. I use LuCI/Software just to browse the packages, see the size of them, and the remaining free space.
But when I ask How to remove unused dependencies from LEDE? and ask for anyone to explain the difference between

--force-removal-of-dependent-packages Remove package and all dependencies

and

--autoremove Remove packages that were installed automatically to satisfy dependencies

and if any of them or another option, or another package manager does something like in Ubuntu does the

apt-get autoremove

after reading the opkg help, I could explain to my self that

Remove packages that were installed automatically to satisfy dependencies

is about the packages that where installed automatically when I installed some other packages, not about the system packages!
So believing that

opkg remove --autoremove '*'

will remove unused dependencies, I get this:

root@LEDE:~# opkg remove --autoremove '*'
Removing package kmod-usb-storage from root...
kmod-scsi-core was autoinstalled and is now orphaned, removing.
Removing package kmod-scsi-core from root...
Refusing to remove essential package libc.
	Removing an essential package may lead to an unusable system, but if
	you enjoy that kind of pain, you can force opkg to proceed against
	its will with the option: --force-removal-of-essential-packages
Removing package opkg from root...
Not deleting modified conffile /etc/opkg/customfeeds.conf.
Not deleting modified conffile /etc/opkg.conf.
Refusing to remove essential package libpthread.
	Removing an essential package may lead to an unusable system, but if
	you enjoy that kind of pain, you can force opkg to proceed against
	its will with the option: --force-removal-of-essential-packages
Refusing to remove essential package busybox.
	Removing an essential package may lead to an unusable system, but if
	you enjoy that kind of pain, you can force opkg to proceed against
	its will with the option: --force-removal-of-essential-packages
Removing package odhcpd from root...
Removing package nano from root...
libncurses was autoinstalled and is now orphaned, removing.
Removing package libncurses from root...
terminfo was autoinstalled and is now orphaned, removing.
Removing package terminfo from root...
Removing package kmod-usb-dwc2 from root...
Removing package swconfig from root...
Removing package base-files from root...
Not deleting modified conffile /etc/shells.
Not deleting modified conffile /etc/protocols.
Not deleting modified conffile /etc/sysctl.conf.
Not deleting modified conffile /etc/iproute2/rt_protos.
Not deleting modified conffile /etc/shadow.
Not deleting modified conffile /etc/sysctl.d/local.conf.
Not deleting modified conffile /etc/rc.local.
Not deleting modified conffile /etc/services.
Not deleting modified conffile /etc/sysupgrade.conf.
Not deleting modified conffile /etc/group.
Not deleting modified conffile /etc/hosts.
Not deleting modified conffile /etc/iproute2/rt_tables.
Not deleting modified conffile /etc/inittab.
Not deleting modified conffile /etc/profile.
Not deleting modified conffile /etc/passwd.
netifd was autoinstalled and is now orphaned, removing.
Removing package netifd from root...
procd was autoinstalled and is now orphaned, removing.
Removing package procd from root...
procd-nand was autoinstalled and is now orphaned, removing.
Removing package procd-nand from root...
usign was autoinstalled and is now orphaned, removing.
Removing package usign from root...
lede-keyring was autoinstalled and is now orphaned, removing.
Removing package lede-keyring from root...
fstools was autoinstalled and is now orphaned, removing.
Removing package fstools from root...
ubi-utils was autoinstalled and is now orphaned, removing.
Removing package ubi-utils from root...
fwtool was autoinstalled and is now orphaned, removing.
Removing package fwtool from root...
Removing package ddns-scripts from root...
Not deleting modified conffile /etc/config/ddns.
Removing package dnsmasq from root...
Not deleting modified conffile /etc/config/dhcp.
Removing package kmod-ledtrig-heartbeat from root...
Removing package block-mount from root...
ubox was autoinstalled and is now orphaned, removing.
Removing package ubox from root...
ubus was autoinstalled and is now orphaned, removing.
Removing package ubus from root...
ubusd was autoinstalled and is now orphaned, removing.
Removing package ubusd from root...
Removing package kmod-ltq-atm-ar9 from root...
br2684ctl was autoinstalled and is now orphaned, removing.
Removing package br2684ctl from root...
Removing package odhcp6c from root...
Removing package uclient-fetch from root...
Removing package libuclient from root...
Removing package kmod-ath9k from root...
kmod-ath9k-common was autoinstalled and is now orphaned, removing.
Removing package kmod-ath9k-common from root...
kmod-ath was autoinstalled and is now orphaned, removing.
Removing package kmod-ath from root...
kmod-mac80211 was autoinstalled and is now orphaned, removing.
Removing package kmod-mac80211 from root...
kmod-cfg80211 was autoinstalled and is now orphaned, removing.
Removing package kmod-cfg80211 from root...
iw was autoinstalled and is now orphaned, removing.
Removing package iw from root...
Removing package uci from root...
Removing package wpad-mini from root...
Removing package dropbear from root...
Not deleting modified conffile /etc/dropbear/dropbear_rsa_host_key.
Not deleting modified conffile /etc/config/dropbear.
Removing package radicale-py3 from root...
python3-logging was autoinstalled and is now orphaned, removing.
Removing package python3-logging from root...
python3-openssl was autoinstalled and is now orphaned, removing.
Removing package python3-openssl from root...
libopenssl was autoinstalled and is now orphaned, removing.
Removing package libopenssl from root...
python3-xml was autoinstalled and is now orphaned, removing.
Removing package python3-xml from root...
python3-codecs was autoinstalled and is now orphaned, removing.
Removing package python3-codecs from root...
python3-email was autoinstalled and is now orphaned, removing.
Removing package python3-email from root...
python3-light was autoinstalled and is now orphaned, removing.
Removing package python3-light from root...
python3-base was autoinstalled and is now orphaned, removing.
Removing package python3-base from root...
zlib was autoinstalled and is now orphaned, removing.
Removing package zlib from root...
libffi was autoinstalled and is now orphaned, removing.
Removing package libffi from root...
libbz2 was autoinstalled and is now orphaned, removing.
Removing package libbz2 from root...
Refusing to remove essential package libstdcpp.
	Removing an essential package may lead to an unusable system, but if
	you enjoy that kind of pain, you can force opkg to proceed against
	its will with the option: --force-removal-of-essential-packages
Removing package mtd from root...
Removing package kmod-owl-loader from root...
Refusing to remove essential package libgcc.
	Removing an essential package may lead to an unusable system, but if
	you enjoy that kind of pain, you can force opkg to proceed against
	its will with the option: --force-removal-of-essential-packages
Removing package mjpg-streamer from root...
libjpeg was autoinstalled and is now orphaned, removing.
Removing package libjpeg from root...
Removing package ppp from root...
Removing package kmod-leds-gpio from root...
Removing package kmod-gpio-button-hotplug from root...
Removing package logd from root...
Removing package kmod-ltq-deu-ar9 from root...
kmod-crypto-manager was autoinstalled and is now orphaned, removing.
Removing package kmod-crypto-manager from root...
kmod-crypto-aead was autoinstalled and is now orphaned, removing.
Removing package kmod-crypto-aead from root...
kmod-crypto-null was autoinstalled and is now orphaned, removing.
Removing package kmod-crypto-null from root...
kmod-crypto-hash was autoinstalled and is now orphaned, removing.
Removing package kmod-crypto-hash from root...
Refusing to remove essential package librt.
	Removing an essential package may lead to an unusable system, but if
	you enjoy that kind of pain, you can force opkg to proceed against
	its will with the option: --force-removal-of-essential-packages
Removing package kmod-fs-f2fs from root...
Removing package slide-switch from root...
jsonfilter was autoinstalled and is now orphaned, removing.
Removing package jsonfilter from root...
Removing package ip6tables from root...
Removing package luci from root...
Removing package kmod-usb-ledtrig-usbport from root...
kmod-usb-core was autoinstalled and is now orphaned, removing.
Removing package kmod-usb-core from root...
kmod-nls-base was autoinstalled and is now orphaned, removing.
Removing package kmod-nls-base from root...
Removing package ltq-adsl-app from root...
Removing package uhttpd-mod-ubus from root...
Removing package hostapd-common from root...
Removing package qos-scripts from root...
tc was autoinstalled and is now orphaned, removing.
Removing package tc from root...
kmod-sched-connmark was autoinstalled and is now orphaned, removing.
Removing package kmod-sched-connmark from root...
kmod-sched-core was autoinstalled and is now orphaned, removing.
Removing package kmod-sched-core from root...
kmod-ifb was autoinstalled and is now orphaned, removing.
Removing package kmod-ifb from root...
iptables-mod-ipopt was autoinstalled and is now orphaned, removing.
Removing package iptables-mod-ipopt from root...
kmod-ipt-ipopt was autoinstalled and is now orphaned, removing.
Removing package kmod-ipt-ipopt from root...
iptables-mod-conntrack-extra was autoinstalled and is now orphaned, removing.
Removing package iptables-mod-conntrack-extra from root...
kmod-ipt-conntrack-extra was autoinstalled and is now orphaned, removing.
Removing package kmod-ipt-conntrack-extra from root...
Removing package ppp-mod-pppoa from root...
linux-atm was autoinstalled and is now orphaned, removing.
Removing package linux-atm from root...
kmod-pppoa was autoinstalled and is now orphaned, removing.
Removing package kmod-pppoa from root...
kmod-atm was autoinstalled and is now orphaned, removing.
Removing package kmod-atm from root...
Removing package kmod-ltq-adsl-ar9-fw-a from root...
Removing package ppp-mod-pppoe from root...
Removing package kmod-ledtrig-netdev from root...
^CInterrupted. Writing out status database.
root@LEDE:~# 
[                  free               mkswap             sort
[[                 fsync              mktemp             start-stop-daemon
ash                fw3                mount              strings
awk                grep               mv                 switch_root
basename           gunzip             nc                 sync
brctl              gzip               netmsg             sysctl
bunzip2            halt               netstat            tail
busybox            head               nice               tar
bzcat              hexdump            nslookup           tee
cat                hwclock            ntpd               test
chgrp              id                 ntpd-hotplug       time
chmod              ifconfig           passwd             top
chown              ip                 pgrep              touch
chroot             iptables           pidof              tr
clear              iptables-restore   ping               traceroute
cmp                iptables-save      ping6              traceroute6
cp                 jshn               pivot_root         true
crond              kill               poweroff           udhcpc
crontab            killall            printf             uhttpd
cut                ldd                ps                 umount
date               less               pwd                uname
dd                 ln                 readlink           uniq
df                 lock               reboot             uptime
dirname            logger             reset              vi
dmesg              login              rm                 wc
du                 ls                 rmdir              which
echo               lua                route              xargs
egrep              luci-bwc           rpcd               xtables-multi
env                luci-reload        sed                yes
expr               md5sum             seq                zcat
false              mkdir              sh
fgrep              mkfifo             sha256sum
find               mknod              sleep
root@LEDE:~# opkg
-ash: opkg: not found
root@LEDE:~#

Now I have a router (with Internet connection for now) that I don't dare to reboot, without opkg and without the knowledge how to repair it.
I don't care about the specific LEDE install. I just want to be able to flash firmware again, because in the LuCI GUI I see this:


Anyone with any useful idea?
OK, I won't put my cat to cry if my Netgear DGN3500 becomes a brick, I have 5 more modem/routers, but this is the only LEDE supported.

You need to understand that removing a package that was included in the originally flashed firmware does NOT free any space. The original firmware and all its packages stay intact. You can only remove those packages that you have installed afterwards.

The file system consists of a read-only firmware squashfs + a read-write jffs2 partition where all your changes get stored (ubifs for some modern routers). When you try removing a pre-installed package, you actually just hide that via a hide mark (in the read-wrote partition) and consume a little bit more disk space (as the original package binaries stay in the read-only part).

As the original firmware is intact, the easiest thing for you is probably to reset the router to the clean flash situation. Just issue the command "firstboot" (or just press that "Perform reset" button) and that should remove all your package changes and config change, leaving the router as if it would have just been flashed. Then reboot and you should be fine.

2 Likes

Really? I was starting seriously thinking whether I should put the cat crying! Thank you @hnyman, you gave me some peace and saved me much time searching what to do!
You mean that if I had just turned off and turn on later it would not boot, but the firstboot or Factory reset will correct the problem?
Have a nice day!

Yes.

If you look at your live router file system e.g. with "df -h", you can see how this is done. There is original firmware as /rom, all your changes in /dev/mtdblockX as /overlay, and then those are combined to be a virtual / root overlayfs system.

root@router2:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 5.3M      5.3M         0 100% /rom
tmpfs                    29.3M    924.0K     28.4M   3% /tmp
/dev/mtdblock5            9.1M    460.0K      8.6M   5% /overlay
overlayfs:/overlay        9.1M    460.0K      8.6M   5% /
tmpfs                   512.0K         0    512.0K   0% /dev

(all your changes, files, configs, packages, are in /overlay/upper and all original stuff in /rom )

Factory reset = firstboot = just clearing the read-write /overlay and reverting back to pure /rom and the clean /overlay will get automatically re-created at the next boot.

If you had rebooted, you might still have used the failsafe mode if your router has buttons. https://wiki.openwrt.org/doc/howto/generic.failsafe
In that mode you could also have performed the "firstboot" and got back to clean slate.

Keeping original firmware intact and having all changes in a separate partition eases up things a lot, as recovering from experiments is rather easy via reset. (But note that you will then have all defaults: no wifi enabled, router at 192.168.1.1, no root password, etc.)

1 Like

Defaults are not a problem for me now on this router, I have done it before once more, when I did another stupid thing. Now I have this

root@LEDE:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 2.8M 2.8M 0 100% /rom
tmpfs 29.3M 608.0K 28.7M 2% /tmp
/dev/mtdblock6 11.6M 2.3M 9.3M 20% /overlay
overlayfs:/overlay 11.6M 2.3M 9.3M 20% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda1 511.0M 100.0M 396.0M 20% /mnt/sda1
/dev/sda2 5.7G 460.9M 5.2G 8% /mnt/sda2
/dev/sda3 511.0M 100.0M 396.0M 20% /mnt/sda3

and next I do the firstboot.
Thanks again, see you!

Well...

root@LEDE:~# firstboot
-ash: firstboot: not found

Should I press the button, or the absence of firstboot means that even the button will fail?

firstboot is part of base-files packages, which you removed :frowning:

Reset button will not help you, as it is just a script leading to firstboot command.

The actual commands/binaries are "firstboot" that calls "jffs2reset".
Both are naturally still there in /rom that still contains ALL original files...

root@router2:/# ls -l /rom/sbin/jffs2*
lrwxrwxrwx    1 root     root            10 Jan 11 18:45 /rom/sbin/jffs2mark -> jffs2reset
-rwxr-xr-x    1 root     root          4117 Jan 11 18:45 /rom/sbin/jffs2reset
root@router2:/# ls -l /rom/sbin/firstboot
-rwxr-xr-x    1 root     root            31 Jan 11 18:45 /rom/sbin/firstboot

Just try running /rom/sbin/jffs2reset directly

Or you may copy those two back to /sbin with "cp /rom/sbin/firstboot /sbin/firstboot" and "cp /rom/sbin/jffs2reset /sbin/jffs2reset"
And then try running firstboot again

You removed so crucial core components, that the usual fallbacks are a bit more difficult to reach :frowning:
The generic failsafe would naturally work, as that only mounts the /rom

Please, I don't want to keep you, at any time we stop and I try later again. For now I have:

root@LEDE:~# ls -l /rom/sbin/jffs2*
lrwxrwxrwx 1 root root 10 Oct 17 17:46 /rom/sbin/jffs2mark -> jffs2reset
-rwxr-xr-x 1 root root 8213 Oct 17 17:46 /rom/sbin/jffs2reset
root@LEDE:~# ls -l /rom/sbin/firstboot
-rwxr-xr-x 1 root root 31 Oct 17 17:46 /rom/sbin/firstboot
root@LEDE:~# cp /rom/sbin/firstboot /sbin/firstboot
root@LEDE:~# cp /rom/sbin/jffs2reset /sbin/jffs2reset
root@LEDE:~# firstboot
Error loading shared library libfstools.so: No such file or directory (needed by /sbin/jffs2reset)
Error relocating /sbin/jffs2reset: fs_state_set: symbol not found
Error relocating /sbin/jffs2reset: find_mount_point: symbol not found
Error relocating /sbin/jffs2reset: find_filesystem: symbol not found
Error relocating /sbin/jffs2reset: volume_find: symbol not found
Error relocating /sbin/jffs2reset: overlay_delete: symbol not found
root@LEDE:~#

Could you print the exact command to

?
Is it?

root@LEDE:~# cd /rom/sbin/
root@LEDE:/rom/sbin# ./jffs2reset

Yes, that should work.

Or simply /rom/sbin/jffs2reset

/rom is just a normal directory tree

Hmm.
sounds like it needs additional libraries, which you have removed :frowning:

But all those will be still in /rom

root@router2:~# ls -l /rom/lib/libfs*
-rw-r--r--    1 root     root         29240 Jan 11 18:45 /rom/lib/libfstools.so

copy them from /rom to the proper places.

root@LEDE:/# /rom/sbin/jffs2reset
Error loading shared library libfstools.so: No such file or directory (needed by /rom/sbin/jffs2reset)
Error relocating /rom/sbin/jffs2reset: fs_state_set: symbol not found
Error relocating /rom/sbin/jffs2reset: find_mount_point: symbol not found
Error relocating /rom/sbin/jffs2reset: find_filesystem: symbol not found
Error relocating /rom/sbin/jffs2reset: volume_find: symbol not found
Error relocating /rom/sbin/jffs2reset: overlay_delete: symbol not found
root@LEDE:/# cd /rom/sbin/
root@LEDE:/rom/sbin# ./jffs2reset
Error loading shared library libfstools.so: No such file or directory (needed by ./jffs2reset)
Error relocating ./jffs2reset: fs_state_set: symbol not found
Error relocating ./jffs2reset: find_mount_point: symbol not found
Error relocating ./jffs2reset: find_filesystem: symbol not found
Error relocating ./jffs2reset: volume_find: symbol not found
Error relocating ./jffs2reset: overlay_delete: symbol not found

So, I do?

cp /rom/lib/libfstools.so /rom/sbin

No.
cp /rom/lib/libfstools.so /lib

You are a bit on uncharted waters, as you have removed almost everything...

so, do the same for other libraries, too, if they are needed.

EDIT: sorry, wrong answer first.
/rom is read-only. So copy it to the normal place, like I already showed in “cp /rom/sbin/firstboot /sbin/firstboot”

Or the correct is:

cp /rom/lib/libfstools.so /rom/sbin/libfstools.so

Sorry for my ignorance...

cp /rom/lib/libfstools.so /lib

Think like /rom/remaining_path --> /remaining_path

Let's see what we did...

root@LEDE:/lib# ls
config libfstools.so modules
firmware libgcc_s.so.1 netifd
functions libjson_script.so network
ld-musl-mips-sf.so.1 libubox.so preinit
libblobmsg_json.so libubus.so upgrade
libc.so libuci.so wifi
root@LEDE:/lib# /rom/sbin/jffs2reset
This will erase all settings and remove any installed packages. Are you sure? [N/y]

Just as expected :wink:
y