How do I ensure image built with ImageBuilder is not too big for my hardware

Hi,

I am experimenting with ImageBuilder which I have the latest (as of 8 Dec 2018) downloaded and configured on centos 7. I can build images and can build them for my TL=WR841ND v9 which has limited space. I cannot install xl2tpd via opkg as it runs out of space, but, both with my install of Image Builder and the online one at https://as-test.stephen304.com I can build an image with xl2tpd and all the prerequsite modules. I do not want to brick the device, so how can I check the image size is ok for the device? No where does it say that either tool will ckeck the image is suitable.

Thanks again

RB

The binwalk utility can provide some insight as to how large the overlay file system is. It's no guarantee that it won't brick your unit, but at least a bit of insight into if the flashed ROM will likely have enough storage to support configuration and operation.

Here's an example that I have running on my Archer C7:

$ binwalk out/OpenWrt-2018-09-05_2218-0700-ath79-generic/targets/ath79/generic/OpenWrt-2018-09-05_2218-0700-ath79-generic-tplink_archer-c7-v2-squashfs-sysupgrade.bin 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
512           0x200           LZMA compressed data, properties: 0x6D, dictionary size: 8388608 bytes, uncompressed size: 5034275 bytes
1587612       0x18399C        Squashfs filesystem, little endian, version 4.0, compression:xz, size: 10097010 bytes, 1319 inodes, blocksize: 262144 bytes, created: 2018-09-02 18:58:29

size: 10097010 bytes -- About 10 MB for the ROM file system on this Archer C7 (16 MB flash)

and the output of df on the running device

jeff@office:~$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 9984      9984         0 100% /rom
tmpfs                    62248       420     61828   1% /tmp
/dev/mtdblock4            4736       860      3876  18% /overlay
overlayfs:/overlay        4736       860      3876  18% /
tmpfs                      512         0       512   0% /dev

You'll typically want at least three "erase blocks" in your overlay filesystem for it to be usable.

I am not quite sure if the image builder enforces the image size the same way as the full toolchain, but I think so.

You might test it by adding a large package to build, making it surely to exceed your size. If you get a warning then, you know that there is a limit check also in the imagebuilder. If there is no warning, then you are out of luck.

Note that there may also be a narrow corner case, where the image is just small enough to boot successfully, but the first config files take remaining needed flash space from overlay and then the device may get into read-only mode.. Mentioned by jeff as

You'll typically want at least three "erase blocks" in your overlay filesystem for it to be usable.

I am not quite sure if the image builder enforces the image size the same way as the full toolchain, but I think so.

You might test it by adding a large package to build, making it surely to exceed your size. If you get a warning then, you know that there is a limit check also in the imagebuilder. If there is no warning, then you are out of luck.

Yes it does with the caveat mentioned by jeff above. I found a safer approach was to roll the latest distro from https://as-test.stephen304.com. First install the stock openwrt image, configure the router etc, then install the distro from https://as-test.stephen304.com with out luci which frees up a lot of space, then install the extra packages i need that way there is no question of bricking the router. Configure the extra packages manually.

If you're tight on space, then installing packages post facto means that they aren't compressed, as they would be if you included them in the ROM image. It's very roughly a 2:1 difference.

Jeff I do not follow what you mean a 2:1 difference, are you refering to the build image for install, if so then that may not help as when it comes to load time and uncompressing them will not that lead to problems. If I cannot fit the packages the way I did it they are not going to fit when the device boots even if the image is compressed. It will need to be uncompressed at some point. My knowledge of how these things work is almost nill but you cannot fit a pint into a quart pot!

Ah, yes, you're right, but the trick is that you keep the ROM compressed, and when the data is read, the process gets the uncompressed data stream. The squashfs file system, as I recall, uses high-compression xz, as well as removing duplicates of the same file.

From one of my Archer C7s with 16 MB of flash:

jeff@office:~$ sudo du -h -d 0 /rom
25.0M	/rom

jeff@office:~$ df -h /rom
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 9.8M      9.8M         0 100% /rom

jeff@office:~$ ( sudo find /rom -type f -exec cat {} \; ) | wc -c
27952239

Hi, thanks for the clarification, but, just to be sure before I brick the router, if I can build an image with image builder without it croking a size error, does this mean it will run on the device? I can for example build an image for the TL-WR841ND (4m/32M) which includes the ipsec, lx2tpd, strongswan, and pptpd (without luci). This seems a lot of stuff to get on there when there would be no remote way of getting that on with opkg. I would love to load this but am cautious as I do not want to bick the route

I'd take a two- or, to be super conservative, three-pass approach:

  • Look at the distro image, determine the size of the ROM, confirm the size of the overlay on the booted router, take note of how much is used
  • Build without LuCI, no additional packages (less than what's in the distro image)
  • Determine the size of the ROM from the image, confirm the size of the overlay on the booted router
  • Build with what you think you can comfortably fit in, based on the above, estimate how much of an overlay partition you'll have

With an estimate of what the overlay will be with your custom package selection and how much the "default" config takes up, you should be able to estimate how much free space you'd have if you were to flash it. If you're at 200 kB or more, it will probably be tight, but functional (I'm basing that on my memory of the erase block being 64 kB * 3 = 192 kB). A bit below that it probably will boot OK, but you may not be able to save settings. If your down below 128 kB, all bets are off. I personally wouldn't try an image with only 128 kB of free space as it would likely be problematic in the future if things change.

The good news is that many of the TP-Link models have TFTP boot capabilities, so unless you somehow overwrote the boot loader, they should be recoverable from a bad OpenWrt ROM image.