Wednesday, December 12, 2007

Installing Ubuntu 7.04 Server on QEMU

I was able to install and run an Ubuntu 7.04 Linux (Server Edition) on a Windows XP host using QEMU. Installation was pretty straightforward, what required some extra research was getting the Linux guest OS to communicate with the host OS using TCP/IP.

Here are the steps:

Ubuntu Installation

1. Download and install QEMU for Windows

2. (Optional) Download and install KQEMU for Windows

This will greatly speed up the virtual machine running in QEMU.

3. You will also need to download the Ubuntu server .iso file.

4. Once these are ready, you can create the disk image that will be used by the virtual machine.

The command line below will create a disk image 3GB-large in the file ubuntu.img:

qemu-img.exe create ubuntu.img 3G

5. Boot the virtual machine with the Ubuntu .iso as CD-ROM drive

qemu.exe -cdrom ubuntu-7.04-server-i386.iso -boot d -m 256 -L . ubuntu.img

You should see a window with the Ubuntu installation screen.
Proceed with the installation as per normal.

After installation, you need to reboot with the disk image as boot disk. Just remove the -boot d option to do this.

qemu.exe -cdrom ubuntu-7.04-server-i386.iso -m 256 -L . ubuntu.img

Voila! A Linux box (with LAMP) right inside your Windows desktop.

Configuring the Network

There are a couple of ways to go about this, and it really depends on your network configuration (i.e., whether you use DHCP, whether you need to connect to the Internet, etc.). The steps below describe what I did in my set-up:

1. Download and install OpenVPN.

Actually you will just need the Tap-Win32 component, so you can go ahead and de-select the other components during installation.

2. After installation you will have a new "Local Area Connection" in your Network Settings folder. For convenience later, I suggest you rename this to something like tap0.

This interface will be used to connect to the guest OS. You can assign it an IP address, e.g. 192.168.1.1.

3. Boot the guest OS, but this time add the ff. parameters: -net nic -net tap,ifname=tap0

This will give the virtual machine a network interface, and connect that network interface to the host's tap0 interface.

4. After the Ubuntu server has booted, it should have an eth0 interface. You can assign an IP address to this using ifconfig.

$ ifconfig eth0 192.168.1.2

That's it. Your host OS and guest OS should have network connectivity! Try to ping each other. Your network should look like this:

192.168.1.2(eth0, linux) <----> 192.168.1.1(tap0, windows)

If you want to connect the linux box to the Internet then you can use the bridging function of Windows. I also suggest turning on the Samba server of the linux box so that transferring files between OSes will be very convenient.

Happy emulating!

Tuesday, December 4, 2007

vi plug-in for Eclipse

During the past few years, I've gotten so used to using vi that my fingers have memorized some of the key bindings. Now that I'm using the Eclipse as IDE, I'm having withdrawal symptoms... like constantly typing :wq to save current file, or '/' to perform a search. It's just so convenient to not have to lift my hand over to the mouse to do some common editing tasks.

Much as I love the convenience, though, I'm not willing to give up the powerful Java & C/C++ editing features of Eclipse: outline view, type hierarchy, continuous build, among many others. Given this dilemma, what is a developer to do?

Thankfully, Eclipse is an extensible IDE/platform and creating plug-ins has never been easier.
So I did the next best thing: I tried to create my own plug-in that emulates vi inside the Eclipse IDE (specifically, inside the text editors).

So, let me introduce to my own (pre-alpha) version of the Eclipse vi plug-in.

Here's how to install it:
  1. Inside Eclipse, go to Help->Software Updates->Find and Install...->Search for new features to install
  2. Click the New Remote Site button. Enter the information below when prompted:
    • Name: Eclipse vi plug-in (or whatever suits you)
    • URL: http://eclipseviplugin.sourceforge.net/update/0.x/
  3. Click Finish. Eclipse will try to download the plug-in from the above site.
  4. Once the download is finished, you will be asked to select the features to install. Just select All then hit Next.
  5. Accept the license... blah blah blah.
  6. Next. Then Finish. You will be prompted to restart Eclipse shortly afterwards. Please do.
  7. After restarting, try opening a text, Java, or C/C++ file.
  8. Press Ctrl+4 (my temporary equivalent of vi's ) inside the editor to go into vi command mode
  9. From command mode, you can press i (insert), a (append), or o (insert line) to go back to edit mode. Or just click the mouse anywhere inside the document.
Voila! The convenience of vi at your fingertips. Literally.

Mind you, it is still pre-alpha (v0.0.1), and thus sorely lacking in features and probably ridden with bugs too. If you find some, please don't hesitate to report it in the project's Bugs or Feature Requests page. Please be kind as I am only doing this in my free time :-)

Here are some of the other commands that work so far:
  • :w (save)
  • :wq (save and close)
  • :q (close)
  • w (next word)
  • b (previous word)
  • $ (go to end of line)
  • ^ (go to start of line)
  • % (find matching bracket - you need to be in a Java or C/C++ editor for this)
  • most navigational keys (h, j, k, l and arrow/pgup/pgdown keys)
  • delete commands (x, dw, d$, dd, db)
  • u (undo)
In the future, I plan to add support for:
  • Find commands (/, ?, *, #)
  • Repeat previous command (.)
  • Command count (e.g., 3x to delete 3 characters)
  • Other neat vi features
  • Text editor (UI) enhancements such as status line, popup dialogs, preference pages, etc.
  • Help pages
Members & contributors to the project are most welcome, especially those with Eclipse platform knowledge!

In the next posts, I will try to document some of the experiences in developing the plug-in, for the benefit of those who might also be interested in Eclipse plug-in development. Stay tuned!

[Update (12/05/2007) - Ack.. I forgot to set the compiler level to 1.5. As a consequence, v0.0.1 will not run on 5.0 JREs. It's fixed now in v0.0.2]

Sunday, December 2, 2007

Build-averse

After reading this blog entry, I had a personal epiphany of sorts (or was it?). I realized that one of the reasons I love using Eclipse is: I hate building. Well, not really hate. It's just that, sometimes, I consider it a part of "noise" in the signal-to-noise of writing software. Or, maybe I'm just too lazy. Or, I just didn't know how useful (and perfectly natural) having a continuous build would be.

Most probably it's all of the above :-)