Creating a minimal Linux with Busybox
Saturday, October 21st, 2006I’m working from a regular Debian Sarge, but the following operations should work with pretty much any distribution.
In order to create a bootable Linux system you need two things :
- A kernel to boot on
- A minimal filesystem (aka a root disk)
We’re going to create those in a few steps :
Compiling the kernel
We’ll start by building a very simple, vanillia kernel :
wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.1.tar.bz2
tar xjf linux-2.6.18.1.tar.bz2
cd linux-2.6.18.1
make menuconfig
at this point, just exit and save the default configuration. Start the compilation (this can take a while) :
make
Preparing the root disk :
Then we have to prepare the virtual disk, mount it and prepare its skeleton structure. 10 MB will be way enough.
dd if=/dev/zero of=/tmp/fsfile bs=1k count=10000
/sbin/mkfs.ext2 -F /tmp/fsfile
mkdir /tmp/fsfile.mount
sudo mount -o loop -t ext2 /tmp/fsfile /tmp/fsfile.mount
cd /tmp/fsfile.mount
mkdir proc bin sbin tmp mnt etc etc/init.d etc/mtab usr usr/bin devcd dev
cd dev
sudo mknod console c 5 1
sudo mknod tty1 c 4 1
sudo mknod tty2 c 4 2
sudo mknod tty3 c 4 3
sudo mknod tty4 c 4 4
sudo mknod tty5 c 4 5
cd ..
chmod 1777 tmp/
Preparing busybox :
wget http://www.busybox.net/downloads/busybox-1.2.1.tar.gz
tar xzvf busybox-1.2.1.tar.gz
cd busybox-1.2.1
make
You need to configure 3 specific items there :
- Busybox Settings / General Configuration / “Support –install” to YES
- Busybox Settings / Build Options / “Build BusyBox as a static binary” to YES
- Init Utilities / init to YES
- Shells / ash to YES
Save your configuration and redo :
make
Installing busybox :
cp busybox /tmp/fsfile.mount/bin/
cd /tmp/fsfile.mount
sudo mount -t proc proc proc
sudo chroot . /bin/busybox –install -s
sudo umount proc
cd ..
sudo umount /tmp/fsfile.mount
Testing with qemu :
Go back to the directory linux-2.6.18.1 where we built the kernel
qemu -hda /tmp/fsfile -kernel arch/i386/boot/bzImage -append “root=/dev/hda”
Conclusion :
Obviously with so few efforts a few things are missing :
- The kernel is a stand-alone file, it’s not integrated in the ext2 image
- The kernel is rather heavy-weight
- Not many commands are installed (/sbin/poweroff is not really all that interesting alone
)
That will be the topic of next posts.