This article describes how to create a tiny rootfs based on BusyBox.
Test platform: i.MX 95 19x19 LPDDR5 EVK. The attached layer can be used with other platforms as well.
Software: Linux BSP 6.12.34-2.1.0
Boot device: SD card
This article provides a custom meta-tiny-rootfs layer, to simplify the enablement. The layer:
Using the default DISTRO=fsl-imx-wayland and core-image-minimal, the rootfs size is 800MB.
Using the custom DISTRO=tiny-rootfs and core-image-tiny, the rootfs size reduces to 2.6MB.
1. Prepare the Yocto environment according to Section 3, 4, 5 in i.MX Yocto Project User's Guide.
In the next commands, we'll assume the Yocto directory is imx-yocto-bsp, and the build directory is build.
2. Configure the build directory:
cd ~/imx-yocto-bsp/
DISTRO=fsl-imx-wayland MACHINE=imx95-19x19-lpddr5-evk source ./imx-setup-release.sh -b build
Note: The imx-setup-release.sh script accepts only Wayland distributions. We'll set the custom distro at the next step.
3. Set the custom distro. In the build directory, run:
echo 'DISTRO = "tiny-rootfs"' >> conf/local.conf
4. Download the meta-tiny-rootfs archive, and extract it into the ~/imx-yocto-bsp/sources directory.
cd ~/imx-yocto-bsp/sources
tar -xvf meta-tiny-rootfs.tar.gz
5. Add the meta-tiny-rootfs layer to BBLAYERS:
cd ~/imx-yocto-bsp/build
bitbake-layers add-layer ../sources/meta-tiny-rootfs
6. Build the core-image-tiny image.
bitbake core-image-tiny
7. Write the image on an SD card, and boot. You should be able to see a similar log:
[ 6.183401] Run /sbin/init as init process
init started: BusyBox v1.37.0 ()
starting pid 163, tty '': '/bin/mount -t proc proc /proc'
starting pid 164, tty '': '/bin/mount -t sysfs sysfs /sys'
starting pid 165, tty '': '/bin/mount -t devtmpfs devtmpfs /dev'
mount: mounting devtmpfs on /dev failed: Resource busy
starting pid 166, tty '': '/bin/mount -o remount,rw /'
[ 6.246037] EXT4-fs (mmcblk1p2): re-mounted a5abac39-6c11-419f-97ef-86532e2616ad.
starting pid 167, tty '': '/bin/mkdir -p /dev/pts'
starting pid 168, tty '': '/bin/mount -t devpts devpts /dev/pts'
starting pid 169, tty '': '/bin/mount -a'
starting pid 170, tty '': '/sbin/swapon -a'
starting pid 176, tty '': '/etc/init.d/rcS'
starting pid 177, tty '/dev/ttyLP0': '/usr/sbin/ttyrun ttyLP0 /sbin/getty 115200 ttyLP0'
Tiny Rootfs Operating System 1.0.0 imx95-19x19-lpddr5-evk /dev/ttyLP0
imx95-19x19-lpddr5-evk login:
If you want to add additional features to DISTRO_FEATURES, MACHINE_FEATURES, or IMAGE_FEATURES, please use the DISTRO_TINY_FEATURES, MACHINE_TINY_FEATURES and IMAGE_TINY_FEATURES variables.
For example, to add bluetooth to MACHINE_FEATURES, add the following line in conf/local.conf.
MACHINE_TINY_FEATURES = "bluetooth"
Note: If you need to add a package that requires the full libc (instead of musl), add the following in conf/local.conf:
TCLIBC = "glibc"
These optimizations were inspired by this presentation: Honey, I shrunk the rootfs!