Building Tiny Linux Systems with Busybox, Part 2: Building the Kernel
Creating a ROM Root File System
We're going to go through all of the steps for creating a minimal root file system by hand so that you will understand just how little is necessary to boot your system rather than copying all of the files from the root of your Linux distribution and then being afraid to remove anything because you don't know whether it's necessary. You will need to become root (the superuser) to perform the following steps because the mknod command requires superuser privilege.
Create the tiny-linux directory and change directory into it:
mkdir tiny-linux cd tiny-linux
Create the standard directories in it:
mkdir dev etc etc/init.d bin proc mnt tmp var var/shm chmod 755 . dev etc etc/init.d bin proc mnt tmp var var/shm
Enter the tiny-linux/dev directory:
cd dev
Create the generic terminal devices:
mknod tty c 5 0 mknod console c 5 1 chmod 666 tty console #Allow anyone to open and write terminals.
Create the virtual terminal device for the VGA display:
mknod tty0 c 4 0 chmod 666 tty0
Create the RAM disk device:
mknod ram0 b 1 0 chmod 600 ram0
Create the null device, used to discard unwanted output:
mknod null c 1 3 chmod 666 null
Change directory to tiny-linux/etc/init.d, where startup scripts are stored:
cd ../etc/init.d
Use an editor to create this shell script in tiny-linux/etc/init.d/rcS. It will be executed when the system boots:
#! /bin/sh mount -a # Mount the default file systems mentioned in /etc/fstab.
Make the script executable:
chmod 744 rcS
Change directory to tiny-linux/etc:
cd ..
Use an editor to create the file tiny-linux/etc/fstab, which says what file systems should be mounted at boot time:
proc /proc proc defaults 0 0 none /var/shm shm defaults 0 0
Set the mode of tiny-linx/etc/fstab:
chmod 644 fstab
Use an editor to create the file tiny-linux/etc/inittab, which tells /bin/init, the system startup program, what processes to start:
::sysinit:/etc/init.d/rcS ::askfirst:/bin/sh
The above example runs the script /etc/init.d/rcS at boot time and runs an interactive shell on the console device.
Set the modes of tiny-linux/etc/inittab:
chmod 644 inittab
That's everything necessary to create your root file system, except for the installation of the programs. Change directory to tiny-linux/bin:
cd ../bin
Copy your static-linked version of Busybox from wherever you built it into tiny-linux/bin/busybox with a command similar to this one:
cp ~/busybox-0.46/busybox busybox
Add another command name ls to Busybox using the ln command:
ln busybox ls
Run ls, and the result should look like this:
-rwxr-xr-x 2 root root 580424 Sep 12 15:17 busybox -rwxr-xr-x 2 root root 580424 Sep 12 15:17 ls
Repeat the above ln command for all of these names:
[, ar, basename, cat, chgrp, chmod, chown, chroot, chvt, clear, cp, cut, date, dc, dd, deallocvtdf, dirname, dmesg, du, dumpkmap dutmp, echo, false, fbset, fdflush, find, free, freeramdisk, fsck.minix, grep, gunzip, gzip, halt, head, hostid, hostname, id, init, insmod, kill, killall, length, linuxrc, ln, loadacm, loadfont, loadkmap, logger, logname, lsmod, makedevs, md5sum, mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc, nslookup, ping, poweroff, printf, ps, pwd, reboot, rm, rmdir, rmmod, sed, setkeycodes, sh, sleep, sort, swapoff, swapon, syn, c syslogd, tail, tar, tee, telnet, test, touch, tri, true, tty, umount, uname, uniq, update, uptime, usleep, uudecode, uuencode, wc, which, whoami, yes, zcat
Are you tired yet? Well, now is a good time to take a break--you've finished creating your ROM root file system.