chroot with X applications

Posted in:

I recently needed to install a second distribution for development purposes, and found that with the great design that Linux has, you can easily use both at once, even with windows from different system and different users appearing side by side on the screen.

There are three basic parts:

  • Setting up a distribution chroot. If the system you want to add is Debian based, this is stupidly easy - just use debootstrap. This got me a basic Debian Sarge system installed in about 10 minutes, including download time!. Since I was developing a KDE app, I then just needed to apt-get install kdebase (or something similar) to get a more complete desktop system installed.

  • Copy or hard-link certain files from the main system to the chroot. This included /etc/passwd, /etc/shadow, /etc/group, and /etc/hosts, though I daresay I could have lived without these. Also, you have to bind your /proc/ mount dir from the main system to the chroot (details in the link below).

  • Get X applications working. There are two basic parts to this (which work automatically when you log in to a local machine, but if you mess around with multiple machines will need some attention, and this is effectively the same case).

    • Applications (clients in the X Window System model) need to know which X Server to talk to, and for that you just need to set the DISPLAY variable correctly. (e.g. if DISPLAY=:0.0, the app will try to place it's window on display 0, screen 0 on the localhost)

    • Second, the X server (on your local machine) needs to allow the client applications access to the screen (and keyboard and mouse). There are various ways to achieve this, one is something like xhost +localhost, another using xauth extract and xauth merge.

      You also need to bind mount /tmp from the main system to chroot to get this working correctly, due to the way X sockets work or something.

I've got my solution to these last bits in a little script, which must be run as root. It means that in seconds, and without using hardly any extra resources, I've got a terminal from which I can run programs within another distribution entirely seamlessly, whether commandline or graphical. It's not a virtual machine (it uses the same kernel and hardware), but it has everything I need from a VM without the disadvantages of one (which are considerable).

Anyway, a proper HOWTO I found, unfortunately after I'd already completed the above, is here:

Development for Multiple Linux Distributions mini-HOWTO.

The main difference I'd note is that if you are testing a Debian distribution, then debootstrap makes the first stages so much quicker and easier - you don't even need to reboot. Since my main system is a Debian based distro, Ubuntu, debootstrap itself was only 5 seconds away (apt-get install debootstrap), but I imagine you can get it for other distros too.)

Comments §

Comments should load when you scroll to here...