Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Since LXC (Linux Containers) is a kernel level super-chroot, I've been wondering what sort of video driver the containers have:

My host is Ubuntu 12.04 64-bit machine with ATI gpu. Will the LXC container have access to the same driver? Or do they need to be installed on each container?

share|improve this question
    
Please share a bit more on what you're trying to accomplish. Are you trying to run GUI applications or even OpenGL-enabled applications in your LXC container? –  gertvdijk Dec 14 '12 at 12:57

3 Answers 3

up vote 2 down vote accepted

Please, take a look at this script to create a LXC container that runs steam with sound and video acceleration:

http://bazaar.launchpad.net/~ubuntu-lxc/lxc/steam-lxc/view/head:/steam-lxc

The magic comes here:

Outside LXC:

    # Add the bind mounts to the container's fstab
    self.container.set_config_item("lxc.mount.entry",
                                   "/tmp/.X11-unix tmp/.X11-unix "
                                   "none bind,ro")
    self.container.set_config_item("lxc.mount.entry",
                                   "/dev/dri dev/dri none bind,ro")
    self.container.set_config_item("lxc.mount.entry",
                                   "%s/pulse.socket home/%s/.pulse_socket "
                                   "none bind,ro" % (self.config_path,
                                                     self.user.pw_name))

We export X11 with a bind mount the /tmp/.X11-unix directory to allow container to use host X11. Do the same with /dev/dri directory and audio socket.

Inside LXC:

    # Get pulseaudio to listen on the socket
    with self.user_privileges():
        subprocess.call(['pactl', 'load-module',
                        'module-native-protocol-unix',
                        'socket=%s' % self.pulse_socket,
                        'auth-cookie-enabled=0'])

    # Start steam
    self.run_command(
        ["steam"], {'DISPLAY': os.environ['DISPLAY'],
                    'PULSE_SERVER': "/home/%s/.pulse_socket" %
                                    self.user.pw_name})

Uses pactl to use a unix socket to communicate with host pulse audio server and later export the socket and DISPLAY environment variable to allow steam to use local X11 server and socket to audio server.

Take a look at the script and enjoy it :)

With that environment variables inside LXC you could play (theoretically) almost all games.

Best regards!

share|improve this answer
1  
interesting. Have you tried to have at least 2 simultaneous containers using HW acceleration? –  lurscher May 21 at 17:03
    
No, I'm currently using Docker (not plain LXC) to run Gazebo 5 containers, I didn't try to run two containers running accelerated applications at once. I'll try it this afternoon and I'll tell you if it works (I think that it'll work). –  OscarGarcia May 25 at 8:00
    
Sorry for the delay. Yes, it is possible to run multiple LXC containers and run simultaneously several accelerated applications. Take a look to this video that I recorded for you: youtu.be/RAUtZBaN1Oo –  OscarGarcia May 26 at 16:04
    
Here is the github repository with the code used in the video: github.com/ojgarciab/docker3d –  OscarGarcia May 26 at 16:21
    
so, create.sh and create2.sh create the two containers and start.sh and start2.shstart each separately. What does make.sh do and in what order should it be run? –  lurscher May 26 at 17:23

Container-based 'virtualisation' technologies such as OpenVZ and LXC don't virtualize any hardware, unlike Xen, KVM, VMware, etc. Another major difference is that LXC/OpenVZ containers are running in the same instance of a single Linux kernel, whereas real virtual machines are running their own kernel.

Because the containers are inside the same kernel and don't manage any hardware, they're 'running' the same driver, yet they don't have any knowlegde about it. All processes are simply chroot'ed and this is completely independent of hardware drivers (kernel modules).

share|improve this answer
    
so, the question is: if i run LIBGL_DEBUG=verbose glxinfo | grep rendering inside the lxc container console, will i see "direct rendering: yes"? –  lurscher Dec 14 '12 at 12:47
    
@lurscher I can't tell what you will see on your hardware. Usually, people are not running anything directly related to hardware in containers. Either way, I think this article might give you some insight. –  gertvdijk Dec 14 '12 at 12:56
    
i mean, i can see direct rendering: yes on the host, but that doesn't translate directly to the container, because the system installation (including the fglrx driver) will not be shared with the containers, right? That article seems to point that at least some direct rendering is possible using the open source driver, which is a good fallback plan for me, but if i could rely on the propietary fglrx ati driver it would be golden –  lurscher Dec 14 '12 at 13:06

To the best of my knowledge the lxc containers will have acess to the driver. check out this site for more info http://libvirt.org/drvlxc.html

share|improve this answer
    
Your link is a page about the Libvirt LXC client/plugin, they call a 'driver'. I don't see any information regarding video drivers or alike. –  gertvdijk Dec 14 '12 at 8:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.