[Solved] OPKG - How to list only packages that I have installed?

By following the EXTROOT configuration guide, I was told to remove the packages I have installed:

These devices should have enough space to install the packages we need. Remove all packages you have installed to add functionality, as they are only wasting space now. After you make the extroot you will have all space you need.

But, how to do that? opkg list-installed isn't what I need, because it lists all installed packages, not just the ones I have installed. Neither is opkg list-installed | cut -d- -f1 | opkg status | grep -B 3 "user installed", because it still lists more "user installed" packages than I really installed.

opkg list-installed is the correct command...what are you trying to accomplish???

WHAT!?!?!?

If you have an image from the LEDE site that needs packages uninstalled to make more space, you will have to create a custom image for your needs. Uninstalling included packages doesn't free space.

opkg list-installed is the correct command…what are you trying to accomplish???

opkg list-installed lists busybox and opkg as installed by me. I have not installed opkg using opkg! I remember installing gparted, for example, so I removed it, but there are 125 packages on the result, as I could check with opkg list-installed | grep "." -c.

If you have an image from the LEDE site that needs packages uninstalled to make more space, you will have to create a custom image for your needs. Uninstalling included packages doesn’t free space.

I don't want to remove packages already present on the distro, just the ones I installed after the distro was installed. So, I don't want a smaller LEDE package, but that my LEDE, that already had some packages installed by me, have those packages removed, to free up space on the overlay partition.

1 Like
  • Make a backup of your config
  • Perform a firstboot and restart
  • Restore your config

All the packages you installed will be removed.

1 Like

Perhaps

ls /overlay/upper/usr/lib/opkg/info/*.list | sed -e 's/.*\///' | sed -e 's/\.list//'

(That also shows the ones you have updated, as well as added)

2 Likes

If all the stuff you need to install to get extroot working still fits into your flash, then there's no need to remove anything you installed after flashing.

I asked due to the possibility of removing the USB drive on the future, and then needing to deal with a smaller space again...

https://wiki.openwrt.org/doc/howto/generic.sysupgrade

There is section close to tha top of the page that describes how to list user installed packages.

#!/bin/ash
echo >&2 User-installed packages are the following:
sed -ne '/^Package:[[:blank:]]*/ {
	s///
	h
}
/user installed/ {
	g
	p
}' /usr/lib/opkg/status
1 Like

That actually lists user and default packages

... In addition, packages installed as dependences of other packages may show here.

Do opkg list > current-opkg-list.txt.
Backup your present install and then do fresh install and immediately opkg list > fresh-opkg-list.txt.
The difference will give you some info but not necessarily reveal which packages were installed as dependencies.

From sysupgrade on current master

                # Format: pkg-name<TAB>{rom,overlay,unkown}
                # rom is used for pkgs in /rom, even if updated later
                find /usr/lib/opkg/info -name "*.control" \( \
                        \( -exec test -f /rom/{} \; -exec echo {} rom \; \) -o \
                        \( -exec test -f /overlay/upper/{} \; -exec echo {} overlay \; \) -o \
                        \( -exec echo {} unknown \; \) \
                        \) | sed -e 's,.*/,,;s/\.control /\t/' > ${INSTALLED_PACKAGES}

2 Likes

There seems to be nothing in my /rom or /overlay directories, although there is a /boot/overlay. A device specific difference?

if you have no rom or overlay.... just change the path to /usr......

this is what i run as part of my backup script... apologies if minor errors... had to pull it from a function etc.

BKOPKG="/root/.ostate"
BKDIR="/root"

mkdir -p $BKOPKG

[ ! -f $BKOPKG/original.txt ] && {
	echo "Original package list not present -> creating...."
	opkg list-installed | cut -f 1 -d ' ' > $BKOPKG/original.txt
}

[ ! -f $BKOPKG/available.txt ] && {
	opkg list | cut -f 1 -d ' ' > $BKOPKG/available.txt
}
	
[ ! -f $BKOPKG/opkg.list ] && {
	opkg list | cut -f 1 -d ' ' > $BKOPKG/opkg.list
}

[ ! -f /bin/oget.sh ] && {
	echo "cat $BKOPKG/opkg.list | grep \$1" > /bin/oget.sh
	chmod +x /bin/oget.sh
}	

echo ">>>>>>>>>>>>> Updating package metadata"
if [ -f $BKOPKG/current.txt ]; then
	mv $BKOPKG/current.txt $BKOPKG/previous.txt
else
	opkg list-installed | cut -f 1 -d ' ' > $BKOPKG/previous.txt
fi
opkg list-installed | cut -f 1 -d ' ' > $BKOPKG/current.txt

pkgsincel="`grep -Fvxf $BKOPKG/previous.txt $BKOPKG/current.txt | wc -l`"
if [ "$pkgsincel" -gt 0 ]; then
	echo ">>>>>>>>>>>>> Packages since last backup"
	grep -Fvxf $BKOPKG/previous.txt $BKOPKG/current.txt

       echo "`date +%Y%m%d`" >>  $BKDIR/added.opkg
	grep -Fvxf $BKOPKG/previous.txt $BKOPKG/current.txt >> $BKDIR/added.opkg
else
	echo ">>>>>>>>>>>>> No recently added pkgs"
fi

echo ">>>>>>>>>>>>> Packages since new"
grep -Fvxf $BKOPKG/original.txt $BKOPKG/current.txt
grep -Fvxf $BKOPKG/original.txt $BKOPKG/current.txt > $BKDIR/installed.opkg


[ ! -f $BKDIR/opkgrestore.sh ] && {
echo "for f in \$(cat /root/installed.opkg); do opkg install \$f; done" > $BKDIR/opkgrestore.sh
chmod +x $BKDIR/opkgrestore.sh
}

and the corresponding re-add ( runs remotely )

USER=`echo $1 | cut -d'@' -f1`
ROUTERIP=`echo $1 | cut -d'@' -f2`
PKGLIST="${2}"
if [ -f "/tmp/opkgrestore.log" ]; then rm -f /tmp/opkgrestore.log; fi

ssh $USER@$ROUTERIP 'opkg update'
for pkg in $(cat $PKGLIST); do
	echo -n "####### $pkg"
	ssh $USER@$ROUTERIP 'opkg install '$pkg >/tmp/opkgrestore.log ; retcode=$?
	if [ $retcode -eq 0 ]; then 
		echo " $retcode"
	else
		echo " $retcode"
	fi
done
echo "pkg add complete!"

if [ -f "/tmp/opkgrestore.log" ]; then
	echo "Errors occurred see /tmp/opkgrestore.log"
	cat /tmp/opkgrestore.log
fi

1 Like

Hi, I wrote a small script today.
It works for me.

But I'm using entware on Synology NAS device, so it might not work on OpenWrt though.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.