Wednesday, May 16, 2018

Ubuntu Bionic OVA size optimization (reduction)

For Ubuntu 18.04 LTS “Bionic Beaver,” Canonical has released a new installer on the server image, the one with live in the ISO’s filename.  (The old installer, with full feature support, is available as an alternative download.) The new installer is named Subiquity.

We have a set of scripts that take “an Ubuntu install” and turn it into a VM image pre-installed with PHP, Perl, and dependencies for our code.  This creates a “lite” VM build.  (We used to have a “full” build that included all our git repos and their vendored code, but that grew large.  We’ve moved to mounting the code to be run into the guest.)

Our standard build scripts produced an 850 MB OVA file when starting from the new Subiquity-based installer, compared to around 500 MB on previous releases.  The difference?  Previous releases used the “Install a minimal virtual machine” mode option in the old installer.  In fact, after checking I had used zerofree correctly, using the minimal VM mode in the alternate installer for 18.04 produced a 506 MB OVA.

But maybe that alternate install won’t be around forever, and I should fix the bloat sooner rather than later.  Where do those 344 MB come from, and how do we find them?



First things first: how do we find them?  The easiest way is to run sudo apt install wajig followed by wajig large.  This lists out all installed packages with installed sizes over 10 MB, and the winner is…

linux-firmware with over 200 MB installed.

It turns out that the largest difference between our installations is that Subiquity installs linux-image-generic which pulls in linux-firmware and a linux-modules-extra-{KERNEL_VERSION} package.  By installing linux-image-virtual instead, as the old installer did, and getting the extra modules and firmware out of there, the built image size dropped to 675 MB. That’s 175 MB saved with nothing more than a change of kernel.

That’s less than the installed size of the removed packages, because the disk image actually is compressed.  I always wondered about that; now, I know.

Another useful command to run is wajig size, which yields similar output as wajig large, but without the 10 MB cutoff.  All installed packages get listed, sorted by (and shown with) their installed sizes.

After getting ideas from wajig, I ended up going through a diff of apt list --installed on both systems, to clear up a number of other packages that weren’t too relevant for us.  I don’t have the details on what I removed, since I’m not at work now, but there were a few things like filesystem tools for btrfs & xfs, dmevent, lxc/lxd, and other things we didn’t really need to run the development environment on ext4.

The other caveat here is: this is obviously specific to our system.  Others may need to keep some of these things around.

By stripping down the Subiquity install (adding some calls to remove packages in our build scripts), I ended up with a reasonable final size.  It’s not directly comparable to the alternate install, because I also removed emacs-nox (and thus emacs-common) due to changes in the external environment.

No comments: