Building Tiny Linux Systems with Busybox, Part 2: Building the Kernel
For this example I use Linux kernel version 2.2.17. The 2.4.0-test8 kernel that I tried did not size the RAM disk for the root file system properly, leading to a ``not enough memory'' message at boot time. That bug will probably be repaired in the 2.4 series of kernels by the time you read this.
We will build our example to run on an i386-architecture PC-compatible system with PC keyboard and VGA display, booting from a floppy disk and running the root file system entirely in RAM once the system is booted. This example should also boot from IDE disks and from FLASH EEPROM devices that masquerade as IDE disks. It can also be configured to boot from a CD-ROM.
Build a bzImage-style kernel with all of the facilities needed for the application, plus these three:
RAM disk support (in the Block Devices menu)
Initial RAM disk (initrd) support (also in the Block Devices menu)
ROM file system support (in the File Systems menu)
Don't use kernel modules, because this example system doesn't support them. Don't put any facilities in the kernel that you don't need, as they will use up space that you need on the floppy disk. A kernel with the facilities you need should be around half a megabyte in size and should fit easily on a floppy along with the ROM root file system. A kernel with many unnecessary bells and whistles will be a megabyte or more and won't leave sufficient room for your ROM root file system.
If you're not familiar with building and installing kernels on a normal Linux PC, you'll need to study up on that. In short, I placed the kernel sources in /usr/src/linux and ran:
xhost +localhost su make xconfig make dep make bzImage
This created a compiled Linux kernel in /usr/src/linux/arch/i386/boot/bzImage.
In the busybox source directory, edit the Makefile, changing the variable DOSTATIC from false to true. Then run make. That will create a static-linked version of busybox. Confirm that it is static-linked by running this command:
ldd busybox
This should print something like:
statically linked (ELF)It's important to get this right; if you install a dynamic-linked version of Busybox, your system won't run because we aren't installing the runtime dynamic linker and its libraries on the floppy disk for this example.
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/shmEnter the tiny-linux/dev directory:
cd devCreate 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 tty0Create the RAM disk device:
mknod ram0 b 1 0 chmod 600 ram0Create the null device, used to discard unwanted output:
mknod null c 1 3 chmod 666 nullChange directory to tiny-linux/etc/init.d, where startup scripts are stored:
cd ../etc/init.dUse 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 rcSChange 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 0Set the mode of tiny-linx/etc/fstab:
chmod 644 fstabUse 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/shThe 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 ../binCopy 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 busyboxAdd another command name ls to Busybox using the ln command:
ln busybox lsRun 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 lsRepeat 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, zcatAre you tired yet? Well, now is a good time to take a break--you've finished creating your ROM root file system.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- RSS Feeds
- Readers' Choice Awards
- Tech Tip: Really Simple HTTP Server with Python
- DynDNS
3 hours 12 min ago - Reply to comment | Linux Journal
3 hours 45 min ago - All the articles you talked
6 hours 8 min ago - All the articles you talked
6 hours 11 min ago - All the articles you talked
6 hours 13 min ago - myip
10 hours 38 min ago - Keeping track of IP address
12 hours 29 min ago - Roll your own dynamic dns
17 hours 42 min ago - Please correct the URL for Salt Stack's web site
20 hours 53 min ago - Android is Linux -- why no better inter-operation
23 hours 9 min ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
How Keyboard is working when no support provided in Linux
How Keyboard is working when no support provided in Linux ?
When i booted Linux from floppy and used the ramdisk as the rootfs, everything is working fine.
But i was wondering how the keyboard is working ? No loadable drivers provided.
Also no support in Linux provided>
I am not getting the # prompt instead i am getting the $ prompet
Hai Bruce Perens,
I have followed each and every step you told in this article but i am not getting the # prompt after booting it from the floppy. Instead i am getting the $ prompt.
How to get the # prompt can you tell me the error i am donig
Thanking you,
K.RajaSekahr
Re: Building Tiny Linux Systems with Busybox, Part 2: Building t
Luckily he provided the list of names in almost the right format for python.
An easier way to create those links to busybox:
import os
names=["ls","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", "csyslogd", "tail", "tar", "tee", "telnet", "test", "touch", "tri", "true", "tty", "umount", "uname", "uniq", "update", "uptime", "usleep", "uudecode", "uuencode", "wc", "which", "whoami", "yes", "zcat"]
for name in names:
os.system("ln busybox "+name)
Re: Building Tiny Linux Systems with Busybox, Part 2: Building t
I did this do create the links with a debian 'busybox-static'
#!/bin/sh
#
# Thorsten Strusch 2005-01-06
#
#########################################################################
#
BUSYBOX=$(which busybox)
#
Liste=$( $BUSYBOX 2>&1 | grep -A20 Currently | grep -v Curren | sed -e '{s/\t//}' -e '{s/\n//}' -e '{s/ //}' | grep -v ^$)
export IFS=','
for i in $Liste
do ln -s $BUSYBOX $i
done
unset IFS
Re: Building Tiny Linux Systems with Busybox, Part 2: Building t
Or even easier:
from the busybox build dir
$ make PREFIX=../tiny-linux install-hardlinks
Re: Building Tiny Linux Systems with Busybox, Part 2: Building t
Hi...
all went ok, kernel uncompressed, but then..kernel panic :(
kernel panic: unable to mount root fs on 01:00, what that is.. i gave my full memory, but .. nothing.. why? can u send me reply?
P.S.: best article(s).. thanx...
Re: Building Tiny Linux Systems with Busybox, Part 2: Building t
Im trying to make a mini floppy disk linux distro thing (if thats the right name) , i used a differant tutorial looks almost the same as this BUT .... i got the same boot error! that and something about VFS and "cramfs: wrong magic" so yeah. somethings up there, maybe i enabled some wrong options in the kernel and they are breaking each other.
Re: Building Tiny Linux Systems with Busybox, Part 2: Building t
did you enable ROM filesystem support in the kernel? if not you can try mkcramfs instead
ROM filesystem
I had a similar problem with romfs. In my case, I had to gzip the file system without "-9".