Creating basic image with Buildroot

Based on OSMZ presentation 31.3.2009, Michal Krumnikl

Buildroot is a set of Makefiles and patches that makes it easy to generate a cross-compilation toolchain and root filesystem for your target Linux system using the uClibc C library. Buildroot is useful mainly for people working with small or embedded systems. Embedded systems often use processors that are not the regular x86 processors everyone is used to using on their PC. It can be PowerPC processors, MIPS processors, ARM processors, etc. And to be extra safe, you do not need to be root to build or run Buildroot.

Using buildroot step-by-step instructions

Following procedure was tested on Fedora 10
Linux nemesis #1 SMP Mon Mar 23 23:08:10 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7),

1) Download

2) Unzip the archive using    tar -xzf buildroot-2009.02.tar.gz

3) run make menuconfig

make menuconfig

4) Choose at least these options :
5) make uclibc-menuconfig


6) run make  (it will download approximatelly 340 MB)

make will fail with the following line :
/build_i686/staging_dir/usr/include/xorg/miscstruct.h:54:20: error: pixman.h: No such file or directory

cd ./build_i686/staging_dir/usr/include
 ln -sf pixman-1/* .
cd -

Final build should finish like this :

-rw-rw-r-- 1 michal michal 58580992 2009-04-05 23:03 /mnt/build/binaries/uclibc/rootfs.i686.ext2
rm -f /mnt/build/project_build_i686/uclibc/.fakeroot*

Creating a disk image for QEMU

1) Create an empty file for disk image,  dd if=/dev/zero of=myimage bs=512 count=$((64*1024*1024/512))
Block size will be 512B, we need 64MB = 64*1024*1024, the number of 512B blocks will be 64MB/512.

2) Make a block device from the image file using losetup. losetup is used to associate loop devices with regular files or block devices, to detach loop devices and to query the status of a loop device. In Unix like operating systems, a loop device is a  pseudo-device that makes a file accessible as a block device. Lets create a loop device from the image.  losetup /dev/loop0 myimage

3) Create a partition layout using fdisk. fdisk is a commonly used name for a command-line utility that provides disk partitioning functions in an OS. fdisk /dev/loop0
Create a primary partition with maximum size.

4) Mount primary partition to filesystem, this way you can copy files created by buildroot to your image.
First created a loop device representating the partition. Partition is beginning on the first cylinder (check fdisk -ul /dev/loop0, and find begining block). Calculate the offset of the partition from the beginning of the device (starting block * block size, 63 * 512 = 32256B). Now you can create second loop device pointing on the partition ( losetup -o 32256 /dev/loop1 /dev/loop0 ).
For more information concerning harddisk and its geometry have a look at

5) Create an EXT2 (or EXT3) filesystem on the partition. mkfs (make a filesystem) is the standard Unix command for formatting a disk partition. Using mkfs.ext2 -m0 /dev/loop1 will create an EXT2 filesystem with 0% reserved space for root (by default 5% is reserved, but this was overriden by the -m parameter).

6) Mount your newly created filesystem to your system directory structer mount -a /dev/loop1 /mnt/somewhere. Now you should be able to write data on your 64M filesystem. Check df for free space.

/dev/loop1               63429     45750     17679  73% /mnt/somewhere

7) Copy files from /buildroot-2009.02/project_build_i686/uclibc/root to your mount point (be sure to keep file rights and owner root)

8) Get working kernel from somewhere (you can try to compile from source (, make menuconfig, make, resulting in bzImage) or use Buildroot (it supports building kernel image and placing release file into root structure) or the easiest way - use kernel from some Live distro, such as FedoraLive, you will need vmlinuz0 and initrd0))

9) Prepare boot loader, we will use GNU GRUB ("GRUB" for short) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Multiboot Specification, which allows a user to have several different operating systems on their computer at once, and to choose which one to run when the computer starts.

10) Create GRUB configuration file in your filesystem ( /mnt/somewhere/boot/grub/grub.conf ). Add following lines (these are referring to kernel taken from Fedora Live)

root (hd0,0)
kernel /boot/vmlinuz0 rw root=/dev/sda1
initrd /boot/initrd0.img

11)  Now we should be able to boot the image from QEMU -  qemu -snapshot -hdd myimage -boot c


and terminal :

You have 17MB for your project ...