Linux on Windows

Last updated 31/01/06

Sometimes you want to run something quickly under Linux without resorting to a reboot or using a different PC. An excellent product to achieve this is VMWare, however, there is also a very good free solution called coLinux (Cooperative Linux). CoLinux allows you to boot Linux on top of Windows without resorting to a reboot. It is like a Cygwin shell but binary compatible with Linux, i.e. you can run Linux binaries under Colinux.  I have been very impressed with CoLinux and use it regularly to compile stuff under Linux and to run some Linux only tools on Windows. This page describes the procedure I used to install coLinux running Gentoo on my WinXP laptop. This procedure also work for Win2K.

Before you start I would suggest you defrag your harddisk, you will need about 6 or 12 Gbyte for the full installation and lots of time. You might also want to open the following links for quick references before starting.

coLinux Wiki Getting Started Long
Gentoo Linux x86 Handbook

Installing coLinux

1)    Download the latest coLinux executables (coLinux-0.6.3-rc4.exe at the time of writing) from here and execute. When it asks for a distribution select the Gentoo Delux image, alternative download the Gentoo-2005.1-stage3-ext3.bz2 or later version from sourceforge.net.

2)    Next download an empty root filesystem, I would recommend to go for the 10GByte version (fs_10Gb.bz2) if you have the space.
3)    From the same site download an empty swap filesystem, as with Linux pick a file which is roughly equal or max twice your physical memory (e.g. swap_1024Mb.bz2)
4)    Unzip the Linux image, filesystem and swap image using bzip2 under Cygwin or download one of the many windows utilities like e.g. WinRAR, using cygwin:    

bzip2 -d Gentoo-2005.1-stage3.bz2
bzip2 -d swap_1024Mb.bz2
bzip2 -d fs_10Gb.bz2 

5)    The next step is the most tricky one, setting up the network. The executable will automatically download and install the TAP and WinPCAP network driver. For this setup I have selected the TAP driver. Select properties of your My Network Places, if you are running XP you will something as shown below

The installed TAP-Win32 adapter has created a virtual network adapter. To share the coLinux network with the outside world select your LAN connection and enable the sharing option with the TAP adapter (Local Area Connection 3) as shown below. You can find this option by RMB on the main LAN adaptor (Local Area Connection) and selecting properties, then select the advance tab

I had some difficulties under Windows2000, for some reason I couldn't enable the share until I had started coLinux. If you get stuck, check out the links below and do the usual google search:

coLinuxNetworking Wiki
Wrangling CoLinux Networking
coLinux Networking
CoLinux Setup

6)    Open the default.colinux.xml file in wordpad (note notepad!) or another good editor and correct the drive letter (i.e. if c:\colinux is not the installation directory), network connection and image files as shown below. I would also suggest to increase the memory_size.

<?xml version="1.0" encoding="UTF-8"?>
<colinux>
   <block_device index="0" path="\DosDevices\d:\coLinux\Gentoo-2005.1-stage3-ext3" enabled="true" />
   <block_device index="1" path="\DosDevices\d:\coLinux\swap_1024Mb" enabled="true" />   
   
   
<!-- bootparams allows you to pass kernel boot parameters -->
   <bootparams>root=/dev/cobd/0</bootparams>
   
<!-- Initial RamDISK (initrd) support -->
   <initrd path="initrd.gz" />    
   
<!-- image allows you to specify the kernel to boot -->
   <image path="vmlinux" />
   
<!-- this line allows you to specify the amount of memory available
         to coLinux -->
   
   <memory size="128" />
   
<!-- This allows you to modify networking parameters, see the README
         or website or wiki for more information -->

   <network index="0" type="tap" name="Local Area Connection 3" />

</colinux>

7)    Next execute coLinux:

colinux-daemon.exe -t nt -c default.colinux.xml

If you get any errors check that the default.colinux.xml file is correct. and that all the image files exists. You might also want to run dos2unix (Cygwin) on the file to remove any spurious CR and EOF characters.

8)    Login to Gentoo using the root password "root" (might be changed on later releases)
9)    I did not have to change any network configuration files on my Gentoo installation. To get the network up and running I only had to start the network daemon.

/etc/init.d/net.eth0 start

10)   After getting the network up and running get the latest software listings, you can do this using the command:

emerge --sync

11)   Update Gentoo to the latest versions, note this will take a couple of hours (3 hours on my AMD3500, 7 hours on my 3GHz laptop)!

emerge world

If you get a build error try to emerge the latest portage version followed again by emerge world

emerge portage
emerge world 

12)   After the update you are asked to update some config files in /etc, the easiest way to do this is to use the etc-update utility, use the -3 option followed by typing in 'y' for a few times

etc-update

13)   Update your fstab file, Gentoo comes with the nano editor, use CTRL-O to save the results and CTRL-X to quite.

nano -w /etc/fstab

example of my fstab file is shown below (only partly shown).

# <fs>       <mountpoint>  <type>   <opts>
/dev/cobd/0  /             ext3     noatime   0 1
/dev/cobd/1  none          swap     sw        0 0

14)    Enable the swap file

mkswap /dev/cobd/1
swapon /dev/cobd/1

15)    Shutdown coLinux.

shutdown -h now

Note: for some reason the "shutdown -h now" command doesn't work properly on my Win2K machine, however the reboot command does (you want to cleanly stops coLinux and not just kill the DOS box)

reboot

You have now a full binary compatible Linux console on your Windows machine! It is advisable to make a backup copy of the image incase something goes wrong. Just zip/rar/bzip2 the image, it should compress to less than 500Mbyte. 

