How to find out which package consumes how much space?

Hello everyone,
I have two identical NSA devices and I have installed the same packages on the two. However, one has around half the free space the other has. I recall once, while looking for a solution to a problem, selecting to "Overwrite files from other packages" (during installation of a package).

I suspect that this is causing the discrepancy. Is it possible to see which packages are consuming how much space?
And in addition, if you once selected "Overwrite files from other packages", can you undo it and return to the original packages/files? I am sure that this was unnecessary and is now only consuming space needlessly.

Thank you for your help
Alex :slight_smile:

AFAIK there is no way to ask for installed size. The information is stored (you can find it in /usr/lib/opkg/status/info/*.control, which has an 'Installed-Size' field), but not retrievable trough opkg.
However, that number is not reliable. The packages are stored on a compressed filesystem, and so it's not easy to tell how much bytes are actually used, and the package system doesn't keep track of it. The 'Installed-Size' is a guess, it is not the size of the file(s), but an estimated compressed size. That estimation is done by the package builder, and it is wrong. There are 3 places where an package can be installed, in squashfs (part of the base system), in jaffs or ubifs (on the remaining build-in flash rom) of on extroot (on an USB stick, or internal harddisk, or ...)
The compression of squashfs is best, jaffs or ubifs has less compression, and extroot normally has no compression. So how to catch that in a single estimation?

Yet you can ask for (uncompressed) sizes of installed files:
du -ah /overlay/upper/
If you want to know which package contributed a file
opkg whatprovides <filename>
or search for it in /usr/lib/opkg/info/*.list

It is easy to compare both installations. Just execute
ls -R /overlay/upper/
on both boxes, and compare the outputs.

Depends if the overwritted file was in the base installation, or in a later installed package. In the latter case the file is actually gone, and the only way to get it back is by extracting it from the package file. (manually or by opkg). When the file was part of the base installation, it's still there. The base installation is in read-only squashfs, and so cannot be changed. To get it back you'll have to understand how the layered filesystem of OpenWrt works. Normally it consists of a readonly squashfs, and a read-write ubi- or jaffs. The readonly part is mounted on /rom/, and the read-write part is mounted on /overlay/upper/. Together, with some magic glue, they are mounted on /. Of you search for a file in /, it first looks in /overlay/upper/, and only if it can't be found there, it looks in /rom/. So if you overwrite a file in squashfs, you can find it in both places, but only the one in /overlay/upper/ is actually used.
So to get the original file back, you only have to delete it in /overlay/upper/. Be careful with this, if the overwritten file does not meet upgraded requirements, your system might render unusable.
BTW, using the layered filesystem it's also possible to delete a file in the ro layer. In that case in the upper layer an entry is created with a special name, meaning 'no such file'.

Your question suggests that you are running out of space. In your case you can choose to install one or more packages on harddisk. I think it can be done by executing
opkg install <package> --dest /mountpoint/of/disk/subdirectory/
You'd better not install a much used package this way, as a disk is slow, and might to have to spinup.
Another way to preserve space is to use the Image Builder to create a new image with the packages included. That way they are installed in squashfs, which has a (far) better compression than in overlay.

1 Like

Thank you @Mijzelf for your perfect reply! :slight_smile:

I will need to play around with it to find out where the disc space is consumed.

Hi, I guess you are aware, that when you compile openwrt yourself with packages you need, they will consume far less flash space because of compression. This is especially useful for routers with small flash.

I did not think about it, but now that you mention it, it does make sense.

I actually have not reached the point at which I am running out of free space. I still have 80 MB on one and 40 on the other. But this difference bugs me given that both should have the same setup.