Update #1 (26 December 2019): There is a newer overall post that describes the different ways to run a GUI program in a LXD container. And there is a fresh and simpler post that replaces this one.
Original post continues below…
I like to take care of my desktop Linux and I do so by not installing 32-bit libraries. If there are any old 32-bit applications, I prefer to install them in a LXD container. Because in a LXD container you can install anything, and once you are done with it, you delete it and poof it is gone forever!
In the following I will show the actual commands to setup a LXD container for a system with an NVidia GPU so that we can run graphical programs. Someone can take these and make some sort of easy-to-use GUI utility. Note that you can write a GUI utility that uses the LXD API to interface with the system container.
You are running Ubuntu 19.10.
You are using the snap package of LXD.
You have an NVidia GPU.
Setting up LXD (performed once)
sudo snap install lxd
Set up LXD. Accept all defaults. Add your non-root account to the lxd group. Replace myusername with your own username.
sudo lxd init usermod -G lxd -a myusername newgrp lxd
You have setup LXD. Now you can create containers.
Creating the system container
Launch a system container. You can create as many as you wish. This one we will call steam and will put Steam in it.
lxc launch ubuntu:18.04 steam
Create a GPU passthrough device for your GPU.
lxc config device add steam gt2060 gpu
Create a proxy device for the X11 Unix socket of the host to this container. The proxy device is called X0. The abstract Unix socket @/tmp/.X11-unix/X0 of the host is proxied into the container. The 1000/1000 is the UID and GID of your desktop user on the host.
lxc config device add steam X0 proxy listen=unix:@/tmp/.X11-unix/X0 connect=unix:@/tmp/.X11-unix/X0 bind=container security.uid=1000 security.gid=1000
Get a shell into the system container.
lxc exec steam -- sudo --user ubuntu --login
Add the NVidia 430 driver to this Ubuntu 18.04 LTS container, using the PPA. The driver in the container has to match the driver on the host. This is an NVidia requirement.
sudo add-apt-repository ppa:graphics-drivers/ppa
Install the NVidia library, both 32-bit and 64-bit. Also install utilities to test X11, OpenGL and Vulkan.
sudo apt install -y libnvidia-gl-430
sudo apt install -y libnvidia-gl-430:i386
sudo apt install -y x11-apps mesa-utils vulkan-utils
Set the $DISPLAY. You can add this into ~/.profile as well.
export DISPLAY=:0echo export DISPLAY=:0 >> ~/.profile
Enjoy by testing X11, OpenGL and Vulkan.
ubuntu@steam:~$ glxinfo name of display: :0 display: :0 screen: 0 direct rendering: Yes server glx vendor string: NVIDIA Corporation server glx version string: 1.4 server glx extensions: GLX_ARB_context_flush_control, GLX_ARB_create_context, ...
ubuntu@steam:~$ vulkaninfo =========== VULKANINFO =========== Vulkan Instance Version: 1.1.101 Instance Extensions: ==================== Instance Extensions count = 16 VK_EXT_acquire_xlib_display : extension revision 1 ...
The system is now ready to install Steam, and also Wine!
We grab the deb package of Steam and install it.
sudo dpkg -i steam.deb
sudo apt install -f
Then, we run it.
Here is some sample output.
ubuntu@steam:~$ steam Running Steam on ubuntu 18.04 64-bit STEAM_RUNTIME is enabled automatically Pins up-to-date! Installing breakpad exception handler for appid(steam)/version(0) Installing breakpad exception handler for appid(steam)/version(1.0) Installing breakpad exception handler for appid(steam)/version(1.0) ...
Here is how you install Wine in the container.
sudo dpkg --add-architecture i386
wget -nc https://dl.winehq.org/wine-builds/winehq.key
sudo apt-key add winehq.key
sudo apt update
sudo apt install --install-recommends winehq-stable
There are options to run legacy 32-bit software, and here we show how to do that using LXD containers. We pick NVidia (closed-source drivers) which entails a bit of extra difficulty. You can create many system containers and put in them all sorts of legacy software. Your desktop (host) remains clean and when you are done with a legacy app, you can easily remove the container and it is gone!