Some general setup

1)    Change the hostname to something meaningful (instead of localhost):

nano -w /etc/conf.d/hostname

2)    Add your network script to the default runlevel so that it is executed automatically when you start coLinux

rc-update add net.eth0 default
/etc/init.d/net.eth0 start

3)    Fix the keyboard if required (look for the KEYMAP variable)

nano -w /etc/conf.d/keymaps

4)    Change the root password if required

passwd

5)    Add a new user (you don't want to work as root)

useradd -m -G users,wheel,audio -s /bin/bash hans
passwd hans
exit

(log on as non-root user to see if all is OK)

6)    Shutdown coLinux.

shutdown -h now

More commands and configuration options can be found in the Gentoo handbook and documentation. If you want to issue the reboot or shutdown command from a non-root user than checkout sudo.

Expanding Root

The 2Gbyte Gentoo image is too small to install any software, an easy trick is to mount an empty file system, copy all files across and then make the new filesystem the root image. This is described on this page, for completeness I have copied the procedure below.

1)    Open the default.colinux.xml file in an editor and add the line below (change the drive letter and image name as appropriate):

<block_device index="3" path="\DosDevices\d:\coLinux\fs_10Gb" enabled="true" />   

2)    Start coLinux and mount the new 10Gbyte empty filesystem.

mkdir /mnt/test
mount /dev/cobd/3 /mnt/test

You should get no warning messages, if you do check the default.colinux.xml file

3)     Copy the old 2Gbyte filesystem onto the new 10Gbyte one

cp -ax / /mnt/test
cp -a /dev/* /mnt/test/dev/
umount /mnt/test
reboot

4)     Modify your default.colinux.xml config file to use the new 10Gbyte image for the root filesystem (note block_device index changed from 3 to 0) and remove the Gentoo-2005.1-stage3-ext3 one

<block_device index="0" path="\DosDevices\d:\coLinux\fs_10Gb" enabled="true" />

5)    Restart coLinux and check the new filesystem, you should now have plenty of space to install applications. Note how easy it is to change the filesystem!

codionysus ~ # df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/cobd/0           4.0G  1.2G  2.6G  31% /
udev                   62M  480K   62M   1% /dev
none                   62M     0   62M   0% /dev/shm
codionysus ~ #
 

Installing Software under Gentoo

If you are planning to install Samba, X.org and xfce as described in the next two sections I would advice you to do this during a very long lunch break if you have a fast desktop or overnight on a laptop. Installing both packages took 8 hours on my laptop. You can use the following combined commands (the sync and portage commands are optional if you have already executed them),

emerge --sync
emerge portage
emerge samba tightvnc xfce4
 

Installing Samba

1)    If you already installed samba then skip this step. To share files between coLinux and the Windows host PC you can use samba. Downloading and installing Samba using Gentoo this is as easy as....

emerge samba

This will download a large number of files including some X stuff, not sure if this is all required but at least it is all compiled and installed automatically. The whole process will take some time (3 hours on an AMD3500).

2)    Create a shareable folder under Windows e.g. winshare
3)    Change to superuser on coLinux, create a directory under /mnt and set the permissions

su
mkdir /mnt/winshare
chown hans:users /mnt/winshare
exit

4)    Check that your windows firewall allow files to be shared for the TAP-Win32 adapter
5)    Create a samba mount (change IP, username and /mnt directory as appropriate)

smbmount //192.168.1.227/winshare /mnt/winshare -o hans

6)    You can now share files between coLinux and Windows using the winshare directory.
7)    You can add the share to your /etc/fstab file such that a user can mount it using mount /mnt/winshare. Example fstab file (again change windows hostname, username etc as appropriate):

# <fs>               <mountpoint>   <type> <opts>                        <dump/pass>
//Dionysus/winshare  /mnt/winshare  smbfs  username=hans,password=,user  0 0

8)    Some general links:

Accessing Windows Drives With Samba wiki
Gentoo Samba HOWTO
Mount Linux page 

X Display

1)    First emerge TightVNC if you haven't already done so:

emerge tightvnc

2)    log out of root and into your user account

exit    

3)    Start the Tightvnc server, make sure you use a minimum depth of 16, default resolution is 1024x768, you can change this using the -geometry option.

hans@codionysus ~ $ vncserver -depth 16
You will require a password to access your desktops.

Password:
Verify:

Would you like to enter a view-only password (y/n)? n
xauth:  creating new authority file /home/hans/.Xauthority

New 'X' desktop is codionysus:1

Creating default startup script /home/hans/.vnc/xstartup
Starting applications specified in /home/hans/.vnc/xstartup
Log file is /home/hans/.vnc/codionysus:1.log

4)    Start the VNCViewer on windows and use the coLinux IP address (defaults to 192.168.0.40) and the display number returned by the vncserver (in the above case 1).  

And you should hopefully get:

5)    Next kill the vncserver by either pkill Xvnc command or vncserver -kill :1

vncserver -kill :1

6)    TightVNC uses the twm window manager by default, this is OK for some simple text application but you might want to get a more fancy one.  You could go for KDE or Gnome but you might also want to look at a more lightweight manager like xfce

emerge xfce4

7)    To start xfce automatically when you start TightVNC, open the .vnc/xstartup file in nano and change the twm manager to startxfce4. I would also remove or comment out the xterm command

nano -w .vnc/xstartup

My file looks like:

#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
startxfce4 &

8)    Restart the vncserver as described under point 3 and observer a much nicer environment :-)

vncserver -depth 16

 

Some useful links