# 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)

• @IgnacioVazquez-Abrams : BIND MOUNT! – user2284570 Dec 15 '13 at 18:27
• @MariusMatutiae : Thanks, I've just tried to copy (cp -r --sparse=always /path_to_root/* /mnt) the rootfs to the root of an empty partition (on an USB flash disk) and I booted it directly.... And it work perfectly! (So it is not because some packages/files are missing :-( ). I need to use chroot for mixing the functionalities of two different distro. – user2284570 Dec 16 '13 at 19:24
• At least in my case, the machine isn't completely dead. It just doesn't respond to keyboard/mouse. When I log in remotely, I can kill the offending X server and that's enough to resume normal operation. – Petr Pudlák Jul 6 '14 at 16:33
• @PetrPudlák : Yes, That's was I said "The screen is displayed and programs run normally...". I don't have another machine which I can use for ssh. So my only option is to hard-reboot. – user2284570 Jul 6 '14 at 19:19

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.

• fstab is not a help. It is the same as specifying commands manually. I don't accept answer which say they didn't solve the error. Also, there are no Xorg.conf on gentoo. (If you want to use hand written files, you have to it differently). Last question : how to start a session if you have no virtual keyboard? – user2284570 Aug 2 '14 at 23:56
• I did solve the error. Are you sure you read this answer completely? The soluton was not fstab. The solution for me was to bind mount /run/udev... I also stated I did not use an xorg.conf. Furthermore -- I did state you could also mount --bind it if you wanted to. – transistor1 Aug 3 '14 at 1:05

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.

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.

• Shouldn't this have been a comment instead of an answer? In the best case it's a link only answer. – Cristian Ciupitu Jun 28 '14 at 13:13
• @CristianCiupitu: As I said above, I'm waiting for his feedback in order to flesh it out with the answer for his (unspecified) Linux distribution. – harrymc Jun 28 '14 at 13:42
• The problem is all the links are about plain chroot, while the problem is happening using schroot. Moreover, the second two links talk about how to run a chrooted graphical application on a running X server, while the question is about how to run a standalone X-server inside schroot. I tried to get something out of the first link, but so far I've had no success. (My distribution is Debian Wheezy.) – Petr Pudlák Jun 29 '14 at 9:43
• Some more promising sources : Kde4schroot and chroot jail with sound and X11. Also, have you given thoughts to accounts and permissions? – harrymc Jun 29 '14 at 10:02
• eh, if the original question is in 2013, chances are there's not going to be feedback from the OP. I'd consider having the main points here essential. I'd like to roll back the tag edits however - the instructions are likely to be broadly the same, with distro specific changes and the OP's intentions arn't clear.I'd add that as is, this is a link only answer, and we all tend to hate that. – Journeyman Geek Jun 29 '14 at 14:44