There is a lot of interest lately in various virtualisation methods available for linux. These are very flexible and useful especially considering the CPU and memory resources of modern machines.

The venerable chroot virtualisation method is often overlooked though. chroot is a much simpler inbuilt mechanism to unix which can be used when the parallel environments can share the same kernel. Personally I use the chroot method to run an ubuntu (5.10) environment inside my fedora (4) system. I use it for various things, but mainly for developing debian packages on fedora.

Note I have a shared /home partition between fedora core 4 and ubuntu 5.10. This allows the two environments to share the same settings and data, whether they're running in a dual boot configuration, or running in parallel in a chroot configuration which this page discusses. It also allows me to upgrade or add new distributions independently of my data and settings. Since both environment's apps use the same settings from the shared /home partition, they need to be compatible. I haven't found this to be a problem, even with gnome versions 2.10 and 2.12 on redhat and fedora respectively.

The scenario I detail below is booting the system into fedora, and starting ubuntu in a separate partition in the chroot environment. I've also documented the additional possibility of having the chroot image on the same partition. To distinguish the commands used in both systems, I use green for fedora, and gray for ubuntu.

[Update Jan 2011: I noticed a good post on higher level chroot tools like rinse and debootstrap.]

setting up an ubuntu text console

In an xterm (gnome-terminal) on fedora I do the following to create an ubuntu chroot.
sudo cp /etc/resolv.conf /ubuntu/etc/ #Make DNS available to ubuntu
sudo /usr/sbin/chroot /ubuntu         #chroot to ubuntu root partition
mount /proc                           #make /proc virtual filesystem available
mount /sys                            #make /sys virtual filesystem available
mount /home                           #shared home partition between ubuntu and fedora
su - padraig                          #Change user from root to me
. /etc/environment && export LANG     #need to explicitly set locale
For completeness going the other direction and starting a fedora chroot from ubuntu is done using
sudo cp /etc/resolv.conf /fedora/etc/ #Make DNS available to fedora
sudo chroot /fedora                   #chroot to fedora root partition
mount /proc                           #make /proc virtual filesystem available
mount /sys                            #make /sys virtual filesystem available
start_udev                            #make devices available in /dev
mount /home                           #shared home partition between ubuntu and fedora
su - padraig                          #Change user from root to me
A shell is usually all I use, but sometimes I would like to run X applications from within the chroot, which is discussed in the remaining sections.

starting ubuntu X applications on the fedora X server

To get ubuntu X apps to connect to fedora server one needs to enable TCP access to the fedora server. The handiest way to do that is to get ssh to setup the appropriate authorization and connections by doing the following on the fedora system
ssh -Y localhost
In the resulting shell, you can get the appropriate $DISPLAY variable to set in the ubuntu terminal by running the echo $DISPLAY command, and you set that in the ubuntu terminal as follows:
export DISPLAY=localhost:10.0
Any subsequent ubuntu X applications started, will display on fedora's X session.

Note to enable TCP access to the X server always, negating the need for the ssh session above, you can run the following and restart X

GDM_CONF=`find /etc -name gdm.conf 2>/dev/null`
sudo sed -i 's/#DisallowTCP=true/DisallowTCP=false/' $GDM_CONF

starting a separate ubuntu X server

Note I don't do this and I wouldn't really advise it due to the problems mentioned below, but I'm presenting this info anyway for completeness.

To start a completely new X session (on a new Virtual Terminal), use startx -- :1 &. Note to be able to do that from an xterm (the existing fedora X session) one needs to run on the ubuntu system:

sudo sed -i 's/allowed_users=console/allowed_users=anybody/' /etc/X11/Xwrapper.config
startx will allocate a new VT and start the X session on it. To switch between the original X session and the new one use CtrlAltF7 and CtrlAltF8 respectively. I noticed some problems with this though: For a minimal X session one can at least do:
startx /usr/X11R6/bin/twm -- :1&
Some very quick twm usage notes:
© Mar 15 2007