In this post we are going to build a root file system from scratch using Busybox and test it on QEMU.
Download the latest version of BusyBox (1.20.2 for the time being)
Extract the file and get into directory
$ cd busybox-1.20.2
Let’s use the default configuration and modify it according to our needs.
$ make ARCH=arm CROSS_COMPILE=arm-linux- defconfig
$ make ARCH=arm CROSS_COMPILE=arm-linux- menuconfig
Go to “BusyBox Settings –> Build Options” and enable the option “Build BusyBox as a static binary (no shared libs)
Under the same menu you go to “Open the menu “Installation Options (make install behavior) –> (./_install) BusyBox installation prefix
This option means that the root file system will be installed inside _install directory. You can change it if you like. Let’s leave it as it is.
Start building our root file system.
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
If the compilation ends successfully the root file system will be in _install directory.
$ cd _install
It seems that some of the directories that we are accustomed to see in a normal Linux distro are missing. We will create them manually.
$ mkdir proc sys dev etc etc/init.d
$ cd ..
We will now create a bash script in order to mount some devices automatically after the boot.
$ touch etc/init.d/rcS
Modify its content as
mount -t proc none /proc
mount -t sysfs none /sys
Now change the file’s mode as executable.
$ chmod +x etc/init.d/rcS
Then create an image of the root file system and compress it.
$ find . | cpio -o –format=newc > ../rootfs.img
$ cd ..
$ gzip –c rootfs.img > rootfs.img.gz
We had created a kernel image in the previous examples. You can copy the kernel image to BusyBox directory. We can try our fresh root file system on QEMU
$ qemu-system-arm -M versatilepb -m 128M -kernel zImage -initrd rootfs.img.gz -append “root=/dev/ram rdinit=/sbin/init”
QEMU will boot the kernel and load the root file system. Just press “ENTER” to see shell prompt.