running X applications in your debootstrap chroot

Say you have just make a new chroot environment with debootstrap but now need to run X applications underneath.

The first thing is to not set your display to be simply :0.0 as this will try to use the UNIX socket in /tmp which probably isn't in your chroot.

You need your X server capable of listening on the network, which requires turning off -nolisten tcp. If you usually start X via the startx command you can edit out flag in the /etc/X11/xinit/xserverrc, but if you start from gdm you'll need to look at /etc/gdm/gdm.conf and have a look at the DisallowTCP option.

Once you have restarted your X server should be ready to listen for network connections. In your chroot set your DISPLAY variable to be localhost:0 to force the network socket connection.

At this point you need to sort out allowing access, the easy option is to do something like xhost +localhost to allow yourself to connect.

The only other problem was that debootstrap seems to not make all the devices required. If you see something like

host:/# xterm
xterm: Error 32, errno 2: No such file or directory
Reason: get_pty: not enough ptys

try running MAKEDEV pty in /dev to make the devices you need.

A very handy way of getting things into the chroot environment is to bind mount them. You can do mount --bind olddir newdir to make olddir look just like newdir. This will break through the chroot, which is at times great and at times a security risk. You can make scripts to bind mount in home directories (and even /tmp to avoid the unix socket problem).