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 :)

Wednesday, April 20, 2011

Scrolling up and down the Terminal

I will be posting some of the interesting and useful tips to ease the use of command line in Linux. Today's tip is HOWTO scroll through the terminal page up and down. To scroll through the terminal use

           cntrl + shift + [up arrow | down arrow] [page up | page down]

Tuesday, April 19, 2011

Passwordless SSH login HOWTO

Hello Folks,

Its been a long time since my last post, but now I would try to be more consistent. In this post I am going to explain the step's to setup "Passwordless SSH" to a remote machine.

Quite often we feel the need to login to a remote machine (maybe to backup our daily work or to run few test's..) what ever maybe the reason, we endup entering the password of that machine. Today we will learn howto setup a "Passwordless SSH" to a remote machine.

Before we begin, there are few prerequisites that are needed to successfully perform the task at hand. The remote machine should have sshd (ssh server) installed on it. If not install it using the command

     > sudo apt-get install openssh-server

The above command works only on Ubuntu, on other OS's like fedora use "yum install" etc.

Now a days most of the OS's have openssh-client installed on them by default, if not present install it. This is to be present on the machine from which you are going to ssh to the remote machine.

Once these are done, follow the step's below to successfully perform passwordless ssh login.

1. Enter the command

     >ssh-keygen -t rsa
       Generating public/private rsa key pair.
       Enter file in which to save the key (/user/.ssh/id_rsa):
       Enter passphrase (empty for no passphrase):
       Enter same passphrase again:
       Your identification has been saved in /user/.ssh/id_rsa.
       Your public key has been saved in /user/.ssh/id_rsa.pub.
       The key fingerprint is:
       e2:8e:8a:91:f2:db:06:77:22:29:27:e0:4f:7a:3b:71 user@user-laptop
       The key's randomart image is:
       +--[ RSA 2048]----+
        |                           |
        |                           |
        |                           |
        |.                          |
        |o  .  . S                |
        |oo=ooE..            |
        |++++oo.            |
        |.= =.o                 |
        |. === .               |
       +--------------------------+

For more info on ssh-keygen go through its man page.

When it asks for the file just press enter and when it asks for the passphrase enter the passphrase else just press enter.

Now it would have generated two files id_rsa and id_rsa.pub in /user/.ssh directory. The id_rsa file is the private key which you must never disclose it to anyone.

2. Now copy the public key to the remoter machine. One of my favorite ssh command variant for this is

    > ssh-copy-id -i /user/.ssh/id_rsa.pub remote-user@remote-machine

That's it, now you can login into the remote machine without entering the password.


One of the common problem that we face while using ssh to login to the remote machine may be

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
af:b6:ab:a9:c5:5e:ab:bb:b8:1c:1c:d6:82:0c:ce:9b.
Please contact your system administrator.
Add correct host key in /user/.ssh/known_hosts to get rid of this message.
Offending key in /user/.ssh/known_hosts:34
RSA host key for remote-machine-ip has changed and you have requested strict checking.
Host key verification failed.


If you face this problem, then just delete the file /user/.ssh/known_hosts and you are good to go.