balena-os / meta-balena

A collection of Yocto layers used to build balenaOS images
https://www.balena.io/os
968 stars 115 forks source link

Profile and reduce host OS image size #810

Open willnewton opened 7 years ago

willnewton commented 7 years ago

Profile the on-disk size of resinOS and find areas where it can be reduced.

shaunmulligan commented 7 years ago

maybe look at some of the useless kernel modules we add by default, like PS/2 mouse and joystick drivers :P

willnewton commented 7 years ago

This is the list of installed packages. Total size is 218334kB, of which:

Of the rest a large part of that is pulled in by systemd/networkmanager I think.

A good place to start would be slimming down firmwares for devices that do not need them, e.g. the Intel Wifi firmwares (40MB of them) don't make a whole lot of sense on non-Intel platforms.

Other things that stand out from the list that could be removed:

installed-package-sizes.txt

willnewton commented 7 years ago

It looks like the lvm2 dependency is dropped by the hostapps PR:

https://github.com/resin-os/meta-resin/pull/805/commits/f5c783df899172d9e904818835a6da575d6631ab

willnewton commented 7 years ago

Opened a PR to reduce kernel size here:

https://github.com/resin-os/meta-resin/pull/813

imrehg commented 7 years ago

@willnewton would the file systems make sense to keep since people can use external storage, etc? (and they did use, e.g. external USB stick and such) Or if those are removed from here, would people be able to add them back easily in the container?

willnewton commented 7 years ago

Opened a PR for systemd-analyze here:

https://github.com/resin-os/meta-resin/pull/814

willnewton commented 7 years ago

@imrehg the fileystems are mostly for servers or osbolete:

I left in NFS and CIFS as these seem legitimately useful, we also keep XFS.

alexgg commented 4 years ago

The comments above have size optimized the following:

Although the effort above can be repeated, it is unlikely that we would find any big space saver left. The analysis for v2.48 is summarized in:

284M    /build/balena-intel/build/tmp/work/genericx86_64-poky-linux/resin-image/1.0-r0/rootfs/

36M     /lib/modules
61M     /lib/firmware
45M     /usr/lib
34.5M   /usr/bin/balena-engine
12.2M   /boot/bzImage
7.2M    /boot/init
6.4M    /resin-boot
5M      /usr/bin/os-config
3.1M    /usr/lib/rust/libstd.so
2.8M    /usr/sbin/NetworkManager
1.5M    /usr/sbin/ModemManager
1.4M    /lib/systemd/systemd
1M      /bin/bash.bash

218M, 67M unaccounted (< 1M objects)

On v2.51 with the update of balena-engine the filesystem has gone above it's threshold again. Looking at the above list the following actions can be considered:

  1. Enable kernel compression
  1. Enable firmware compression
  1. Enable balena-engine compression
  1. Enable os-config compression
  1. Removing unneeded files from /boot directory

Also, the inactive partition is 300M, but a 5% is reserved by default (~15M) so only a hostapp of 285M can be updated. As the root filesystem is read-only and nothing read or writes to it, there is no reason not to remove this reserve and use the whole available space, which is 300M minus the 8M journal size.

alexgg commented 2 years ago

Updating on this, according to https://wiki.debian.org/LTS Strech has gone EOL on the 30th June 2022. And according to https://ubuntu.com/about/release-cycle 18.04 LTS (Bionic Beaver) is now under ESM (Extended Security Maintenance). It's a good moment to explore adding module compression as default and checking that Stretch and Bionic can still use non-compressed kernel modules.

jellyfish-bot commented 2 years ago

[alexgg] This has attached https://jel.ly.fish/6e6207ca-a304-4b94-88fe-0cb6ddd40b2d

alexgg commented 1 year ago

Bullseye supports module compression:

root@87d09b8ecf24:/# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@87d09b8ecf24:/# modprobe -V
kmod version 28
-ZSTD +XZ -ZLIB +LIBCRYPTO -EXPERIMENTAL