Install coLinux (and Ubuntu Hardy) on Win XP using Slirp to internet and TAP to host behind a corporate firewall/proxy server

This is my OLD blog. I've copied this post over to my NEW blog at:

You should be redirected in 2 seconds.

coLinux allows you to run a full Linux distribution, such as Ubuntu Hardy, on top of Windows at near native speeds. It runs as a single Windows process with its own specially allocated address space. The guest linux system can run from either a separate disk partition or from a single file on your Windows filesystem.

My initial impression of coLinux was so positive, I had planned to name this post, Goodbye Cygwin, hello coLinux. After 2 months of using coLinux, I still am using Cygwin a little bit. Despite being slow, (almost unbearably slow with my company's mandatory Whole Disk Encryption), Cygwin is good at integrating the GNU tools with Windows. Currently, I am still using Cygwin to script my Windows-only project version control system and use the Cygwin version of Mercurial for my personal version control. I'm not sure if using the Linux version of Mercurial would work on Samba shares. The more I learn about Linux and the less I depend on Windows applications, the less I will need Cygwin. (Update: Mercurial 1.0 works great on Samba shares. The important thing is to setup the owner of the share to be your user id and not root. See samba config below.)

Besides that, coLinux is great. The best part for me was being able to run the dynamic, tiling, scriptable, keyboard-driven window manager, wmii. I access Windows files (and network drives) using Samba. Shell commands, emacs, ssh are all there and are so fast. GUI applications such as Firefox, OpenOffice and Gimp are available as well. However, these are slow with the slirp networking setup. With a TAP connection between coLinux and the host OS, these apps run well, however, I couldn't get the TAP connection to work in conjuction with internet access so I settled for slirp only. If I figure this out, I will update the post. Here are my install notes.

Update 4/28/2008: I got my private TAP connection to the host working along with a slirp connection for internet. This makes my X server connections fast enough to run all my GUI apps like OpenOffice, evince kpdf for pdf files, and my web browser. See this section for details.


Install coLinux
  1. Download the coLinux installer and the Ubuntu root file system image
  2. Run the coLinux Windows installer
    • Accept defaults except for:
    • Destination Folder: change to c:\coLinux
    • You do not need to install WinPCap library.
    • You will get a warning dialog saying that "TAP-Win32 Adapter V8 (coLinux)" has not passed Windows Logo testing. Click "Continue Anyway"

Configure CoLinux
I already had Cygwin running so I did this stuff in a bash shell. You can use Windows commands as well to do the same thing.
  1. Copy Ubuntu-6.06.1.ext3.1bg.bz2 to c:\coLinux. (Keep a copy of this file as a backup to revert your Ubuntu filesystem if you mess things up.)
  2. Decompress the Ubuntu file system image. (Note, this could take a minute or more depending on your system.)
    $ cd /cygdrive/c/coLinux
    $ bunzip2 Ubuntu-6.06.1.ext3.1gb.bz2
  3. Create a swap file
    $ dd if=/dev/zero of=swap_device bs=1M count=512
    $ dd if=/dev/zero of=swap_device.2gb bs=1M count=2K
    (In Windows, you can use fsutil file createnew swap_device 536870912 )
  4. Create a configuration file
    $ cp example.conf colinux.conf
    Edit colinux.conf and set the following:
    eth1=tuntap # only needed for TAP connection
    The following items should already be set by default:

Run CoLinux
  1. Open a Windows cmd.exe shell
  2. cd c:\colinux
  3. colinux-daemon.exe -t nt @colinux.conf
    (the -t nt is optional but makes it easier to copy/paste)
  4. login as "root" with password "root"
  5. Try commands such as ls, pwd, etc.
  6. To exit, use the halt command.

Configure networking with slirp only
  1. If you use a http proxy server to get to the internet, do the following inside the running CoLinux session:
    root@ubuntu:~# echo "export http_proxy=''" >> .bash_profile
    root@ubuntu:~# source .bash_profile
  2. Otherwise, there is nothing to do. The Ubuntu image already has the correct /etc/network/interfaces and /etc/resolv.conf files setup.

    /etc/network/interfaces should look like this:
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    # The loopback network interface
    auto lo
    iface lo inet loopback
    # The primary network interface (slirp)
    auto eth0
    iface eth0 inet static

  3. /etc/resolv.conf should look like this:
  4. To test internet access, use something like wget since ping doesn't work with slirp.
    root@ubuntu:~# wget

Configure networking with slirp to internet and TAP to host
In this configuration, I set up TAP to form a private connection to the host and slirp to access the internet. If you want to use X applications, this will make the response much better than with slirp only. I had to play around with the IP addresses to find one that didn't conflict with the static IP addresses on our network. I ended up choosing "" for the TAP colinux address and "" for my Windows side.
  1. TAP should be installed when you install coLinux
  2. In Windows, go to "Start", "Control Panel", "Network Connections"
  3. Find the "TAP-Win32 Adapter V8 (coLinux)" adapter. For me, it was named "Local Area Connection 2". Right click on it and select "Properties".
  4. On the "General" tab, scroll down and select "Internet Protocol (TCP/IP)". Click on "Properties".
  5. Select "Use the following IP address:". Enter in "" for the "IP address:" and "" for the "Subnet mask:". Leave the rest blank. Click "OK" twice to finish.
  6. in coLinux, edit /etc/network/interfaces to look like the following:
    auto lo
    # Loopback interface
    iface lo inet loopback
    # Network interface for internet access (slirp)
    auto eth0
    iface eth0 inet static
    # Network interface for private connection to Host OS (tap-win32)
    auto eth1
    iface eth1 inet static
  7. Make sure your "colinux.conf" file has the following lines:
  8. You will need to set your DISPLAY variable to ""
    root@ubuntu:~# export DISPLAY=

Update your Ubuntu Dapper installation
  1. root@ubuntu:~# apt-get update
    You can ignore the following warning:
    W: GPG error: dapper-security Release: Could not exec
    ute /usr/bin/gpgv to verify signature (is gnupg installed?)
    W: GPG error: dapper-updates Release: Could not exe
    cute /usr/bin/gpgv to verify signature (is gnupg installed?)
    W: GPG error: dapper-backports Release: Could not e
    xecute /usr/bin/gpgv to verify signature (is gnupg installed?)
    W: GPG error: dapper Release: Could not execute /us
    r/bin/gpgv to verify signature (is gnupg installed?)
    W: You may want to run apt-get update to correct these problems
  2. root@ubuntu:~# apt-get upgrade
    Answer yes to prompts.
  3. That was easy.

Run an Xterm and other apps

Warning, getting the X Window System working properly was one of the most frustrating parts of the setup for me. The behavior seemed to be even non-deterministic. This is what worked for me. You may need to consult other sources to get it working for you. I am starting to read X Power Tools to learn more about the X Window System and will update this section if I learn anything new. I used Cygwin's X server because I already had Cygwin installed. Another option is Xming.

Update 5/6/2008: After switching to the Slirp+TAP networking configuration, I've been getting errors when trying to start my X clients:

$ xeyes
No protocol specified
Error: Can't open display:
$ xterm
No protocol specified
xterm Xt error: Can't open display:
$ urxvt
No protocol specified
urxvt: can't open display, aborting.
To resolve this, I have been starting up a Cygwin bash shell, and running the xhost + command to disable access control. This worked, but it was annoying to do this all the time. I discovered that there is a -ac command line option to Xwin which will do the same thing. I've updated my batch file below to reflect this. Here is a list of all the Xwin command line options:
use: X [:] [option]
-a #                   mouse acceleration (pixels)
-ac                    disable access control restrictions
-audit int             set audit trail level
-auth file             select authorization file
bc                     enable bug compatibility
-br                    create root window with black background
+bs                    enable any backing store support
-bs                    disable any backing store support
-c                     turns off key-click
c #                    key-click volume (0-100)
-cc int                default color visual class
-co file               color database file
-core                  generate core dump on fatal error
-dpi int               screen resolution in dots per inch
-deferglyphs [none|all|16] defer loading of [no|all|16-bit] glyphs
-f #                   bell base (0-100)
-fc string             cursor font
-fn string             default font name
-fp string             default font path
-help                  prints message with these options
-I                     ignore all remaining arguments
-ld int                limit data space to N Kb
-lf int                limit number of open files to N
-ls int                limit stack space to N Kb
-logo                  enable logo in screen saver
nologo                 disable logo in screen saver
-nolisten string       don't listen on protocol
-noreset               don't reset after last client exists
-reset                 reset after last client exists
-p #                   screen-saver pattern duration (minutes)
-pn                    accept failure to listen on all ports
-nopn                  reject failure to listen on all ports
-r                     turns off auto-repeat
r                      turns on auto-repeat 
-render [default|mono|gray|color] set render color alloc policy
-s #                   screen-saver timeout (minutes)
-sp file               security policy file
-su                    disable any save under support
-t #                   mouse threshold (pixels)
-terminate             terminate at server reset
-to #                  connection time out
-tst                   disable testing extensions
ttyxx                  server started from init on /dev/ttyxx
v                      video blanking for screen-saver
-v                     screen-saver without video blanking
-wm                    WhenMapped default backing-store
-x string              loads named extension at init time 
-maxbigreqsize         set maximal bigrequest size 
+extension name        Enable extension
-extension name        Disable extension
-query host-name       contact named host for XDMCP
-broadcast             broadcast for XDMCP
-indirect host-name    contact named host for indirect XDMCP
-port port-num         UDP port number to send messages to
-from local-address    specify the local address to connect from
-once                  Terminate server after one session
-class display-class   specify display class to send in manage
-cookie xdm-auth-bits  specify the magic cookie for XDMCP
-displayID display-id  manufacturer display ID for request
The X Keyboard Extension adds the following arguments:
-kb                    disable the X Keyboard Extension
+kb                    enable the X Keyboard Extension
[+-]accessx [ timeout [ timeout_mask [ feedback [ options_mask] ] ] ]
                       enable/disable accessx key sequences
-ar1                   set XKB autorepeat delay
-ar2                   set XKB autorepeat interval
-noloadxkb             don't load XKB keymap description
-xkbdb                 file that contains default XKB keymaps
-xkbmap                XKB keyboard description to load on startup
-depth bits_per_pixel
 Specify an optional bitdepth to use in fullscreen mode
 with a DirectDraw engine.
-emulate3buttons [timeout]
 Emulate 3 button mouse with an optional timeout in
-engine engine_type_id
 Override the server's automatically selected engine type:
  1 - Shadow GDI
  2 - Shadow DirectDraw
  4 - Shadow DirectDraw4 Non-Locking
 Run the server in fullscreen mode.
-refresh rate_in_Hz
 Specify an optional refresh rate to use in fullscreen mode
 with a DirectDraw engine.
-screen scr_num [width height [x y] | [[WxH[+X+Y]][@m]] ]
 Enable screen scr_num and optionally specify a width and
 height and initial position for that screen. Additionally
 a monitor number can be specified to start the server on,
 at which point, all coordinates become relative to that
 monitor (Not for Windows NT4 and 95). Examples:
  -screen 0 800x600+100+100@2 ; 2nd monitor offset 100,100 size 800x600
  -screen 0 1024x768@3        ; 3rd monitor size 1024x768
  -screen 0 @1 ; on 1st monitor using its full resolution (the default)
 Hide the windows mouse pointer when it is over an inactive
 Cygwin/X window.  This prevents ghost cursors appearing where
 the Windows cursor is drawn overtop of the X cursor
 Do not draw a window border, title bar, etc.  Windowed
 mode only.
 Run the server in multi-window external window manager mode.
 Run the internal window manager.
 Run the server in rootless mode.
 Run the server in multi-window mode.
 EXPERIMENTAL: Use the entire virtual screen if multiple
 monitors are present.
 Run the clipboard integration module.
 Do not use at the same time as 'xwinclip'.
 Do not use Unicode clipboard even if NT-based platform.
 In windowed mode, allow screens bigger than the Windows desktop.
 Moreover, if the window has decorations, one can now resize
 Do not create a tray icon.  Default is to create one
 icon per screen.  You can globally disable tray icons with
 -notrayicon, then enable it for specific screens with
 -trayicon for those screens.
-clipupdates num_boxes
 Use a clipping region to constrain shadow update blits to
 the updated region when num_boxes, or more, are in the
 updated region.  Currently supported only by `-engine 1'.
 Ctrl+Alt+Backspace exits the X Server.
 Alt+F4 exits the X Server.
-xkbrules XKBRules
 Equivalent to XKBRules in XF86Config files.
-xkbmodel XKBModel
 Equivalent to XKBModel in XF86Config files.
-xkblayout XKBLayout
 Equivalent to XKBLayout in XF86Config files.
 For example: -xkblayout de
-xkbvariant XKBVariant
 Equivalent to XKBVariant in XF86Config files.
 For example: -xkbvariant nodeadkeys
-xkboptions XKBOptions
 Equivalent to XKBOptions in XF86Config files.
-logfile filename
 Write logmessages to  instead of /tmp/Xwin.log.
-logverbose verbosity
 Set the verbosity of logmessages. [NOTE: Only a few messages
 respect the settings yet]
  0 - only print fatal error.
  1 - print additional configuration information.
  2 - print additional runtime information [default].
  3 - print debugging and tracing information.
 Grab special windows key combinations like Alt-Tab or the Menu key.
 These keys are discarded by default.
 Disable the usage of the windows cursor and use the X11 software cursor instead
You can view this list by typing Xwin --help in a Cygwin bash shell. Also, in the process, I tried the Xming X server. However, I couldn't get it to work with wmii, so I decided to stick with Cygwin's X server.

  1. Edit your startxwin.bat file (located in "C:\cygwin\usr\X11R6\bin") so that it starts X in rootless mode, with clipboard support, disables access control, and doesn't run anything else. Run the new bat file.
    @echo off
    SET CYGWIN_ROOT=\cygwin
    SET RUN=%CYGWIN_ROOT%\bin\run -p /usr/X11R6/bin
    SET PATH=.;%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin;%PATH%
    SET XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
    SET XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
    SET XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
    SET XNLSPATH=/usr/X11R6/lib/X11/locale
    if not exist %CYGWIN_ROOT%\tmp\.X11-unix\X0 goto CLEANUP-FINISH
    attrib -s %CYGWIN_ROOT%\tmp\.X11-unix\X0
    del %CYGWIN_ROOT%\tmp\.X11-unix\X0
    if exist %CYGWIN_ROOT%\tmp\.X11-unix rmdir %CYGWIN_ROOT%\tmp\.X11-unix
    %RUN% XWin -clipboard -silent-dup-error -rootless -ac
  2. If you are using Slirp-only networking:
    • Obtain your Windows host IP address by opening a cmd.exe shell and running ipconfig
    • In coLinux, set your DISPLAY variable to this IP address:
      root@ubuntu:~# export
      where is your IP address. Don't forget the :0.0 at the end.
  3. If you are using TAP plus Slirp configuration described above, set your DISPLAY variable to ""
    root@ubuntu:~# export DISPLAY=
  4. root@ubuntu:~# apt-get install xterm
    Answer yes to prompts.
  5. root@ubuntu:~# xterm&
    Xterm comes up!
  6. You can now install and run other high level apps like firefox or emacs

Expand the root file system image
You will need to expand the size your root filesystem image to hold the larger Ubuntu installation. I expanded it to 4GB for Xubuntu Hardy and am currently using about 87% of that. You might want to expand it to 5GB or more especially if you will be installing a lot of apps. See for more information. Note, Google's calculator function can be useful for calculating block sizes. (e.g. entering in 4GB / 16KB into the Google search box returns: (4 gigabytes) / (16 kilobytes) = 262 144)
  1. If you have coLinux running, shut it down, with halt
  2. In a Cygwin bash shell, make a copy of your current image.
    $ cp Ubuntu-6.06.1.ext3.1gb Ubuntu-6.06.1.ext3.4gb
    This may take a while.
  3. Expand the new file:
    $ dd bs=16384 if=/dev/zero of=Ubuntu-6.06.1.ext3.4gb seek=65536 count=262144

    bs=16384 sets the blocksize to 16KB
    seek=65536 skips the first 65536 blocks (1GB/16KB = 65536)
    count=262144 adds 262144 blocks to the image (4GB/16KB = 262144)

    This may take a while also. It should display the following when complete:
    262144+0 records in
    262144+0 records out
    4294967296 bytes (4.3 GB) copied, 154.362 s, 27.8 MB/s
  4. Change your colinux.conf file to use the new file system image:
  5. Switch back to the cmd.exe console, and start coLinux again
  6. root@ubuntu:~# apt-get install ext2resize
  7. root@ubuntu:~# ext2online /dev/cobd0
  8. Look at your available space:
    root@ubuntu:~# df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/cobd0             4128448    411148   3507624  11% /
    varrun                  128096        36    128060   1% /var/run
    varlock                 128096         0    128096   0% /var/lock
    devshm                  128096         0    128096   0% /dev/shm
  9. Note, you may want to make a backup copy of your new expanded root file system image at this point in case things get hosed up later on. Be sure to halt coLinux first. Note, this will take even longer than the 1gb filesystem copy.

Upgrade to Ubuntu Hardy
Update 4/28/2008: When I first installed coLinux, Ubuntu Gutsy was the latest release. Because there was no direct upgrade path from Ubuntu 6.06 Dapper to Ubuntu 7.10 Gutsy, I had to incrementally upgrade from Dapper to Edgy, Edgy to Feisty, and Feisty to Gutsy. Later, when Hardy came out, I upgraded from Gutsy to Hardy. If you are upgrading to Dapper to Hardy for the first time, you can use the incremental method, or the direct method. Ubuntu supports a direct upgrade from 6.06 Dapper Drake to 8.04 Hardy Heron because both are Long Term Support (LTS) releases. See the Ubuntu upgrade documentation for more information. Note, I did not test the direct upgrade method.
  1. In coLinux:
    root@ubuntu:~# apt-get update
  2. root@ubuntu:~# apt-get install ubuntu-minimal
  3. root@ubuntu:~# apt-get install ubuntu-standard
  4. root@ubuntu:~# apt-get install xubuntu-desktop
  5. Edit your sources.list file and change "dapper" to "edgy"
    root@ubuntu:~# nano /etc/apt/sources.list
  6. root@ubuntu:~# apt-get update
  7. root@ubuntu:~# apt-get upgrade
  8. root@ubuntu:~# apt-get dist-upgrade
  9. Change "edgy" to "feisty" in /etc/apt/sources.list and repeat steps 6-8.
  10. Change "feisty" to "gutsy" in /etc/apt/sources.list and repeat steps 6-8.
  11. Change "gutsy" to "hardy" in /etc/apt/sources.list and repeat steps 6-8.
  12. Remove unneeded packages:
    root@ubuntu:~# apt-get autoremove

Disable some startup services
This is optional but may give you fewer warnings. In coLinux, go to the /etc/rc2.d directory and follow the instructions in the README file for disabling services. Here are some suggested services to disable:
  • acpid, acpi-support, apmd: used for power management
  • bluetooth: used for bluetooth
  • hotkey-setup: used to configure laptop hotkeys
  • pcmciautils: tools for PCMCIA cards (PC cards)
  • powernowd: controls CPU speed and voltage using the sysfs interface
  • vbesave: used to save the video card state

Configure Ubuntu
  1. Don't start gdm (the display manager which starts the X server)
    root@ubuntu:~# mv /etc/rc2.d/S13gdm /etc/rc2.d/K87gdm
  2. Set the timezone
    Start your Cygwin X server if it is not already running.
    root@ubuntu:~# time-admin &
    Set your timezone.
  3. Set the root password
    root@ubuntu:~# passwd
  4. Set local machine name:
    root@ubuntu:~# nano /etc/hostname
    root@ubuntu:~# nano /etc/hosts
  5. Create a user account
    root@ubuntu:~# adduser sofeng
    Note, adduser is a higher level command than useradd. adduser will set up a group and home directory.
  6. Set permissions on /dev/tty* (Note: not sure if this is needed)
    root@ubuntu:~# chgrp tty /dev/tty*
    Edit /etc/group to have the following line:
  7. Make a pty device
    root@ubuntu:~# cd /dev
    root@ubuntu:~# MAKEDEV pty
  8. Add environment variables to .bash_profile
    Use the printenv command to list your environment variables.

Create a home filesystem image
  1. Create a 10GB blank file. In Cygwin,
    $ dd if=/dev/zero of=home-fs-image.10gb bs=1M count=10K
  2. Add the following to your c:\coLinux\colinux.conf file:
  3. Restart coLinux, then do the following:
    Create an ext2 file system on the new disk image
    root@ubuntu:~# mke2fs -F /dev/cobd2
    Turn this into an ext3 filesystem
    root@ubuntu:~# tune2fs -i 0 -j /dev/cobd4
  4. Mount the new filesystem to /home
    root@ubuntu:~# mv /home /home_backup
    root@ubuntu:~# mkdir /home
    root@ubuntu:~# mount /dev/cobd2 /home
    Check it worked:
    root@ubuntu:~# df
  5. To mount the filesystem automatically at startup, add the following line to your /etc/fstab:
    /dev/cobd2   /home   ext3   defaults   0 0

Setup the swap file
  1. Add the following to /etc/fstab:
    /dev/cobd1   swap   swap   defaults  0 0
  2. Initialize the swap partition
    root@ubuntu:~# sudo mkswap /dev/cobd1
  3. make use of swap now, without rebooting system:
    root@ubuntu:~# swapon -a
  4. Check that swap total is non-zero:
    root@ubuntu:~# free

Mount Windows filesystem as Samba share
  1. Setup Windows networking:
    • In Windows Explorer, right click on your C: drive and select "Properties"
    • Click on the "Sharing" tab
    • Select "Share this folder". Set the "Share name:" to "E$". Setup "Permissions" as necessary.
  2. create the location for your samba share:
    $ sudo mkdir -p /mnt/cdrive
  3. add the following to /etc/fstab:
    //$ /mnt/cdrive smbfs auto,user,rw,dir_mode=0777,file_mode=0777,uid=sofeng,gid=sofeng,credentials=/etc/smb-credentials 0 0
    /mnt/cdrive is the mount point
    smbfs means it is a samba filesystem type
    auto means it will be mounted at startup
    user means any user can mount it
    rw means it will be readable and writable
    file_mode=0777 specifies that files will be readable, writable, and executable by everyone (this replaces the deprecated fmask)
    dir_mode=0777 specifies that directories will be readable, writable, and executable by everyone (this replaces the deprecated dmask)
    uid=sofeng means the owner is sofeng
    gid=sofeng means the group is sofeng
    credentials=/etc/smb-credentials specifies the file that contains the user name and password
  4. create /etc/smb-credentials
    $ sudo chmod 600 /etc/smb-credentails
  5. Mount the drive:
    $ sudo mount /mnt/cdrive

Set up wmii window manager
  1. Install wmii window manager
    apt-get install wmii
  2. I use emacs so the following steps are used to change the mod key.
  3. Download KeyTweak for Windows and remap your "Left Windows" key to "Context Menu".
  4. Use xmodmap to setup the "Menu" key to be "mod4". For my keyboard, my ~/.Xmodmap file looks like this:
    clear mod4
    keycode 115 =
    keycode 127 =
    keycode 117 = Super_L
    add mod4 = Super_L
    Then run xmodmap in one of your startup scripts (.xinitrc, .bash_profile, etc.)
    xmodmap ~/.Xmodmap

1 comment:

Brito said...

Hi Sofeng,

Your blog's content is excellent and quite helpful. Your site is now in my bookmarks, and I've just recommended this post in my blog.

Keep up the good work.


This is my *OLD* blog. I've copied all of my posts and comments over to my NEW blog at:

Please go there for my updated posts. I will leave this blog up for a short time, but eventually plan to delete it. Thanks for reading.