How to optimize package storage: asu/auc, owut and firmware-selector

Attended Sysupgrade (ASU/auc), owut, firmware selector and openwrt-imagebuilder-***.tar.zst all allow customizing the openwrt image.

While updating with Attended Sysupgrade (with luci), it openly suggests to add all currently installed packages in the image that is going to be installed and this is the default behavior.

I have a 16mb device (RB962UiGS-5HacT2HnT (hAP ac)) and I wanted to install tailscale, which installed might go up to 25mb (There are instructions how to minify tailscale). This motivated me to figure out how package size is calculated.

First, how is storage used. If I understand correctly, the image is installed in
/rom and the rw part is in /overlay.

# lsblk
NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
mtdblock0  31:0    0  128K  0 disk 
mtdblock1  31:1    0   56K  1 disk 
mtdblock2  31:2    0    4K  1 disk 
mtdblock3  31:3    0    4K  1 disk 
mtdblock4  31:4    0   60K  1 disk 
mtdblock5  31:5    0    4K  0 disk 
mtdblock6  31:6    0 15.9M  0 disk 
mtdblock7  31:7    0  2.7M  0 disk 
mtdblock8  31:8    0 13.2M  0 disk /rom
mtdblock9  31:9    0  6.8M  0 disk /overlay

My router is 16mb, so that's probably mtdblock6? Then it is split into mtdblock7 and mtdblock8. But then /rom + /overlay is 13.2+6.8=20mb, which I don't have an explanation for. Maybe mtdblock9 is an uncompressed version of mtdblock7. I don't know. My router's page doesn't have a description

But then:

# du -sh /rom
23.7M   /rom

This in my head means mtdblock8 is somehow compressed and I get 23.7mb out of 13.2, compression ratio is 23.7/13.2=1.80

I don't know how to calculate the data compression ratio of /overlay, but basically /rom and /overlay is a zero-sum game. So which place is better for a package?
If I want to update a remote device that I only access via tailscale, then I need to create an image with tailscale already baked in and some uci-defaults scripts to configure it.


Second, what are the default packages of a clean openwrt. Every sub-target has a manifest file (example). But this contains all the dependencies.

The firmware-selector gives a better answer in the customized field.

I tested and I can create an image without any of the default packages - 3.3 mb bin file. Will the .bin be the size of the mtdblock8?

Tested again and the default 24.10.0 image for my device is 7.2mb, that means all the 'default' packages are 3.9mb. Can I remove any of them?

My final test was to add tailscale to the build, The result is 13.3. Does that mean I can flash it on the device?

Questions:

  1. why is /rom + /overlay = 20mb, when I have 16mb storage?
  2. what is the data compression ratio of /rom and of /overlay?
  3. can I remove any of the 'default' packages, if yes, which ones?
  4. Will the .bin file be exactly the same size as mtdblock8? Is it copied one-to-one or does it do something else?
  5. If the image is 13.3mb, does that mean I can flash it on a 16mb device?

1/ compression
2/ lzma / none
3/ you can remove web, wifi, firewall like complete blocks
4/ depends on platform
5/ no

cat /proc/mtd will explain partition assignments

probably mount usb storage and install hog packages there? not extrot.

your last answer - why not. And what is the limit?

Like petabytes?

It would be cool if Openwrt ever got into a double image mode, where you get an image for the router and all it does it chain boot along to usb. So the build just generates two images and anything with a USB port doesn't have to worry about any of this end of story.

dmesg explains mtd:

    0.437988] Creating 5 MTD partitions on "RouterBoot":
[    0.443205] 0x000000000000-0x00000000e000 : "bootloader1"
[    0.449677] 0x00000000e000-0x00000000f000 : "hard_config"
[    0.457438] 0x00000000f000-0x000000010000 : "bios"
[    0.463234] 0x000000010000-0x00000001f000 : "bootloader2"
[    0.471005] 0x00000001f000-0x000000020000 : "soft_config"
[    0.477567] 0x000000020000-0x000001000000 : "firmware"
[    0.485763] 2 minor-fw partitions found on MTD device firmware
[    0.491699] Creating 2 MTD partitions on "firmware":
[    0.496785] 0x000000000000-0x0000002b0000 : "kernel"
[    0.503349] 0x0000002b0000-0x000000fe0000 : "rootfs"
[    0.509248] mtd: setting mtd8 (rootfs) as root device
[    0.515235] 1 squashfs-split partitions found on MTD device rootfs
[    0.521529] 0x000000920000-0x000000fe0000 : "rootfs_data"

But this is even more confusing:

  1. kernel starts from 0, so all before kernel are part of kernel?
  2. rootfs_data is part of rootfs

Yeah, it is called extroot, so durable you cannot sysupgrade.

1 Like

you said I cannot flash 13.2mb image on my 16mb device. Why not? What's the limit (12mb, 13mb, 14mb, some formula)?

Will the firmware-selector protect me?

Yes, what happens if the usb is removed? Can the router survive?

Not really what i'm saying I think but hey. Yeah there is extroot.

You asked general question. Yes fw selector will permit images up to accessible flash space.

You know that thing, called documentation?

I apologize, ignore my exroot question.

Back to 13.2mb question. Why did you say it wont flash? The default image is 7.2mb so I guess that works, but is there a mechanism that protects me agains flashing something that will brick the device?

At upper limit you will lose writable overlay.

So 13.2mb might work, with the caveat of almost non-existent rw space.

Is there some kind of pattern or rule or strategy which packages go to /rom and which should be in \overlay?

If I have to construct a strategy it would be as follows:

  1. in /rom go only what is needed to access the device after sysupgrade (wifi, networking, vpn, ...)
  2. /overlay - everything else
    1. until one runs out of space and then optimizations such as this forum topic.
    2. no easy updating of such large packages, only sysupgrade.

would be epic
AFAIU exroot might cause even more problems than it solves in my case

You can install packages to /tmp and /mnt/sda. No idea why you would ever require extroot.

  • /mnt/sda - what if it disconnects, currently my usb flash drive is inserted but doesn't show and this is a remote device that I have to be careful updating because I don't have physical access to it
  • /tmp - opkg install -d tmp - I lack enough knowledge and can't find enough information what happens when you reboot. is the package just missing, is it auto-reinstalled, what happens to configuration.

And my large package (tailscale) is vital for me not losing access to the device. (i have a backup wireguard set up, but the idea is not to use it).

Install a local virtual machine with x86 squashfs image and learn something new.

1 Like