Course contentsShow
← Embedded Systems & Computer Architecture
Lesson 802 of 93611. Introduction to Embedded LinuxFree lesson

Creating Minimal Filesystems with BusyBox

Build a compact root filesystem by manually compiling and installing BusyBox to provide basic shell utilities and system commands.

In this lesson, you will learn how to build a space-efficient root filesystem (rootfs) by manually compiling and installing BusyBox to provide essential user-space commands.

When a Linux kernel finishes booting, it requires a filesystem containing the basic tools needed to interact with the system, such as sh, ls, cp, and mount. Installing a full desktop distribution would be overkill for an embedded device. Instead, we use BusyBox—often called "the Swiss Army knife of embedded Linux"—which integrates dozens of common utilities into a single, compact binary.

Configuring and Compiling BusyBox

First, fetch the BusyBox source and configure it for your target architecture. You must ensure the build system uses your cross-compiler:

make menuconfig
# In the menu, select "Settings" -> "Build static binary (no shared libs)" 
# for a truly portable, minimal filesystem.
make CROSS_COMPILE=arm-linux-gnueabihf-

By enabling the static binary option, you avoid the complexity of managing shared libraries (libc) within your rootfs, which significantly reduces the disk footprint.

Installing into the Filesystem

Once compiled, you install the binaries into your target directory structure. BusyBox works by creating "symbolic links" (or hard links) pointing to the main busybox binary. When you run ls, the system actually executes the busybox binary, which checks argv[0] to determine that it should behave like ls.

mkdir -p /mnt/target_rootfs
make CONFIG_PREFIX=/mnt/target_rootfs install

After installation, your bin/ and sbin/ directories will be populated with symlinks. You then need to create the remainder of the Linux directory hierarchy (like /dev, /proc, /sys, and /etc) manually or via a script. Because BusyBox handles the logic of core commands, your filesystem size drops from hundreds of megabytes to just a few megabytes, making it perfect for constrained flash memory.

Key Takeaway: BusyBox minimizes your filesystem by consolidating common utilities into a single multi-call binary, allowing you to build a functional, lightweight user-space environment tailored for your specific embedded hardware.