Microsoft

SolutionBase: Use coLinux to run Linux and Windows side-by-side

Both VMWare and Virtual Server 2005 will allow you to run both Linux and Windows at the same time on one server. However, if your budget doesn't allow you to afford these programs, you may be interested in coLinux. Here's how you can get Linux and Windows running side-by-side with coLinux.

Windows shops, take note! You can continue to run your supported platform of choice—Windows—and fairly easily run that useful Linux service you've been eyeing as a possible solution to one of your nagging problems. Perhaps you want to run Linux as your DHCP server for some reason. Go ahead! Even better, run it as a Linux service on one of your Windows servers using coLinux.

What is coLinux and how does it work?

coLinux—short for "cooperative Linux"—is a port of the Linux kernel modified to allow it to run simultaneously with another operating system's kernel. Sure, you could use a program like VMware to achieve something similar, but by using coLinux, you can cheaply and quickly get a Linux installation up and running on a Windows server without the need for third party software at all. In doing so, you avoid the overhead created by VMware's own processes as well.

coLinux works fairly in a fairly unique way. Basically, coLinux runs as any other Windows process and creates a virtual network between the physical computer and the Linux kernel process. By working in this way, it makes the Linux server act like a real Linux server that can run network-accessed services in the expected way.

System requirements

coLinux requires Windows 2000, XP, or Windows Server 2003 in order to work, although I was unsuccessful at getting it to work under Windows Server 2003. I have yet to find out why. These NT-based operating systems include support for asynchronous operations and include security features not found in DOS-based versions of Windows. "Asynchronous operations" is just a fancy way of saying that the computer can work on new tasks while waiting for other tasks to complete rather than queuing tasks up.

coLinux also requires the use of the TAP-Win32 virtual Ethernet adapter driver. TAP-Win32 allows processes running under a Windows server to access that Windows server as if it were accessing it over the network and vice-versa. This probably brings some insight into how coLinux achieves its capability of appearing to run as a separate computer. The version of the coLinux installer I used for this article installed the TAP-Win32 driver as a part of the installation.

You also need the Winpcap utility. Winpcap is a utility for Windows that provides packet capture and analysis functions and is offers programmers a way to directly access a packet driver independent of Microsoft's APIs.

That said, you can also configure coLinux to be bridged to a specific physical network adapter in your host computer if you like. Accomplish this by making changes to the coLinux configuration file, as discussed later. For this article, I'll be using the TAP-Win32 driver, which is installed automatically as a part of the coLinux installation. I will, however, mention how to use a bridged connection in a little while.

As far as RAM and disk space go, this is where things get a little hairy with coLinux. Depending on how things work out, coLinux can use anywhere from 16MB to 64MB of RAM. In the docs, the authors use the phrase "It used to default to 29MB which was sufficient for most things, now it seems to default to 64MB", which probably doesn't inspire a whole lot of confidence. I tend to think that whoever wrote that part of the documentation just chose a poorly worded sentence and didn't intend to imply that they have no idea how much RAM coLinux really uses.

This doesn't mean that a system with a total of 128MB of RAM will cut it. Bear in mind that you still need to run the operating system and other required processes, so be sure to have sufficient physical RAM to accommodate everything. Shoot for a minimum of 512MB, which, these days, shouldn't be much of a problem.

For disk space, you should have a partition with a few gigs available, just like you would for a normal Linux server. Since coLinux works using disk images you can download, you can check the size of the image you want to use to determine exact requirements. Officially supported distributions include Gentoo, Debian, and Fedora Core in the 2.4 series kernel and just Gentoo and Debian if you prefer to use a kernel based on Linux 2.6. You can modify other kernels to work with coLinux, if you want, but I won't be going over that in this article.

Whatever you decide to download, it's a root file system image that you use to boot your coLinux process. I'll go over this more in a bit.

Scope of this article

This article isn't intended to be a complete replacement for the coLinux FAQ site. By the end of this article, you'll have a working coLinux installation and network connectivity between the host computer on which coLinux is installed and the coLinux-based Linux server. You'll even be able to get to the Internet with your coLinux system, which takes a few extra steps.

Further, coLinux does not include a GUI—it's a command line only affair. However, you can use a remote VNC session to get a desktop. I'll also go over that in this article. It is possible to get an X desktop, but that requires a Cygwin installation and, in the interest of simplicity, I use the VNC option.

 

