[Lxc-users] [lxc-users] Do someone success in installing X in a lxc container ?

John lxc at jelmail.com
Fri Apr 22 10:14:28 UTC 2011


On 22/04/11 07:49, Franck BUCHERON wrote:
> Hi,
>
> I tried some experimentations found on the web, but even if X 
> installation is ok, the vt7 can't be opened.
>
> Regards,
>
> F. BUCHERON
>
>
> ------------------------------------------------------------------------------
> Fulfilling the Lean Software Promise
> Lean software platforms are now widely adopted and the benefits have been
> demonstrated beyond question. Learn why your peers are replacing JEE
> containers with lightweight application servers - and what you can gain
> from the move.http://p.sf.net/sfu/vmware-sfemails
>
>
> _______________________________________________
> Lxc-users mailing list
> Lxc-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-users
Yes I have done this. Perhaps the following may help: I use Arch Linux 
so my notes relate to that.

This provides a containerised desktop environment that uses the host’s 
hardware. The Desktop runs on one of the host’s virtual terminals. You 
can have multiple isolated environments that can be switched between 
using the hosts’s Alt+Fn virtual terminal switch.

Set up a basic container and then:

Create the device node the virtual terminal to be used for the desktop.

# mknod -m 666 /srv/lxc/mycontainer/dev/tty9 c 4 9

Create the device nodes for the graphics card.

# mknod -m 666 /srv/lxc/mycontainer/dev/nvidia0 c 195 0
# mknod -m 666 /srv/lxc/mycontainer/dev/nvidiactl c 195 255

Create the device nodes for the input devices

# mkdir /srv/mycontainer/dev/input
# mknod -m 666 /srv/lxc/mycontainer/dev/input/mice c 13 63

Add a rule to the container’s configuration file 
|/etc/lxc/mycontainer.conf| to allow access to the host’s virtual 
terminal, graphics card and input devices.

# XOrg Desktop
lxc.cgroup.devices.allow = c 4:9 rwm    # /dev/tty9 X Desktop
lxc.cgroup.devices.allow = c 195:* rwm  # /dev/nvidia Graphics card
lxc.cgroup.devices.allow = c 13:* rwm   # /dev/input/* input devices

*Ensure that the |lxc.tty| setting is less than the tty number allocated 
for the desktop (9 in above example) otherwise the host’s /dev/tty9 
device will not be accessible by the container. *

Update the container

# lxc-destroy -n mycontainer
# lxc-create -f /etc/lxc/mycontainer.conf -n mycontainer

Start and enter the container. Log in as root.

# lxc-start -n mycontainer
# lxc-console -n mycontainer


        XOrg installation

Install XOrg and the graphics driver

# pacman -S xorg nvidia

Xorg normally uses evdev to locate input devices but it can not be used 
inside a container because it sits on top of udev. Therefore, a 
configuration file is required to disable auto device detection and to 
provide input device configuration. Create the file 
../etc/X11/xorg.conf.d/10-input.conf..:

Section "ServerFlags"
         Option "AutoAddDevices" "False"
EndSection

Section "ServerLayout"
     Identifier     "Desktop"
     InputDevice    "Mouse0" "CorePointer"
     InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
     Identifier "Keyboard0"
     Driver "kbd"
     Option "XkbLayout" "gb"
EndSection

Section "InputDevice"
     Identifier "Mouse0"
     Driver "mouse"
     Option "Protocol" "auto"
     Option "Device" "/dev/input/mice"
     Option "ZAxisMapping" "4 5 6 7"
EndSection

The entry in the file for “XkbLayout” changes the keyboard layout from 
the default US layout and is only required if the default US keyboard is 
not wanted.

Alternatively, the way to change layouts at run time is to use setxpbmap:

# setxkbmap gb

However note that only lasts for that X session.

Because Xorg is not using evdev, the mouse and keyboard drivers must be 
loaded:

# pacman -S xf86-input-{keyboard,mouse}

Start X on virtual terminal 9

# startx -- vt9

To test the mouse device just do |cat /dev/input/mice| from a command 
prompt. Correct operation just gives garbage output when the mouse is moved.

use the nvidia-settings tool to create a configuration file. Install the 
nvidia utilities

pacman -S nvidia-utils gtk2

gtk2 is a dependency but did not get picked up so has been included on 
the command line explicitly.

Use the ..nvidia settngs.. utility to properly configure the display 
hardware and save a new configuration file. The default location, 
/etc/xorg.conf is being deprecated by Xorg so save the file as 
/etc/X11/xorg.d/21-nvidia-settings.conf.


      Login Manager

The container can start an X login manager when it boots. This example 
uses Slim <http://slim.berlios.de/>, the Simple login manager.

Install Slim:

pacman -S slim

Edit ../etc/inittab.. to start the system in run level 5:

## Only one of the following two lines can be uncommented!
# Boot to console
#id:3:initdefault:
# Boot to X11
id:5:initdefault:

and to start slim when in runlevel5:

x:5:respawn:/usr/bin/slim>/dev/null 2>&1

Configure ../etc/slim.conf.. so that slim starts on the desired vt (line 
5 in the file):

xserver_arguments   -nolisten tcp vt09

When the container is restarted, the X login panel should appear.

Automatic Login to X

The container can as a specific user and start their X session when it 
boots.

Edit ../etc/inittab.. to start the system in run level 5:

## Only one of the following two lines can be uncommented!
# Boot to console
#id:3:initdefault:
# Boot to X11
id:5:initdefault:

and to automatically log in a specific user:

x:5:once:/bin/su john -l -c "/bin/bash --login -c /usr/bin/startx -- vt10>  /dev/null 2>&1"

When the container is restarted, the user’s X session should appear.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxcontainers.org/pipermail/lxc-users/attachments/20110422/534c7e1b/attachment.html>


More information about the lxc-users mailing list