here, we just use the current vmlinuz and initrd.img, if you want to build your own linux kernel and filesystem, please compile the linux kernel yourself to generate a new vmlinuz(bzImage) and make your own filesystem with busybox. if you want to know more about how to compile the linux kernel, and build the mini filesystem with busybox, please refer to the references[3,4].
1.3 configure the isolinux boot loader
check the size of initrd.img, the size is 7.0M, the 8M(8192kb) is engogh for it.
the iso file will be stored in target as target/minios.iso
2. boot the iso file on an VM(virtual machine)
before burning the ISO file to a cd-rom, you can check it via booting on an VM. here will introduce two open source VMs, one is Virtualbox[5], another is Qemu[6].
the steps for using them are the same, at first, An system image file should be created, and then a specific device should be indicated to boot this system,such as a cd-rom, floppy, of course, a virtual device is also supported, for example, a floppy image file or an ISO image file.
2.1 use Virtualbox
install virtualbox
$ apt-get install virtualbox-ose
add the current user to the group vboxusers
$ adduser $USER vboxusers
insert the relative modules to kernel
$ /etc/init.d/vboxdrv start
start virtualbox, follow the prompt, and boot a system from the iso file
$ virtulbox
if this not work, please reboot your system to make sure the user have been added to the vboxusers group.
2.2 use Qemu
if we want to use qemu, it should be installed firstly
$ apt-get install qemu
now, we can boot the iso file
$ qemu -m 128M -cdrom minios.iso -boot d -no-kqemu
if you want to boot a floppy image file, how?
$ qemu -m 64 -boot a -fda boot.img -no-kqemu
in virtualbox, booting a floppy image file is like booting an ISO file.
that is all, is it useful? yes, of course, you will have no need to reboot your system like before, and test the embedded system on current host system. what's more? if you are writing your own bootloader, you just need to create a flopy image[7], and test it via booting it on these VMs.
if you want to speed up the qemu, please install kqemu, the basic steps are:
now, there is no need to use the -no-kqemu option when using qemu and the running speed of qemu will be accelerated.
3. build the network between VMs and the HOST system/Internet
there are several methods to built network between VMs and HOST system, such as through NAT, Router and Bridge. here will just introduce the method with Bridge for this is available to Virtualbox and Qemu.
3.1 install the basic tools
for controlling the virtual network device(TUN/TAP), we should install uml-utilities, for controlling the bridge device, we should install bridge-utils.
$ apt-get install uml-utilities bridge-utils
3.2 configure the network on HOST system
here are two scripts for starting and stoping the network configuration on HOST OS.
$ cat vmnet_up.sh #!/bin/bash
USER="$USER" IP="Please Configure An IPaddress to you HOST system Here" GW="Please Set the Default GateWay Address Here"
#IP="Please Configure An IPaddress to you HOST system Here" #GW="Please Set the Default GateWay Address Here"
ifconfig tap1 down tunctl -d tap1 ifconfig br0 down brctl delbr br0 # for static configuration # ifconfig eth0 $IP netmask 255.255.255.0 # route add default gw $GW # for dynamica configuration dhclient
if we want to start the network configuration on HOST system, please set the necessary variables(i.e user,ipaddress,default gateway) and issue the following command.
$ sudo vmnet_up.sh
correspondingly, you can stop it via vmnet_down.sh
3.3 configure it on VMs
for using Bridge method to build the network, we should also configure the VMs themselves to support the relative device.
3.3.1 Virtualbox
After starting Virtualbox, you can select one of the existing VM and then press the "Setting" button to do some configurations, afterward, choose the "Network" menu on the left side, and then, you will find the following inforamtion.
Enable Network Adapter
Cable Connected
choose the above two options, and then set the "Attached to" as "HOST Interface", set the "interface name" as "tap1".
3.3.2 Qemu
if you want to enable the bridge method in Qemu, just start it with the additional options:
-net tap,vlan=0,ifname=tap1
4. debug Linux kernel via VMs
it's very simple to debug Linux Kernel via Qemu[9], of course, we can debug it via Virtualbox[8], here just give a demo about how to debug it via Qemu. the detail steps are:
4.1 compile linux kernel with -g option
for debugging Linux kernel, we should compile it using gcc with the -g option, simply, we can check it whether there is a line in the linux-/Makefile like this:
CFLAGS += -g
after compiling Linux Kernel, a compressed linux kernel image file will be stored as linux-/arch//boot/bzImage,the original one will be stored as linux-/vmlinux.
4.2 boot linux kernel with Qemu
if you never create a virtual disk image file before, please create one like this:
$ qemu-create linux.img 1G
and then boot the kernel using qemu with the -S option.
after qemu is running, a black screen will appear which is the interface of the linux system, please switch it to the qemu command line via typing the following command to start the gdb server:
$ gdbserver 1234
afterward, you can start a new terminal on your HOST system and execute gdb to debug the linux kernel.
as the above steps we have doen, we find that it's very convenient to develop OS on VMs, here we just introduce how to develop the existing os(linux kernel) on an indicated cpu architecture.
what's more? we can develop our own os and even just a boot loader for different cpu architectures on VMs, because some VMs can emulate different cpu architectures and peripherals, Qemu is one of such VMs.
if you want to know more about VMs, you can access this link[10].
play with VMs perhaps is the best choice for a poor but aspirant student because of most of them are open source, free and powerful.