Getting and installing winpcap

Remember, before you get coLinux, download and install winpcap from http://winpcap.polito.it/install/default.htm. It's a very straightforward installation. There are not gotchas to watch for.

Getting and installing coLinux

For this article, I downloaded coLinux 0.6.2, which provides support for Linux 2.6 series kernels, from coLinux's SourceForge site. When you look at the download size and realize it's just under 5 MB, you might start to wonder how small coLinux's kernel really is. Actually, the downloadable installer doesn't include a full kernel. Instead, during the installation, you're asked to decide which kernel you want to use. You'll see more of that soon.

Once downloaded, execute the installer file. I saved everything to c:\colinux, which is also the location I'll ultimately use for my full coLinux install.

One of the first screens, shown in Figure A, asks you which components you'd like to install. Notice that winpcap is listed as a component, but when I failed to install winpcap before coLinux, I was greeted with a friendly error message asking me to install winpcap. Short story: I don't know if the coLinux installer really installs winpcap, so to play it safe, I just canceled the coLinux install, installed winpcap and then continued on with the coLinux install. It seemed to be the safest route to make sure that winpcap did really make its way onto my server.

Figure A

For a standard install, pick everything and hit next.

Note that the last item on the list is the "Root Filesystem Image Download". If you've opted to build your own coLinux-compatible kernel, you can deselect this option. For this article, I won't be building a custom kernel, so I kept the last option selection.

Next, decide where you want the coLinux files to reside. The default configuration, which you can change if you want, looks for everything to be located in c:\colinux, so that's where I installed coLinux, as shown in Figure B.

Figure B

Choose an installation location for coLinux.

After deciding where you want coLinux, decide which Linux distribution—Debian or Gentoo—you want to use for your coLinux installation. Whatever you choose will be downloaded and installed during the coLinux installation. I chose the Debian option for one installation and the Gentoo install for another, and eventually stuck with the Debian choice.

Figure C

Pick a Linux distribution, or none at all.

The next part takes a little time, depending on the speed of your connection to the Internet. This part of the installation downloads your selected distribution and then performs the actual coLinux installation. During this, you'll get a hardware installation warning for TAP-Win32 indicating that it's not certified by Microsoft. Continue the installation from there.

Using coLinux

Before you get started using coLinux, you need to expand the .bz2 (compressed) distribution image downloaded during the coLinux installation. Winzip supports bz2 files. Expanding the Debian image I downloaded resulted in a root file image around 1GB in size. Make sure you have a lot of disk space available!

Next. copy the default configuration file so you can preserve it in case you make a mistake. For me, I copied the default.colinux.xml configuration file to "debian.xml" in c:\colinux. I only made a couple of changes to the configuration file to make coLinux work on my server. I had to change the file so that it pointed to the Debian root file image that I downloaded. The following configuration line achieved this:

<block_device index="0" path="\DosDevices\c:\coLinux\Debian-3.0r2.ext3-mit-backports.1gb" enabled="true" />

Make networking work

Right out of the box, the Linux machine will run as a Windows application, but it's "disconnected"—that is, it doesn't have a way to use the network yet. To get browsing, you have to do a few things first.

First, enable Internet Connection Sharing on your host system's primary adapter. Later, the TAP driver you installed will use this connection to let your Linux machine access the rest of the network and the Internet. To enable Internet Connection Sharing, go to the Properties page for the network connection that connects your host system to the network and choose the Advanced tab. From that tab, enable the Internet Connection Sharing checkbox.

Bear in mind that ICS is not available on domain controllers at all, so you might have to mess around with bridging adapter interfaces on your Windows system. If at all possible, avoid this. It can result in unanticipated problems. Just try to use ICS wherever possible. In the "Home networking connection" option box, choose the TAP interface from the list.

Figure D

Choose the TAP interface as the home networking connection

Next, make sure that the IP address for your TAP interface is set to 192.168.0.1. The file system images provided by the coLinux folks default to 192.168.0.40. Also, rename your TAP interface to TAP. It's probably called something along the lines of "Local Area Connection 2" before you rename it.

Toward the end of your configuration file, look for the line that starts with <network index="0" | add a name="TAP" parameter to the end of that line. I found that it was easier to get coLinux working properly when this parameter was added. When you're done, the line should read:

<network index="0" type="tap" name="TAP" />

If you haven't renamed your interface, replace name=TP" with name="name of your interface" instead. If the network adapter you use to connect to the Internet or to your network is wireless, you should add another parameter to this line to make sure networking eventually works; namely add a mac="xx:xx:xx:xx:xx:xx" parameter right after the name parameter. In place of the XXs, of course, provide the MAC address for your wireless adapter. This fools your wireless access point into thinking that any traffic originating from your coLinux machine is actually originating from your host.

Add a swap partition

Every good server needs space to swap RAM to and from the disk. Your coLinux installation is no exception. Adding a swap partition is pretty easy, though. First, you need a disk image for the swap file. A number of pre-made swap file images in varying sizes are available from http://gniarf.nerim.net/colinux/swap/. I selected a 256MB swap file for my installation and modified the swap file line in my xml configuration file to read:

<block_device index="1" path="\DosDevices\c:\coLinux\swap_256Mb" enabled="true" />

The rest of the configuration can be left alone, assuming you installed coLinux to c:\colinux. If you didn't, make the appropriate changes in the configuration file before continuing.

Run coLinux

By default, coLinux is allocated 64MB of RAM. My machine has 2GB, which is more than enough for coLinux and Windows to coexist nicely. To run coLinux, from c:\colinux, execute

colinux-daemon -c debian.xml

If you've used Linux before, you'll see the familiar text scrolling by as disks are checked and services started, as shown in Figure E. Notice that the console is wrapped up inside a Windows window.

Figure E

Debian Linux under coLinux is starting up.

Test host networking by pinging, from the coLinux window, 192.168.0.1, the IP address of the host machine's TAP interface. Next, from the host machine, ping 192.168.0.40, the default IP address for the distributions available from the coLinux site. In both cases, you should have success, as I did for my installation.

Want a display?

I know: I said earlier that coLinux doesn't provide a GUI. That's not entirely true since you can load the X-windows packages and a window manager and then use them remotely over a VNC connection.

First, you need the core X-windows packages, conveniently available by using Debian's apt-get. Of course, if you're using a different root file system such as Fedora or Gentoo, these instructions won't work for you.

To get the X-windows core system files, from the command line, execute:

apt-get install x-window-system-core

You'll eventually come to a configuration, which asks you a few questions regarding your overall X configuration. With the exception of the questions listed below, choose the defaults. Figures F and G show samples from my lab configuration.

Figure F

Choose the defaults for the overall X configuration

Figure G

These are the options I modified and used in my sample configuration:

  • Color depth -16 bits
  • Resolution -800x600
  • X-server driver -VGA
  • Monitor type -LCD

With X-windows in place, now you just need a window manager, such as KDE, to really be able to use your system. Further, you'll need to install the VNC server on your system so that you can connect to your coLinux desktop using a VNC client such as RealVNC, which is the client I used for this example. Use the following two commands to install KDE and the VNC server:

apt-get install kde

apt-get install vncserver

Before trying to connect to your shiny new coLinux server, configure the VNC server side information that is executed when you connect to an X session on your coLinux server. To do so, create a directory name ".vnc" (with a leading period) in your home directory. For this example, I used the root user, although in a production environment, this probably isn't a good idea. My VNC directory is created in /root/.vnc.

Next, create a file called xstartup inside this new directory and add the following lines:

#!/bin/sh

startkde &

This is a shell script that starts KDE in the background when a VNC connection is established.

Next, provide a password for your VNC server by typing "vnc server password" at the command prompt. Upon doing so, your coLinux machine asks you to provide a password and then asks you to verify what you've typed.

Finally, start the VNC server. I wanted to start up in 800x600 with 160bit color, so I used the following command:

vncserver :1 -geometry 800x600 -depth 16

You might want different options, so make changes were appropriate. The result for my installation is shown in Figure H.

Figure H

A VNC session to my coLinux X-server

coLinux makes Linux and Windows cohabitate nicely

Sure, VMware could have done a lot of this with a little less hassle, but if you're just looking for a test Linux system, coLinux is starting to look like an interesting and viable option. With a few problems—I was unable to get coLinux to work under Windows Server 2003 SP1, for example—this beta of coLinux is looking really good and could conceivably be used to satiate that web developer that needs a Linux system to test different browsers, or just to dip your toes into the Linux world.

Editor's Picks

Free Newsletters, In your Inbox