Sunday, March 16, 2008

Install Gentoo with coLinux

coLinux is gaining momentum as a way to run Linux programs on Windows, and I decided to try it. As a user of Gentoo, my first choice is to use Gentoo with coLinux. The following description documents what I have done to run Gentoo cooperatively in Windows laptop. I mainly follows up the Gentoo Wiki Howto article and other coLinux resources.

1. Installation

First download the latest coLinux snapshot (you can also get it from SourceForge). The file I used is coLinux-0.7.2.exe from SourceForge. Run the installer. Some notes during installation:

  • In screen Choose Components, leave the default settings on (i.e. selecting all components), but uncheck Root FileSystem image download (we will download it separately).
  • In addition, change the Destination folder to c:\bin\coLinux (note that all the description below assumes coLinux is installed into this directory. If you prefer other directory, please modify accordingly in steps below).
  • Installer prompts to download and install WinPCap separately, but my network configuration does not need WinPCap therefore I don't install it.

Then download Gentoo-colinux-i686-2007-03-03.7z from SourceForge, extract the archive into c:\bin\coLinux, with a gentoo subdirectory created during extraction. Copy file gentoo.conf in gentoo to the parent directory and modify it as follows:


Some explanations of the above file, details will be covered in later sections.

  • For mem, I set it to 1G. Choose according to your own situation.
  • For network, I only select TAP driver.
  • I shared Windows folder c:\linux to coLinux.
  • CD/DVD-Drive is mounted.

To test drive, open a command prompt, change to the directory c:\bin\coLinux, and run the following command:

colinux-daemon @gentoo.conf

coLinux console should run. If there is something wrong, please check previous steps. After some time, you are prompted for log in. You can now login as root with password. Change your password immediately.

Congratulations! You just successfully run Gentoo in coLinux! You can now fool around with the system. Type halt when you are tired. There is still a long road ahead to fully harness the power. Following is two optional steps, but highly recommended.

Run coLinux during system startup

First, we need to install coLinux as a service. Open a command prompt, change to the directory c:\bin\coLinux, and run the following command:

colinux-daemon.exe @gentoo.conf --install-service "CoGentoo Linux" 

Then open Control Panel, first select Administrative Tools, then Services, click service CoGentoo Linux, and change its Startup type to Automatic.

Enlarge the image file

The original image size is 2G. This might not be sufficient. To enlarge it, you need to download the tools from here. Extract the archive and run file toporesize.bat. Use the program to resize file c:\bin\coLinux\gentoo\gentoo-root to whatever size you want. Make sure you uncheck "resize file only no resize2fs".

2. Configuration

2.1 Timezone

Since I'm located in Beijing, I set the corresponding info as follows. The related configuration files is /etc/conf.d/clock. I changed two lines as follows.


Also run command ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime.

It is interesting that Beijing cannot manage to snap one place inside /usr/share/zoneinfo/Asia.

2.2 Network

Based on coLinux wiki article.

2.2.1 One network interface

This configuration only enable TAP, which is used to enable both the high-speed private connection between Windows host and Linux guest, and also to bridge the connection to Internet. One drawback of this setup is that when you Internet connection changes (e.g. from ADSL to WiFi, you have to adjust bridging and some parameters manually).

File gentoo.conf discussed above already contains the setup for coLinux. Next steps are as follows.

On hosting OS (Windows), configure TAP-Win32 Adapter V8 (coLinux) with following properties (make sure to leave Default Gateway as blank):

Ethernet adapter:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : TAP-Win32 Adapter V8 (coLinux)
        Dhcp Enabled. . . . . . . . . . . : No
        IP Address. . . . . . . . . . . . :
        Subnet Mask . . . . . . . . . . . :
        Default Gateway . . . . . . . . . :

