So it's been a very long time since I blogged, and I thought I should write another post. Since my last post I've finished my PhD and I'm now working as a software engineer working on embedded linux systems. I've learnt a lot during my time working as a software engineer, and I've found some of the things I've been googling are quite obscure, and some of the tutorials are a little out of date.
One task that I was given was to create an operating system using the buildroot tool, and run it virtually using qemu. If you've found your way here from Google you probably know about these tools, briefly, buildroot is a set of Makefiles which allows you to compile Linux for specific target architectures and add in a number of packages depending on your needs. Qemu is an open source virtualisation tool similar to virtualbox.
By the way, I'm assuming you're using a linux operating system to do this. I used Ubuntu 10.04 to do this.
iface eth0 inet dhcp
One task that I was given was to create an operating system using the buildroot tool, and run it virtually using qemu. If you've found your way here from Google you probably know about these tools, briefly, buildroot is a set of Makefiles which allows you to compile Linux for specific target architectures and add in a number of packages depending on your needs. Qemu is an open source virtualisation tool similar to virtualbox.
By the way, I'm assuming you're using a linux operating system to do this. I used Ubuntu 10.04 to do this.
Setting up Buildroot
- Download buildroot from here and type tar xf buildroot-2013.02.tar.gz
- Change into the buildroot directory and type make menuconfig. You will see a blue screen with lots of configuration options.
- Set target architecture to i386, and target architecture variant to i686.
- I used linux 2.6.37.2 for my version, I got this to work but I see no reason why leaving the default configuration wouldn't work, however to follow my exact steps go into toolchain and set kernel headers to manually specified, then enter 2.6.37.2 in the linux version section.
- Next go into system configuration and set Port to run a getty (login prompt) on to /dev/ttyS0, and then set the baud rate to 38400.
- Go into Filesystem images and select an ext2 filesystem. I also used an iso image, but I think you need to build a kernel first before you can select an iso image.
- Go into the Kernel menu, and select Linux kernel, select "custom tarball" for kernel version, then set the kernel url to http://ftp.lug.ro/kernel/linux/kernel/v2.6/linux-2.6.37.2.tar.gz, also select "Install kernel to /boot in target".
- Still inside the Kernel menu set Defconfig name to "i386"
- Now exit and save your configuration, then type make. This will build a filesystem and kernel and will take a while (~30 minutes).
- When the compiler has finished type make linux-menuconfig and go to File systems, then select "Second extended fs support" (press space twice).
- Exit linux-menuconfig and save the changes.
- Now type make menuconfig. Go to Kernel configuration, and select "using a custom config file", then set the "Configuration file path" to "output/build/linux-2.6.37.2/.config".
- Now exit and save the changes.
- Type make and your new file system will build.
Now you have a linux operating system! You probably want to be able to connect to it when it's running.
Setting up Netwoking
- To set up networking on the new system first add a couple more packages in buildroot.
- Go to Package selection, and select show packages provided by busybox.
- Go through and select dhcp and openssh, also select thttpd if you want.
- Change to the directory with rootfs.ext2 and bzImage in it.
- Type mkdir mnt.
- Now run sudo mount -o loop rootfs.ext2 mnt/
- Then cd mnt/etc/network and add the following lines to interfaces:
iface eth0 inet dhcp
- Now type sudo umount mnt
Now you're completely finished with buildroot, now to get it running using qemu.
Setting up Qemu
- DO NOT install qemu using apt-get on the Ubuntu. I had problems with this.
- I installed qemu using git, as follows:
git clone git://git.qemu-project.org/qemu.git
git submodule update --init pixman
- Then the usual configure, make, sudo make install builds qemu (this can take a good few minutes too!).
- You might need to do sudo apt-get install libglib2.0-dev if the configure stage complains about missing glib2-12.
Running as a VM
- Now you can run the buildroot image as a VM using qemu.
- Change to the directory containing bzImage and rootfs.ext2.
- Run this command: qemu-system-i386 -kernel bzImage -hda rootfs.ext2 -boot c -m 128M -append "root=/dev/sda rw console=ttyS0,38400n8" -nographic -net nic -net user -redir tcp:2222::22 -redir tcp:3333::33 -no-reboot -localtime
- You should see the buildroot login prompt, log in as root.
- Type adduser <yourname> and enter password details.
- Open up a terminal and type ssh -p 2222 <yourname><at>localhost and you can connect to the VM.
- You can also set up thttpd to host content on port 33 on the VM and access content in your browser by navigating to localhost:3333.
That's it, you're done. You now have a working linux operating system that is running virtually on your machine. You can SSH in to it, and it also has internet access, (ping will probably fail because apparently qemu doesn't like ICMP, but you should be able to wget to test your connection). I hope this helps out whoever is reading, it took me a long time to figure out how to do all this.
If you get into any problems going through this then please leave a comment and I'll try to see if I can help.



