How to Build a Minimal Ubuntu 24.04 Image for Raspberry Pi 3B (from Scratch)
In this guide, I’ll share how I created a custom, ultra-minimal Ubuntu 24.04.3 LTS image for the Raspberry Pi 3B. Unlike the standard server images which can be bloated, this build starts from the official Ubuntu Base rootfs and adds only what’s necessary, resulting in a lightweight, high-performance system (~400MB compressed).
Why Build Your Own?
- Size: The final image is significantly smaller than the official Server image.
- Performance: Includes optimizations like ZRAM (compressed swap) and Hardware RNG enabled by default.
- Control: You know exactly what packages are installed.
- WiFi Ready: Pre-configured WiFi connectivity (Netplan) and fixed firmware for the RPi 3B’s BCM43430 chip.
Prerequisites
You can run this build script on a Linux machine or Windows (via WSL2). You will need:
wget,git,parted,dosfstools,xz-utilsqemu-user-static(for cross-compiling on x86 machines)sudoprivileges (to mount loop devices)
The Build Process
The entire process is automated in a single bash script. Here is a breakdown of what it does:
1. Download and Verify
We start by downloading the official ubuntu-base-24.04.3-base-arm64.tar.gz and the Raspberry Pi firmware repository. We verify the SHA256 checksum to ensure integrity.
2. Disk Image Creation
We create a raw empty file (2GB) and partition it:
parted -s "$IMAGE_NAME" mklabel msdos
parted -s "$IMAGE_NAME" mkpart primary fat32 1MiB 257MiB
parted -s "$IMAGE_NAME" mkpart primary ext4 257MiB 100%
3. Formatting and Mounting
The image is mounted as a loop device. The first partition is formatted as FAT32 (boot), and the second as EXT4 (rootfs).
4. Chroot Environment Setup
This is the magic part. We extract the Ubuntu Base into the mounted root partition and use qemu-aarch64-static to “enter” the ARM64 environment from our PC. This allows us to run apt-get install as if we were on the Pi.
5. Installing the Kernel & Firmware
We copy the bootloader and kernel files from the Raspberry Pi firmware repo. A critical step for the Pi 3B is installing the correct WiFi firmware:
# Download Cypress firmware for BCM43430
wget -O /lib/firmware/brcm/brcmfmac43430-sdio.bin ...
wget -O /lib/firmware/brcm/brcmfmac43430-sdio.clm_blob ...
# Create the specific symlink required by the Pi 3B
ln -sf brcmfmac43430-sdio.txt /lib/firmware/brcm/brcmfmac43430-sdio.raspberrypi,3-model-b.txt
6. Optimizations
To make the Pi 3B snappy despite its 1GB RAM, we enable:
- ZRAM: Allocates 50% of RAM as compressed swap.
- Hardware RNG: Speeds up boot time and SSH key generation.
- Watchdog: Auto-reboots the system if it freezes.
The Result
The script produces a .img.xz file. You can flash this directly to an SD card using tools like Etcher or Raspberry Pi Imager.
Download the Script: [build_manual.zip]