We need to bridge the Internet connection with TAP interface. For example, assume you're using an ADSL PPPoE connection. In Windows host, select Control Panel -> Network Connections, right click the PPPoE interface, and select Properties. In tab Advanced, for Internet Connection Sharing, check Allow other network users to connect through this computer's Internet connection, and for the Home networking connection, select the TAP interface (e.g. Local Area Connection 2). When Windows prompts that TAP interface IP address will be set to, choose OK.

Under coLinux, edit file /etc/conf.d/net as follows.

config_eth0=( "" )
routes_eth0=( "default via" )
dns_servers_eth0=(" " )

Please change the DNS server information (shown as xxx above) to those obtained in windows (e.g. via ipconfig).

We have to emphasize here that in this setup, Linux guest has IP address (this is arbitrarily selected, could be other numbers like 192.168.0.x when 2 <= x <= 254), and Windows host has IP address interfacing Linux (of course Windows host has external IP addresses as well).

2.2.2 For two network interfaces

Note this part is NOT compatible with other sections. The purpose of this section is only to document alternatives to above solution. If one interface solution is fine for you, you can skip this section.

This configuration enables both SLiRP and TAP connections. SLiRP is used to connect outside world while TAP enables the high-speed private connection between Windows host and Linux guest, which is desirable for X protocol. The benefits of this configuration includes improved security and that SLiRP can automatically use current Windows Internet connection for outgoing connections (i.e. you do not need to enter DNS server information) without reconfigurations. This works fine for Wireless LANs, but I did meet problems for ADSL and finally decided to use TAP only.

Anyway, let's look at how to setup two network interfaces.

First, we need to modify the aforementioned file gentoo.conf located in coLinux directory. Change the line eth0=tuntap with two lines as below.


Then edit file /etc/conf.d/net on Linux guest. This enables both SLiRP and TAP.

config_eth0=( "dhcp" )
config_eth1=( "" )

We then need to setup DHCP client as following:

emerge dhcpcd
rc-update add dhcpcd default
/etc/init.d/dhcpcd start

Since only eth0 device is generated, we need to generate eth1 device by

cd /etc/init.d
ln -s net.lo net.eth1

On hosting OS (Windows), configure TAP-Win32 Adapter V8 (coLinux) with following properties (make sure to leave Default Gateway as blank):

Ethernet adapter:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : TAP-Win32 Adapter V8 (coLinux)
        Dhcp Enabled. . . . . . . . . . . : No
        IP Address. . . . . . . . . . . . :
        Subnet Mask . . . . . . . . . . . :
        Default Gateway . . . . . . . . . :
2.2.3 Proxy

If you connect to Internet directly, you can skip this section.

To use proxy server, add the following lines into /etc/env.d/99local:


Replace the port and domain name according to your situation. Then run:

env-update && source /etc/profile

2.3 Add additional locales

Modify file /etc/locale.gen, select appropriate locales. For me, the locales are:

en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8

Then run command locale-gen.

2.4 Mirror selection

First run emerge mirrorselect. To select the fastest mirror. I use the following command mirrorselect -D -H -s2 to select the mirror. It means that:

  • -D: actual file will be downloaded from the mirror to test speed.
  • -H: test http mirrors only.
  • -s2: only select 2 mirrors.

After running the command, original /etc/make.conf will be backed up as /etc/make.conf.backup and your selected mirrors will be reflected in make.conf. Type mirrorselect -h for details.

2.5 Modify /etc/make.conf

