Build a Root Filesystem for a Raspberry Pi 3 Model B+
Introduction
This is the sixth post in a series of posts (in a tutorial) about building an embedded Linux system for a Raspberry Pi 3 Model B+. A summary post for the tutorial can be found here. The summary post also talks about …
- what is required to follow along,
- the
<project/root/dir>, - some terms that will be used throughout the series,
- a link to an article that explains how to prepare the SD card,
- some hints on how to use the UART interface of the Raspberry Pi.
The fourth and final piece of the puzzle of building an embedded Linux system is the root filesystem. Let’s build that part now.
Build a Root Filesystem with Busybox
There are many way to build a Root Filesystem for Linux. I decided to use Busybox [1]. The following steps show how to do it.
First of all let’s create a directory that will hold a copy of the root filesystem on the host machine:
cd <project/root/dir>
mkdir rootfs
Now we need the source code of busybox. In the <project/root/dir>, run:
git clone git://busybox.net/busybox.git
cd busybox
git checkout 1_36_1
After checking out the tag 1_36_1, I was on commit 1a64f6a2 of the busybox
repository.
To build the root filesystem, we need the toolchain that was built before.
Therefore we have to prepend our PATH. In case you followed my description
in Building a (Cross) Toolchain,
you just have to adjust <project/root/dir> in the following command.
Otherwise you might have to adjust more. To prepend the PATH, run:
PATH=<project/root/dir>/x-tools/aarch64-rpi3-linux-gnu/bin/:$PATH
Additionally we need to set two environment variable:
export CROSS_COMPILE=aarch64-rpi3-linux-gnu-
export ARCH=arm64
Now we can start building the root filesystem.
Note: The following command will delete a file called .config in your current working directory. In case you have been working on a configuration for a root filesystem before, you might want to save this .config file for later use. For good measure, you should run:
make distclean
Then set the default configuration for Busybox:
make defconfig
make menuconfig didn’t work on my machine, due to some package dependency
problems. At the time of writing this post, I didn’t want to bother with it,
and instead of using make menuconfig to adjust some parts of the
configuration, I opened the file .config in an editor and chanaged the
following lines manually:
In the line starting with CONFIG_CROSS_COMPILER_PREFIX, I added the content
of the CROSS_COMPILE environment variable:
CONFIG_CROSS_COMPILER_PREFIX="aarch64-rpi3-linux-gnu-"
In the line starting with CONFIG_PREFIX I changed the path to the path of the
newly created rootfs directory:
CONFIG_PREFIX="../rootfs"
This changes the directory into which the root filesystem will be installed.
To link the executable of busybox statically, I changed the line that read like this:
# CONFIG_STATIC is not set
to
CONFIG_STATIC=y
To actually build and install the root filesystem into the ´rootfs` directory, run:
make
make install
If you followed along this tutorial (including the previous posts) and run
tree -L 2 in your <project/root/dir>, you should see the following:
$> cd <project/root/dir>
$> tree -L 2
.
├── busybox
│ ├── ... (output shorened)
├── crosstool-ng
│ ├── bin
│ ├── ... (output shortened)
├── linux
│ ├── ... (output shorened)
├── rootfs
│ ├── bin
│ ├── sbin
│ ├── usr
│ └── linuxrc -> bin/busybox
├── rpi
│ └── firmware-master
├── u-boot
│ ├── ... (output shortened)
│ ├── u-boot.bin
│ ├── ... (output shortened)
└── x-tools
└── aarch64-rpi3-linux-gnu
For how to use the root filesystem, see the post Run a Root Filesystem for a Raspberry Pi 3 Model B+.
Take care,
Andreas
References
- Erik Andersen, “Busybox.” [Online]. Available at: https://www.busybox.net/. [Accessed: 31-Jan-2025].
Leave a comment