How to start Xorg-server inside plain chroot?

when I runchroot /somepath /usr/bin/startxI got something what looks like an evdev problem... (I correctly --bind mounted /dev/ /dev/pts /dev/shm /proc /sys /tmp )

The screen is displayed and programs run normally, except I got no mouse nor keyboard and I can't switch to a local terminal, forcing me to hard reboot.

What is the cause of this?
Are there any solution to go ahead by making the server run?

Possible steps to reproduce (work on all distributions):

  • copy the root directory of a Linux distribution to a folder of you running distribution.

  • correctly bind mount everything (/dev/pts /var/run /dev/shm /sys/kernel/debugfs...)

  • run a shell with thechrootcommand.

  • Make sure not any X11 server is already running then launchxinit /usr/bin/some X11 program

You can now hard-reboot your computer! (if you didn't set up any remote access)


Solution 1:

I realize this question is old, but for reference:

The screen is displayed and programs run normally, except I got no mouse nor keyboard and I can't switch to a local terminal, forcing me to hard reboot.

I correctly --bind mounted /dev/ /dev/pts /dev/shm /proc /sys /tmp

In addition to mounting the above, I also had to bind mount /run/udev to make the mouse and keyboard work in my chroot. I did not use an xorg.conf*, and Xorg was able to correctly detect my settings.

Entry in my /etc/schroot/default/fstab:

/run/udev /run/udev none rw,bind 0 0

If you are doing a standard chroot you could obviously put it in your /etc/fstab instead:

/run/udev /path/to/chroot/run/udev none rw,bind 0 0

...or mount --bind it.


*Well-- I tried using an xorg.conf initially, but it didn't work. I also tried adding

Section "ServerFlags" Option "AutoAddDevices" "false" EndSection in xorg.conf, which made my mouse work, but not the keyboard.

Solution 2:

There is an article on Gentoo wiki that details the required procedure :
HOWTO_startx_in_a_chroot.
The article details how to first sett up the chroot, then how to enter the chroot and configure mainsystem.

Another such article comes from Arch Linux :
Running graphical applications from chroot.

More for Ubuntu :
Accessing graphical applications inside the chroot
Creating a chroot jail with sound and X11

For KDE : Kde4schroot. Since that's the one that's demanded, here are some details:

Replace /etc/schroot/schroot.conf with :

# schroot chroot definitions.
# See schroot.conf(5) for complete documentation of the file format.
#
# Please take note that you should not add untrusted users to
# root-groups, because they will essentially have full root access
# to your system.  They will only have root access inside the chroot,
# but that's enough to cause malicious damage.
#
[experimental]
type=directory
description=Debian experimental (unstable)
priority=4
groups=sbuild,root
users=kde4
#root-groups=root,sbuild
aliases=unstable,default
#device=/dev/hda_vg/experimental_chroot
mount-options=-o atime,sync,user_xattr
location=/home/chroot
run-setup-scripts=true
run-exec-scripts=true

Then replace /etc/schroot/mount-defaults :

# mount.defaults: static file system information for chroots.
# Note that the mount point will be prefixed by the chroot path
# (CHROOT_PATH)
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
/dev            /dev            none    rw,bind         0       0
/dev/pts        /dev/pts        none    rw,bind         0       0
tmpfs           /dev/shm        tmpfs   defaults        0       0
/home           /home           none    rw,bind         0       0
/tmp            /tmp            none    rw,bind         0       0

Switch to kde4 user:

su - kde4

Then schroot and type root passwd:

schroot -u root

Add lenny and experimental repositories to /etc/apt/sources.list:

echo "deb http://ftp.us.debian.org/debian experimental main non-free contrib" >> /etc/apt/sources.list
echo "deb http://ftp.us.debian.org/debian lenny main" >> /etc/apt/sources.list

Set up pinning by editing /etc/apt/preferences and adding:

 Package: *
 Pin: release a=experimental
 Pin-Priority: 800
 Package: *
 Pin: release a=unstable
 Pin-Priority: 400
 Package: *
 Pin: release a=lenny
 Pin-Priority: 200

Then run update and install kde4:

aptitude update && aptitude install -t experimental kde4 xorg

Install kdm:

aptitude install -t experimental kdm

Then edit /etc/kde4/kdm/kdmrc and change StaticServers and ReserveServers:

StaticServers=:1
ReserveServers=:2,:3

Or use gdm (gdm will ask to use another display if DISPLAY :0 is already in use.

aptitude install gdm

To run a full kde4 session, go to a text virtual terminal(vt) outside the current X session, for example vt2 (ctrl-alt-F2). To login to a full kde4 session run the following:

su - kde4
schroot
su (use root passwd here)
invoke-rc.d kdm start

And now you should see kdm and should be able to login as kde4 to kde4!
For more details see the above article.