This is specific for your computer type and other factors. Following is my configuration (I'm using a Core 2 Duo CPU on 32 bit Windows). Please refer to Gentoo documentation for your own reference. GENTOO_MIRRORS reflects the fastest mirrors for my connection, so you may skip that line if your have already performed mirrorselect above.

CFLAGS="-march=prescott -O2 -fomit-frame-pointer -pipe -fno-ident"
LINGUAS="en zh"
USE="-* auctex bash-completion bzip2 cjk crypt curl doc emacs gd gif glibc-omitfp gtk \
     javascript jpeg mmx mozilla ncurses nls nptl nptlonly opengl pam png readline \
     ruby sbcl source spell sse sse2 ssl svg tcpd tiff truetype \
     unicode X xft xml xorg xpm zlib"

2.6 Update system

Since our original system is somehow outdated, we need to update it. First run emerge --sync or emerge-webrsync -v to synchronize portage, then run the following suites of commands (we need the -p argument to check what the commands are supposed to do since they're somehow "dangerous"):

emerge -uDNpv world
emerge -uDNv world
emerge --depclean -pv 
emerge --depclean -v
revdep-rebuild -pv
revdep-rebuild -v

Caveat: if you encounter circular dependency when emerge -uDNv world, try to remove gtk USE flag from /etc/make.conf. After successful emerging, add gtk flag again and run emerge -uDNv world again.

After update, run dispatch-conf to update the configuration files (you need to avoid the update of /bin/setfont. If you accidentally updated the file, you can remedy the situation as discussed below):

Caveat: if during booting, you meet the error message putfont: PIO_FONT: Function not supported, Solve the problem as follows (as discussed here):

First, run command mv /bin/setfont /bin/setfont.old

Create a new file /bin/setfont with the following content:


if ! uname -r | grep -q -e "-co-"
        /bin/setfont.old $@

and make it executable by running chmod +x /bin/setfont

3. Run X is already installed in coLinux machine when we update the system as discussed in section 2.6 (we have include X USE flag). Therefore the remaining steps are just to install X server in Windows host.

We choose Xming considering it is lightweight and widely used. To install Xming, Download Xming installer, font installer and Xming-tools-and-clients. You may use Xming-mesa installer to replace Xming installer for stable OpenGL operation (only do so if you meet problems with Xming installer).

My settings during installation of Xming are as follows:

  • Xming
    • Destination directory: changed to c:\bin\Xming.
  • Xming-fonts
    • Destination directory: changed to the same directory as Xming (c:\bin\Xming)
    • Fonts to be installed: select according to your own taste.
  • Xming-tools-and-clients
    • extract the zip file of Xming-tools-and-clients to the directory where Xming is installed (c:\bin\Xming in this case).

Settings on Windows host

For file x0.hosts in Xming directory, make sure the IP address of coLinux machines ( is added.

If you want to run the tools and clients bundled with Xming in Windows host, you need to type set DISPLAY= in your Windows host.

Following steps are used to enable Windows fonts to be used by X application. This step is optional.

Open a command prompt window, change to directory c:\bin\Xming, and type the following commands:

mkfontscale C:/WINDOWS/Fonts
mkfontscale -b -s -l C:/WINDOWS/Fonts

Make sure that directory C:\Windows\Fonts appeared in the file font-dirs in Xming directory.

On coLinux machine

Add the following line into /etc/profile.

export DISPLAY=

After start Xming (preferably to start it automatically when Windows start), you can simply invoke any command inside Linux console like:

xterm &

4. Miscellaneous

Change host name

According to Gentoo Handbook.

Edit file /etc/conf.d/hostname, if you call your coLinux machine as tux, then set the following line.


Edit file /etc/conf.d/net, if you call your domain as homenetwork, then set the following line.


Remove string .\O from file /etc/issue to get rid of the annoying unknown_domain in the welcome message "This is host.unknown_domain ...".

Create regular user accounts

With the following command, I created a new user named foo as a powerful user (with the ability to su to root and also invoke some portage related commands). Pleas substitute foo above with your desired user name.

useradd foo -m -G users,wheel,portage
passwd foo

Access Windows folder

When we edit gentoo.conf above, we have already enabled coLinux to share folder c:\linux. To make our regular user to access this directory in Linux, edit file /etc/fstab and add the following line:

cofs00  /home/foo/windows  cofs  uid=foo,gid=foo,dmask=0755,fmask=0644 0 0

The above line will enable the Windows folder to be shared in Linux as a folder /home/foo/windows. You can modify above line for your own user.

Additional programs

Following is a list of commands to install my own favorite programs. Your situation would be of course different.

# Some system utilities
emerge gentoolkit slocate

# Development tools
echo "dev-lang/erlang hipe" >> /etc/portage/package.use
emerge aspell ruby sbcl erlang dev-util/git maxima

# Gfx (GLEidescope is one of my favorite XScreenSaver)
emerge inkscape blender xscreensaver

# Netowork
emerge mozilla-firefox

# X tools
emerge xlsfonts xfontsel

Before emerge texlive, I have to add a bunch of keywords for dependencies in /etc/portage/package.keywords as follows.

app-text/texlive ~x86
app-text/texlive-core ~x86
dev-texlive/texlive-metapost ~x86
dev-texlive/texlive-basic ~x86
dev-texlive/texlive-documentation-base ~x86
dev-texlive/texlive-psutils ~x86
dev-texlive/texlive-langcjk ~x86
dev-tex/cjk-latex ~x86
dev-texlive/texlive-documentation-english ~x86
dev-texlive/texlive-genericrecommended ~x86
dev-texlive/texlive-latexrecommended ~x86
dev-texlive/texlive-latex ~x86
dev-texlive/texlive-texinfo ~x86
dev-texlive/texlive-latex3 ~x86
dev-texlive/texlive-htmlxml ~x86
app-text/jadetex ~x86
dev-texlive/texlive-fontsrecommended ~x86
app-text/dvipdfm ~x86
dev-texlive/texlive-documentation-chinese ~x86
dev-texlive/texlive-langmanju ~x86

Use CVS version of Emacs

Run the following commands:

echo "app-editors/emacs-cvs ~x86" >> /etc/portage/package.keywords
emerge emacs-cvs

If you want to use this bleeding-edge version only, you can uninstall the previous version of Emacs (if you have installed) and type:

echo "virtual/emacs ~x86" >> /etc/portage/package.keywords

Otherwise (i.e. you have multiple versions of Emacs), when you emerge packages requiring Emacs, a stable version (e.g. v22.1) will be installed. For the multiple-version-installation, you can use eselect emacs list to see a list of available version. To use Emacs 23 just installed, you can type eselect emacs set emacs-23. For details, please consult here.

Emacs extensions

I run the following commands to install a few Emacs extensions. Note that in Gentoo, many extensions (e.g. those related to development) are automatically installed for you when you emerge the related tools and enable emacs USE flag.

echo "app-emacs/gentoo-syntax ~x86" >> /etc/portage/package.keywords
echo "app-emacs/imaxima ~x86" >> /etc/portage/package.keywords
emerge htmlize imaxima app-emacs/gentoo-syntax keywiz

Enable SSH server

You may want to enable SSH access to your coLinux machine. There are some benefits. Examples are shown below (assuming PuTTY is used):

  • More flexibilities to configure the client (e.g. pretty fonts) and nice scrollbars.
  • The title of PuTTY indicates what coLinux is doing (such information might be useful during a long emerge process).

To start SSH server, type the following commands.

rc-update add sshd default
/etc/init.d/sshd start

When you use PuTTY client, you should fill as the host address to utilize the high speed internal connection.

GTK configrations

Change the default GTK+ font. Edit file ~/.gtkrc-2.0, add the following line, and change the font name and size to your preferred one.

gtk-font-name = "Arial 15"

Mount CD

Simply type the following

# mount -t iso9660 -o ro /dev/hdc /mnt/cdrom

Final Words

coLinux is an interesting way to run Linux applications in Windows host. One drawback of coLinux is that the daemon process is pinned to one processor only. This avoids some bizarre issues, however it does not utilize the potentials of modern multi-core systems. This is disappointing especially for a Gentoo user who requires lots of computation power. Hope the situation could be improved in the future.

Update: please refer this post on how to enable sound.