Apk: can't install anything to RAM

For some reason, libopenssl doesn't install to ram, even if I told so:

# opkg -d ram install tor
Installing tor (0.4.7.10-1) to ram...
Downloading https://downloads.openwrt.org/releases/21.02.1/packages/mips_24kc/packages/tor_0.4.7.10-1_mips_24kc.ipk
Installing libevent2-7 (2.1.12-1) to ram...
Downloading https://downloads.openwrt.org/releases/21.02.1/packages/mips_24kc/base/libevent2-7_2.1.12-1_mips_24kc.ipk
Installing libopenssl1.1 (1.1.1t-2) to root...
Configuring libevent2-7.
Collected errors:
 * verify_pkg_installable: Only have 612kb available on filesystem /overlay, pkg libopenssl1.1 needs 988
 * opkg_install_cmd: Cannot install package tor.

So tor and libevent2 here are installing to ram as intended, but not libopenssl (which is a dependency).

Installing it directly doesn't help either - it tries to install to root instead:

# opkg -d ram install libopenssl
Installing libopenssl1.1 (1.1.1t-2) to root...
Collected errors:
 * verify_pkg_installable: Only have 600kb available on filesystem /overlay, pkg libopenssl1.1 needs 988
 * opkg_install_cmd: Cannot install package libopenssl.

Would using the firmware-selector to include libopenssl into a new 25.12.2 image sidestep the issue for you? Yes, openssl is large, but perhaps it fits for your $unspecified_device that way nevertheless (and you really need to upgrade to a supported version anyways).

My device is 8/128 MB (no USB), and I don't really need the libopenssl (it's only needed for tor), so installing that stuff to /tmp is preferable.

I don't understand the nature of this problem though, do you have an idea why it refuses to install to ram that particular package only?
Thanks.

As tor is highly security sensitive, upgrading is even more important.

Still I would like to understand why is that happening.

If someone with apk system could try the same with equivalent apk -p </path/to/root> option, that would be useful.

I don't think tor will run on only 128MB. Some time ago I installed tor on a RPi zero with 512MB ram. But without swap it crashed within a few hours. With swap it was stable, but the microSD card weared out in a few week.

What was the OS? Was it Tor Relay or Client?
(I have to add my client would be mostly idle)

Raspbian. And AFAIK there is no relay/client distinction. There is Tor, which can be configured as relay, end- and/or entry point or none.
But my setup was running as relay, on 1Mbit.

Raspbian could eat the memory.
And it seems there might be huge distinction in memory usage:

Thanks for sharing your experience, though.

Tracking down odd behavior in an old unsupported OpenWrt release just isn’t that attractive. Putting shared libraries in /tmp (default location for ram) isn’t a good idea to start with and even more so for security related libraries like OpenSSL.

Newer OpenWrt releases include ways to include extra packages in the base install where they end up in the squashfs based /rom which achieves higher compression than than ubifs based /overlay. For flash starved devices this can give extra breathing room.

Can you help to test the new apk behavior? I put the link above.

I upgraded to recent apk-based release, and now I can't install anything to /tmp, even info command doesn't work:

## not sure it's needed
# mkdir -p /tmp/root/etc
# cp -r /etc/apk/ /tmp/root/etc/

# apk info  tor -p /tmp/root/ --root-tmpfs=yes 
ERROR: Unable to read database: No such file or directory
ERROR: Failed to open apk database: No such file or directory

Any ideas?

Already mentioned several times: build the extra packages into the base image of a still supported OpenWrt release. A lot of work went into the image builder - at least try it.

I appreciate the efforts, but in this case I'm afraid they are not helpful:
as owrt image grows, only 384 KiB free space left after fresh latest release installation (other than the flash size, the device itself is quite capable - TP-Link Archer C6 v2, 8/128 MiB).
Additionally, tor now depends on libopenssl3 which requires 4,5 MiB vs ~900 KiB earlier.
So I doubt I can do anything to fit it on flash.

And the whole installation would require 25 MiB now:

# apk add tor --simulate
(1/7) Installing libcap (2.69-r1)
(2/7) Installing libevent2-7 (2.1.12-r2)
(3/7) Installing libatomic1 (14.3.0-r5)
(4/7) Installing libopenssl3 (3.5.6-r1)
(5/7) Installing libpthread (1.2.5-r5)
(6/7) Installing librt (1.2.5-r5)
(7/7) Installing tor (0.4.8.22-r1)
OK: 24.5 MiB in 158 packages

So I would be gratitude for the help on topic, this is my only hope.

I played a little on trying to install hostip, as it is pretty small. I also did the following:

# mkdir -p /tmp/root/etc
# cp -r /etc/apk/ /tmp/root/etc/
# mkdir -p /tmp/root/tmp/cache
# ln -s /tmp/root/tmp /tmp/root/var
# cp -r /tmp/cache/apk/ /tmp/root/tmp/cache
# mkdir -p /tmp/root/lib
# cp -r /lib/apk/ /tmp/root/lib/

Now it throws another error:

# apk --root /tmp/root/ add hostip
(1/2) Installing libsodium (1.0.20-r1)
  Executing libsodium-1.0.20-r1.post-install
  * execve: No such file or directory
ERROR: lib/apk/exec/libsodium-1.0.20-r1.post-install: exited with error 127
(2/2) Installing hostip (2019.08.20~07ac3825-r3)
  Executing hostip-2019.08.20~07ac3825-r3.post-install
  * execve: No such file or directory
ERROR: lib/apk/exec/hostip-2019.08.20~07ac3825-r3.post-install: exited with error 127
2 errors; 38.3 MiB in 225 packages

Well, the execve: No such file or directory makes me believe it is more complicated to setup the environment... No idea what additional files need to copied now, but I guess that's the way to go?

Thank you for trying out, I faced that error too, but the packages themselves are apparently got installed, maybe in somewhat inconsistent state.
I managed to run tor from console, some more tweaking are probably needed to run it properly (symlinks from /tmp/root/.. to /.., LD_LIBRARY_PATH=/tmp/root/usr/lib:/tmp/root/lib, etc.).
But yeah, the first error I faced was because of missed that /lib/apk/, so it seems is a way to go indeed if there is no more seamless way..
Thanks again!

@efahl

Well, you know, you could always try extroot instead... You would need to have a small usb drive for that and the drivers installed, but that is possible by creating a custom image with firmware selector with only minimal packages to save space. Once extroot is configured, you can install all other basic packages and finally tor and have it running normally (still no relay due to high ram requirements).

My router doesn't have USB, unfortunately.

Oh... I see... the problem you have. :pensive_face: