Your requirement
You have installed a Linux system under the /test
subdirectory, or mounted the root partition of another Linux system. With the chroot /test
command you can ʻswitch in’ as usual and call programs. But the start of graphical programs fails, even when you set DISPLAY
to :0
.
The problem
Local programs communicate with your computer’s X server via a Unix socket in the /tmp/.X11-unix
directory. In your chroot
environment there is no access to this socket.
The solution
With a mount
command you show the of the ʻouter’ computer’s /tmp/.X11-unix
directory in the chroot
cage:
root@linux# mkdir -p /test/tmp/.X11-unix
root@linux# mount --bind /tmp/.X11-unix /test/tmp/.X11-unix
They also allow access to the display for all local processes:
user@linux> xhost + local:
After calling chroot /test
, set the DISPLAY
variable in the inner system to :0
, and you can then start graphical programs:
root@linux# chroot /test
root@linux# export DISPLAY=:0
root@linux# xterm
By the way: for security reasons a TCP connection via localhost
is switched off by default in most distributions, otherwise instead of the above trick you could take the route via localhost
. Enter xhost + localhost
outside, and export DISPLAY=localhost:0
inside.