Vservers and X
From Linux-VServer
This page has been made to answer the questions related to running X ( XFree86 and XOrg ) in a Vserver.
There are a few things you might want to do relating to X:
- Run an X server on the physical machine that the Vserver is running on, and log in on the keyboard, mouse, and monitor that are connected to the hardware the host and vserver run on.
- Connect from an Xserver on a different machine, and log into a desktop that is running on the Vserver.
- Run an X server on the host and connect to the vserver (I haven't tried this, but I can't imagine that there would be any problems - this should be pretty much the same as option 2. However, you would need to make sure that running the X server on the host didn't create any security concerns - -nolisten tcp should be used for example.)
- Simply forward X via SSH
Contents |
Running an X server inside a vserver
- Allow capability CAP_SYS_RAWIO. It can be set in the capabilities file or the vserver config depending on your util-vserver. (echo SYS_RAWIO >> bcapabilities)
- Set up a mouse device, such as /dev/psaux or /dev/input/mice (mknod psaux c 10 1)
- Set up a vc/tty device, such as /dev/tty7 or /dev/vc/7 (major 4, minor same as device). If you are running a main X server you might need to use 8 or 9 for the vc/tty device (mknod tty7 c 4 7)
- Set up /dev/kmem (not 100% sure this is needed, don't think X has to have it to run) (note: Xorg on debian sid require a /dev/mem -- NebuchadnezzaR?) (mknod -m 660 mem c 1 1)
- Now just switch to a console, log in as root, enter your vserver and startx, a caveat on newer versions of vserver when switching between a vserver X server and the main server's X server you need to switch :to a console first or you can lose access to the main server's X server.
- You'll also need pts/pty devices to run things like xterm, but if you have ssh set up you probably already have them.
Note: All the stuff below is written from memory - I don't have access to the machine I did this on right now, so I'll have to come back later, and fill in the blanks.
Running X on the HOST from inside a Debian Vserver
This is not meant as a secure implementation - but is a working guide, with the minimum of operations.
- On the HOST, install Xorg - your guest cannot run an environment without the modules/drivers being loaded on the host
apt-get install xorg
- Copy the necessary devices to the Vserver guest
VSERVER=gui2 VSERVER_CONF=/etc/vservers/$VSERVER VSERVER_BASE=/var/lib/vservers/$VSERVER cp -prax /dev/psaux /dev/input /dev/fb0 /dev/tty7 $VSERVER_BASE/dev
- Add capabilities to the guest (to control some of the HOST functionalities)
echo SYS_RAWIO >> $VSERVER_CONF/$VSERVER/bcapabilities
- Start and enter the guest
vserver $VSERVER start vserver $VSERVER enter
- If it is a clean Vserver, then the first package a Debian guest needs is 'locales'. On Squeeze, there is also a bug with the 'keyboard-setup' package, so we install that first
apt-get install locales keyboard-setup
- On Squeeze, the installation will fail and you'll need to edit `/etc/init.d/keyboard-setup`. Remove the 'mountkernfs' and 'udev' directives from the opening 6 lines of the file
- To install LXDE,
aptitude install lxde-core kdm x-window-system xorg xserver-xorg xserver-xorg-input-mouse xserver-xorg-input-kbd apt-get remove xserver-xorg-video-vmware hal apt-get -f install apt-get autoremove
OR
- To install KDE (an error with occur with network-manager, this is normal, follow the instructions below exactly)
aptitude install x-window-system xorg xserver-xorg kde-core kdm xserver-xorg-input-mouse xserver-xorg-input-kbd apt-get remove network-manager xserver-xorg-video-vmware hal apt-get -f install apt-get autoremove
- Then finally, to get the mouse working in the guest, you need to create an 'xorg.conf'. Either use the following command, or if that doesn't work run 'Xorg -configure' on the host, then extract the sections used below (do NOT include screen/display sections).
cat > /etc/X11/xorg.conf <<EOF Section "ServerLayout" Identifier "X.org Configured" InputDevice "Mouse0" "CorePointer" InputDevice "Keyboard0" "CoreKeyboard" EndSection Section "InputDevice" Identifier "Keyboard0" Driver "kbd" EndSection Section "InputDevice" Identifier "Mouse0" Driver "mouse" Option "Protocol" "auto" Option "Device" "/dev/input/mice" Option "ZAxisMapping" "4 5 6 7" EndSection Section "ServerFlags" Option "AllowEmptyInput" "no" EndSection EOF
- Now, exit your guest, and restart it. It should come back on and be running X on the HOST server.
Running an X session on a vserver
For this, you don't need to assign any special capabilities to the vserver, as the vserver won't be running an X server. It will run an Xsession back to your local X server.
In the Vserver:
- Install the xdm package - this is the process that listens on udp/177 for XMDCP requests. You can also use kdm, the package that comes with KDE, or gdm, for Gnome.
- Install your desktop of choice. I used KDE.
- Comment out the local X server in /etc/X11*/?dm/Xservers - if you don't do this, X will try to start and will fail - you will get IOPerm errors in /var/log/Xorg.1.log, and it may stop your display manager from starting. (TODO: check this path)
- Set ListenXDMCP? to true in /etc/kde/.../kdmrc (TODO: check this path)
- Add the line: LISTEN 82.x.y.z to your DM config file (/etc/kde/kdm/kdm-config ? <- TODO: Check this).
Make sure that the you can run [xkg]dm in the vserver. [xkd]dm logs to /var/log, and you can run it with higher debug levels from the command line to work out any problems. Most distros will have an init script to run this from startup.
netstat -plnu | grep :177 should show your ?dm running on udp/177.
Problems I encountered:
- If your ?dm starts, and exits without any errors, this may mean that your greeter program isn't working or installed.
- My konsole program didn't start properly - this was due to /dev/ptmx not being writable by my user - chmod 666 /dev/ptmx as root solved this.
Test it by running X -query w.x.y.z :2 on a remote machine (not the vserver). You should get a grey screen, followed by the login manager for KDE/Gnome/X.
SSH Forwarding X
Using ssh X forwarding to get the gui of the apps you want.
- first make sure your guest has an ip and a hostname.
- install open-ssh server onto the guest.
- edit the file /etc/ssh/sshd_config to include X11UseLocalhost no
- restart the ssh server and make sure that you can logon
- ssh into the guest with 'ssh -X'
- if you can't ssh into the vserver check that your own ssh server is not interfering. if so bind it to your ip.
- check the DISPLAY env. var, it should show you soemthing like myhost.mydomain.com:10.0
- make sure that myhost.mydomain.com resolves to the guest IP
- either configure it via DNS or just add it to /etc/hosts like this:
192.168.0.1 myhost.mydomain.com
- verify with ping myhost.mydomain.com that the resolving works
- start whatever X app you ahve installed (e.g. xeyes, xlogo, xterm ...)