Monday, April 25, 2011

Bochs(2.4.6): A cross platform IA-32 Emulator HOWTO

Hello Everyone,

Few days back I installed Bochs from source code, I needed it start my work on Pintos (I will write about this in future posts), it was fun doing it. Bochs is free open source project hosted on sourceforge, so you can download it for free and use it and also make changes to the source and send in your patches and post questions on there mailing list, I must say its one of the active mailing list.

Bochs is a portable x86 and x86-64 IBM PC compatible emulator and a debugger mostly written in C++ and distributed as free software under GNU. So what it means is that it provides an environment similar to the pc but with in the OS (hope I am not confusing), thus providing virtualization similar to another popular open source project Qemu. These emulator's by there name emulate the physical hardware for the OS to run on, they go to an extent of providing a pseudo environment where the OS thinks that it is running on the bare metal hardware but it will be one more process in the user's process list which the user can kill, restart and do what ever he wants with it. So these emulator's are commonly used by
  • OS kernel developers because they have to just start a new process when the kernel crashes rather than restarting the system.
  • Most of them use it to try out new OS distributions, mainly to run apps which are not available on there base OS. So a user using a LINUX machine can run window's within his/her machine.
 Bochs is capable of emulating
  • Harddrives
  • CD Drives
  • Floppy drives
Unlike  Qemu (which uses KVM), Bochs doesnot provide any cpu virtualization thus one can find that it is much slower to run.

In this post I will be demonstrating the installation of Bocs(2.4.6) from the sourcecode on Ubuntu (if you haven't tried it yet, go grab an Installation CD, it's worth a try). Before we do that, Bochs requires few packages to be pre-installed. So, follow to steps to install Bochs(2.4.6):
  1. Since it is written in C++, it requires a c++ compiler, so run
    sudo apt-get install build-essential
  2. The following packages are required to enable X-window's gui used by Bochs to provide a terminal when we run our OS.
    sudo apt-get install libx11-dev
    sudo apt-get install xserver-xorg-dev
    sudo apt-get install xorg-dev
  3. Ncurses  library, it provides API's, that allows the programmers to write text in a terminal (follow the wiki link http://en.wikipedia.org/wiki/Ncurses for more info).
    sudo apt-get install libncurses5-dev
  4. Flex is a free software alternative to lex
    sudo apt-get intall flex
  5. Lastly, GTK library to enable the internal debugger (use --enable-debugger option while running configure).
    apt-get install libgtk2.0-dev
    apt-get install libgtk2.0-0-dbg

Once these packages are installed, we are just few steps.
  • Download the gipped package and unzip it using
    tar xf bochs-2.4.6.tar.gz
  • cd into the un-tarred directory and run configure (follow the link to see more compiling options). I used
    ./configure --enable-gdb-stub --with-x --with-x11 --with-term --with-nogui --prefix installation-path
    to install the simple bochs and
    ./configure --enable-debugger --enable-disasm --with-x --with-x11 --with-term --with-nogui --prefix installation-path
    to install the Bochs with internal debugger enabled. Use prefix to give different names to two different binaries.

  • Now run
    make && make install
That's it. Now start using it :)

2 comments:

  1. Hello,
    The Article on Bochs(2.4.6)which is a cross platform IA-32 Emulator is amazing.It give brief information about it ,Thanks for Sharing the information about it.Xamarin Apps Development

    ReplyDelete