# Busybox: build minimal file system
###### tags: `linux` `env-setup` `Linux Kernel` `busybox`
Host: Linux Ubuntu-20.04
Target Platform: vexpress (arm cortex-a9), linux kernel-5.10.1
busybox: busybox-1.32.0
## Prev step
[Clone Linux Kernel Source](https://hackmd.io/WWkyemFBRWm-MyVHifvDVA)
## Setup
Download busybox:
https://busybox.net/downloads
or
```
wget https://busybox.net/downloads/busybox-1.37.0.tar.bz
wget https://busybox.net/downloads/busybox-1.32.0.tar.bz2
```
unzip
```
tar -jxvf busybox-1.37.0.tar.bz2
```
goto:
```
cd busybox-1.37.0
```
```
export ARCH=arm
```
```
export CROSS_COMPILE=arm-linux-gnueabi-
```
```
make menuconfig
```
config setting :
```
Settings --->
Build Options --->
[*] Build static binary (no shared libs)
```
Build:
```
make install
```
If you see this build error:
```
CC libbb/hash_md5_sha.o
libbb/hash_md5_sha.c: In function ‘sha1_end’:
libbb/hash_md5_sha.c:1316:35: error: ‘sha1_process_block64_shaNI’ undeclared (first use in this function); did you mean ‘sha1_process_block64’?
1316 | || ctx->process_block == sha1_process_block64_shaNI
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
| sha1_process_block64
libbb/hash_md5_sha.c:1316:35: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [scripts/Makefile.build:198: libbb/hash_md5_sha.o] Error 1
make: *** [Makefile:744: libbb] Error 2
```
Try:
```
make menuconfig
```
disable
```
Settings --->
[ ] SHA1: Use hardware accelerated instructions if possible
[ ] SHA256: Use hardware accelerated instructions if possible
```

Rebuild
```
make clean && make install
```
It will create a folder called '_install' under the busybox root folder.
Copy the folder '_install' to 'linux-5.10.1'
```
cd linux-5.10.1/_install
mkdir etc
mkdir dev
mkdir mnt
mkdir -p etc/init.d
cd etc/init.d
vim rcS
```
Copy the following context to rcS:
```
#!/bin/sh
mkdir –p /proc
mkdir –p /tmp
mkdir -p /sys
mkdir –p /mnt
/bin/mount -a
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev –s
```
Add Permision:
```
chmod 777 rcS
```
=============================================
Create a file 'fstab' under "linux-5.10.1/_install/etc", go to "linux-5.10.1/_install/etc"
```
cd ..
```
and use vim or any kind of editor to open it:
```
vim fstab
```
Copy following context to fstab:
```
proc /proc proc defaults 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /dev tmpfs defaults 0 0
debugfs /sys/kernel/debug debugfs defaults 0 0
```
=============================================
Create a file 'inittab' under "linux-5.10.1/_install/etc", go to "linux-5.10.1/_install/etc" and use vim or any kind of editor to open it:
```
vim inittab
```
Copy following context to inittab:
```
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::askfirst:-/bin/sh
::ctrlaltdel:/bin/umount -a –r
```
Go to linux-5.10.1/_install/dev
cd ../dev/
sudo mknod console c 5 1
sudo mknod null c 1 3
## Trouble shooting
1./bin/sh: 1: flex: not found
```
sudo apt install flex
```
2./bin/sh: 1: bison: not found
```
sudo apt install bison
```
## Next Step
[Build Linux Kernel](https://hackmd.io/VL0CysI4TXG_ahNq-SSRFg)