Sunday, January 4, 2009

Linux bootable disk image using EXTLINUX, Busybox

Steps to create a minimal root filesystem using BusyBox and run Linux kernel using QEMU
  • Download BusyBox and build with CONFIG_STATIC=y
  • Create disk image
$ dd if=/dev/zero of=rootfs.img bs=1M count=10
  • Make ext2 filesystem
$ mke2fs -j rootfs.img
$ tune2fs -c 0 -i 0 rootfs.img
  • Mount disk image
$ sudo mount rootfs.img rootfs -o loop -t ext2
  • Make boot directory
$ mkdir rootfs/boot
  • Copy busybox to disk image
$ rsync -a busybox*/_install/ rootfs
  • Create directories and files
$ cd rootfs
$ mkdir etc etc/init.d dev proc sys

$ cd etc
$ vi inittab
::sysinit:/etc/init.d/rcS
::askfirst:/bin/sh
$ chmod 644 inittab

$ cd init.d
$ vi rcS
#! /bin/sh
mount -a
$ chmod 744 rcS

$ cd ..
$ vi fstab
proc /proc proc defaults 0 0
$ chmod 644 fstab
$ cd ../..
  • Unmount disk image
$ sudo umount rootfs
  • Run in QEMU
$ qemu -hda rootfs.img -m 1024

No comments:

Post a Comment