Generating minimal file system with busybox for Raspberry Pi 3 Model B
Share on:Edit on:Table of Contents
- Introduction
- Get the busybox source code
- Change configuration
- Download the patch to fix compile time issue
- Compile the busybox
- Install the minimal filesystem
Introduction
In the earlier articles, we compiled toolchain, U-boot, Linux kernel for the Raspberry Pi 3 Model B.
In order for a Linux system to function fully, a few applications are required. When the Linux kernel boots, it tries to mount the filesystem and then looks for an init
program to execute. If the init program is not found, the kernel panicks and boot process will be stopped.
A shell to execute the commands and some basic utilities are also required to make the Linux system usable.
Busybox is a software suite, that generates a minimal root file system with an init program, the shell and basic Linux utilities.
Get the busybox source code
cd ~/rpi3/
git clone git://busybox.net/busybox.git
cd busybox
# Checkout to latest stable version. Can be found with `git tag --sort=v:refname`
git checkout 1_31_1
Change configuration
make menuconfig
- Build busybox statically (without shared liraries) by enabling Settings -> Build static binary (no shared libraries)
- Add cross compiler prefix (aarch64-rpi3-linux-gnu-) by going into Settings -> Cross compiler prefix
- Add installation directory by going into Settings -> Destination path for ‘make install’. Give the full path. Ex:
/home/USERNAME/rpi3/nfs
. Replace USERNAME with you Ubuntu system username.
Download the patch to fix compile time issue
You might see the following compile time error during compilation.
date.c:(.text.date_main+0x21c): undefined reference to `stime'
collect2: error: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Download and apply the patch to fix the above compile time error.
curl https://www.nayab.xyz/patches/0003-compile-error-fix-stime.patch --output ./0003-compile-error-fix-stime.patch
git apply 0003-compile-error-fix-stime.patch
Compile the busybox
export PATH=$PATH:~/x-tools/aarch64-rpi3-linux-gnu/bin/
make -j`nproc`
Install the minimal filesystem
make install
This will install the minimal root filesystem to the path ~/rpi3/nfs
. Verify the content with following command.
ls ~/rpi3/nfs/
The list should be similar to the following.
bin linuxrc sbin usr
In the next section, we will make the Linux kernel mount the root file system over network.