#!/bin/sh # Run inside the container # Install everything an Ubuntu 12.04 LXC container needs to run X with # nvidia proprietary drivers # Caution: it needs the same version of nvidia driver as the host set -e set -x if [ ! -w / ] then echo "Please run as root." exit 1 fi # See https://www.redhat.com/archives/virt-tools-list/2013-April/msg00187.html if [ -e $root/proc/1/environ ] && cat $root/proc/1/environ | tr '\000' '\n' | grep -Eiq '^container='; then echo Running in lxc else echo "Not running in lxc. Please start the container first." exit 1 fi if ! test -c /dev/input/mice then # See e.g. https://lists.linuxcontainers.org/pipermail/lxc-users/2011-April/001817.html # NVIDIA graphics card devices mknod -m 666 /dev/nvidia0 c 195 0 mknod -m 666 /dev/nvidiactl c 195 255 # input devices mkdir /dev/input chmod 755 /dev/input mknod -m 666 /dev/input/mice c 13 63 fi if ! test -f /usr/lib/xorg/modules/input/kbd_drv.so then apt-get update apt-get install -y xinit nvidia-current xserver-xorg-input-kbd xserver-xorg-input-mouse nvidia-settings # Extras like glxgears, xrandr, and xclock apt-get install -y mesa-utils x11-xserver-utils x11-apps fi # See e.g. https://lists.linuxcontainers.org/pipermail/lxc-users/2011-April/001817.html cat > /usr/share/X11/xorg.conf.d/10-lxc-input.conf <<_EOF_ 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 _EOF_ echo "If you like, test mouse input with 'cat /dev/input/mice' to verify you get garbage when the mouse moves" echo "Then create ~/.xinitrc containing the line 'exec x-window-manager', and install a window manager (e.g. sudo apt-get install lwm)" echo "You may need to tell startx you're allowed to run X by changing /etc/X11/Xwrapper.config to say 'anybody' instead of 'console'" echo "Then start X with 'startx -- vt9'" echo "See https://lists.linuxcontainers.org/pipermail/lxc-users/2011-April/001817.html for more tips."