Purpose: We have already seen how to create a debootstrap system and we also learned how to compile a 32-bit application (like Linux kernel) from within the debootstrap system in Debian Linux. However, what we have learnt so far does not allow us to run graphics (X Window) applications from within the debootstrap system i.e. inside the “chroot” environment which is not very helpful. In this post we will learn how to run X windows application from a “chroot” system.

Note: “debootstrap”, “bootstrap” and “chroot” refers to the same thing. Generally as a way of usage of terms, “you chroot into the bootstrap system”. Also it would be a good idea to perform these steps from a regular user account instead of root user account. Here I am assuming that I am using “kushalk” user account to follow these steps.

Step 1: Create a debootstrap system first

The fist step is to create a 32-bit Debian bootstrap system on your host machine. You can follow this link for step-by-step guide on how to do that. You can either create a 32-bit or a 64-bit Debian stable/testing/unstable system. I am assuming that you created a 32-bit Lenny system.

The end result of this step will be that you will have a brand new 32-bit system in the following directory on your host machine:

/home/kushalk/chroots/debian32

Step 2: Trying running an X application

Normally when you try running an X application from a bootstrap system you are like to get error messages.

host# chroot /home/kushalk/chroots/debian32
debian32#  xclock
No protocol specified
Error: Can't open display: :0.0
debian32#

or try configuring a kernel using “xconfig” or “gconfig”:

debian32# make xconfig
scripts/kconfig/qconf arch/x86/Kconfig
No protocol specified
qconf: cannot connect to X server :0.0
make[1]: *** [xconfig] Error 1
make: *** [xconfig] Error 2
debian32#

As you can see from the above examples that we cannot run any graphical (X) applications however we can run any command-line application that does not uses X window system.

Step 3: Bind mount the directories

This is the crux of this entire post. Here are we are going to bind mount some directories from our host system to the bootstrap system.

host# su root
host # nano /etc/fstab

and add the following lines at the end of the file:

/home /home/kushalk/chroots/debian32/home none bind 0 0
/tmp /home/kushalk/chroots/debian32/tmp none bind 0 0
/proc /home/kushalk/chroots/debian32/proc proc defaults 0 0

Save and exit the file.

Basically here we are telling that use the host system directories like “home”, “tmp” and “proc” on your bootstrap system so that our bootstrap system will have access to necessary files in order to launch X windows application. This entire process is called “bind mounting”.

Step 4: Reboot system

There are many ways to make the mount changes take effect but I prefer to just restart the entire system just to make 100% sure that the changes will take effect.

Alternatively you can give the following command instead of rebooting:

host# mount -a

although I have not verified the success rate of above command.

Step 5: Launch the X application from chroot

We are almost there. Now after rebooting just login to your normal user account (in this case ‘kushalk’) and enter into the bootstrap system:

host# chroot /home/kushalk/chroots/debian32
debian32# xclock

and you should see the xclock window being evoked from your bootstrap system. You might get the following warning message when you give the above command:

Warning: Tried to connect to session manager, Authentication Rejected, reason : None of the authentication protocols specified are supported and host-based authentication failed

Simply ignore the message. You should be still able to launch any X window application.

Similarly you can launch the kernel configuration graphic window now:

debian32# cd /usr/src/linux
debian32# make xconfig

and you should be able to see your familiar graphical Linux kernel configuration window and possible the above warning message too.

That’s it. You are now ready to run any kind of graphical X-based programs right from your boostrap system.

Step 6: Un-mount the bind directories
If you observed carefully you can now access all the three directories of your host system on your bootstrap system as if those were part of your bootstrap system. You can always un-mount them if you don’t need them although I don’t see a reason why anybody would do not unless they think they might accidentally delete those directories thinking that they still have a copy of that directory on the host system (see additional notes section below). To un-mount just give the following command:

debian32# umount /tmp

Now try running any X application and you are likely to get an error message:

debian32# xclock
Error: Can't open display: :0.0
debian32#

I hope this gives you a clear idea what is exactly going on. Basically whenever a X server is started it creates some sort of socket files in the “/tmp ” directories so that other application cannot connect to it. Since we “bind mounted” these directories to the bootstrap system we were able to access all those sockets and hence we were able to launch applications.

Additional notes:

1. Just in case if you are still not able to launch X applications and are getting connection error messages than try giving the following command on host and bootstrap system. First try on host system.

host# xhost +

and now give the above commands again. Most likely this will resolve your issue.

2. Also please note that do not delete any directory from your bootstrap system that we have bind mounted. For example, do not delete “home”, “tmp” and “proc” directories from the bootstrap system otherwise those will get deleted from your host system also since they are essentially being mounted from host system in the first place. I guess it would be fine to delete “proc” directory since it is dynamically generated every time the Linux kenrel boots, however I would not risk the system to delete it.

That’s it.

Happy X-windowing in bootstrap system!

Be Sociable, Share!