Saturday, January 3, 2009

Linux bootable disk image using EXTLINUX, buildroot

Steps to create a root filesystem using buildroot and run Linux kernel using QEMU
  • Download buildroot
$ git clone git://git.buildroot.net/buildroot
  • Update buildroot
$ cd buildroot
$ git pull
  • Change configuration to build for i386
$ make menuconfig
  • Build buildroot
$ make
  • Run in QEMU
$ qemu -kernel /boot/vmlinuz -initrd /boot/initrd.img -hda binaries/uclibc/rootfs.i386.ext2 -append "root=/dev/sda rw" -m 1024

Steps to create a bootable disk image using EXTLINUX, buildroot, Linux kernel and run using QEMU
  • Mount buildroot root filesystem
$ sudo mount binaries/uclibc/rootfs.i386.ext2 buildrootfs -o loop -t ext2
  • Create disk image
$ dd if=/dev/zero of=rootfs.img bs=1M count=10
  • Create 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
  • Copy buildroot to disk image
$ rsync -a buildrootfs/ rootfs
  • Create boot directory
$ mkdir rootfs/boot
  • Copy Linux kernel and initial ramdisk to boot directory
$ cp vmlinuz rootfs/boot
$ cp initrd.img rootfs/boot
  • Install EXTLINUX bootloader
$ extlinux --install rootfs/boot
$ vi rootfs/boot/extlinux.conf
default linux
timeout 10
prompt 1

label linux
kernel /boot/vmlinuz
append initrd=/boot/initrd.img root=/dev/sda clocksource=kvm-clock
  • Unmount disk image
$ sudo umount rootfs
  • Run in QEMU
$ qemu -hda rootfs.img -m 1024

1 comment: