August 24, 2004

Introducing coLinux

Author: Jimmy O'Regan

Windows users who need access to the tools available with Linux while running Windows, without having access to a separate machine, have until recently had two choices: if they simply need POSIX tools, they can install Cygwin; if they need a full Linux system, they can install Linux using a virtual machine such as Cygwin. Cooperative Linux provides a third choice: now users can run Linux alongside Windows.

Cooperative Linux, or coLinux, is similar to User Mode Linux -- a port of the Linux kernel which runs as a program. coLinux consists of a kernel driver for the host system, a Windows service that launches the Linux system and translates calls from Linux devices to Windows devices, and a virtual console.

coLinux isn't as easy to set up as VMware, but it isn't too difficult. From version 0.60 onwards, it uses the usual type of Windows installer program. The download page on SourceForge has disk images for Debian, Fedora Core, and Gentoo; there is also a package of coLinux tools available, if you want to set up another distribution.

I should mention that although I described coLinux as a alternative to Cygwin, Cygwin actually complements coLinux well; the users who will get the best use from coLinux are those who already have experience with Linux, and who will feel at home with Cygwin. Rather than using the coLinux tools to create a disk image, for example, these users may be more comfortable using dd.

Setting up coLinux

The coLinux installer takes care of setting up the kernel part, as well as setting up a TAP (virtual Ethernet) device for networking. After installation, you have to edit the configuration file C:\Program Files\coLinux\default.colinux.xml.

<?xml version="1.0" encoding="UTF-8"?>
<colinux>
    <block_device index="0" path="\DosDevices\c:\coLinux\Debian-3.0r0.ext3.1gb"
    enabled="true" />
    <block_device index="1" path="\DosDevices\c:\coLinux\swap" enabled="true" />

    <bootparams>root=/dev/cobd0</bootparams>

    <image path="vmlinux" />

    <memory size="64" />

    <network index="0" type="tap" />
</colinux>

The only section you really need to edit is the path to the disk image of the distribution you intend to use, though you will more than likely want to use a swap file. The number of the index parameter for each block_device corresponds to the block device Linux will see; my example sets up two devices, /dev/cobd0 and /dev/cobd1.

Once your configuration is set up, you can start the service. The installer should have installed the service, but if it didn't, you can use install it using the colinux-daemon tool:

colinux-daemon --install-service "Cooperative Linux"

This tool can be useful if you want to run more than one instance of coLinux. As you might expect, each instance needs its own configuration file; they also require their own service names. To set up a second instance, you could use:

colinux-daemon -c c:\colinux\config2.colinux.xml --install-service "Cooperative Linux 2"

After you install the service, you need to start it. Using Cygwin, the service can be started with cygrunsrv -S "Cooperative Linux", replacing "Cooperative Linux" with the name you used when installing the service. If you're not using Cygwin, you can start the service from the Control Panel. In Windows NT 4, you can simply open the "Services" applet. In XP, you first need to Switch to Classic View and then open Administrative Tools to get to the Services program. Once you have opened the Services applet, locate the coLinux service -- named "Cooperative Linux" by default -- and click "Start the service." If you don't have the Administrative Tools option available in the Control Panel, you can still access the Services applet by running %SystemRoot%\system32\services.msc /s.

Once the service is running, you can connect the console. coLinux comes with two console programs: colinux-console-nt, which runs from the command-line, and colinux-console-fltk, which provides its own window.

Networking

Now that you have coLinux up and running, you'll more than likely want to set up networking. Most of the work should be done already -- the installer adds a network connection using the TAP device, and the Debian image comes with the proper settings to use it. With the DSL service I use, I have to use Window's Internet Connection Sharing to use the Internet from coLinux. In the Advanced tab of my network card's properties, all I had to do was enable Internet Connection Sharing and select the TAP device, and Windows was ready; once I added the IP address of my ISP's DNS server to /etc/resolve.conf I was ready to start installing software.

If you are running multiple coLinux instances, you need to add new TAP devices for each of them using Add Hardware in the Control Panel.

With the network set up, if you have Cygwin's X packages installed, you can start using X programs across the virtual network. In coLinux, you need to tell X to use the Windows box as the X server by setting the DISPLAY environment variable. Using the default IP addresses set up by coLinux, enter these commands in Cygwin (the -multiwindow switch starts a rootless X server, so you get windows that look like normal windows):

XWin -multiwindow &
xhost +192.168.0.40

Then from coLinux, type:

export DISPLAY="192.168.0.1:0"
xeyes&

If you don't have an X server for Windows, you can use VNC instead. I prefer to use standard resolutions, one step below the resolution I'm using, to take into account the amount of space the VNC viewer will use for its menus. Since my Windows resolution is set to 1024x768, I'll set the resolution to 800x600 when starting the VNC server. To do this in coLinux, enter this command:

vncserver -geometry 800x600 -depth 16

What next?

What you do next is up to you. For sheer convenience, I'd recommend setting up Samba in coLinux to facilitate file and printer sharing with Windows machines. My guess is that the most common use of coLinux will be by Web developers, but I'd be interested to hear about unusual uses.

Talking about kernel compiling would be out of place in this introductory article, but it should be possible to have most kernel patches work with coLinux, so long as you remember to install the coLinux modules with the new kernel. For the truly adventurous, it might be interesting to see if you can get User Mode Linux running -- people have already joined OpenMosix and coLinux.

Anyone who wants more information about coLinux will find it at the coLinux wiki. There's a lot of information available for just about any kind of configuration, with a fairly active community maintaining it.

Click Here!