Skip to content

Instantly share code, notes, and snippets.

@lmlsna
Last active July 10, 2022 00:53
Show Gist options
  • Select an option

  • Save lmlsna/bf6322b9b9977ee31c988315c7d2ddd3 to your computer and use it in GitHub Desktop.

Select an option

Save lmlsna/bf6322b9b9977ee31c988315c7d2ddd3 to your computer and use it in GitHub Desktop.
LXD gui container profile
# Adapted from https://blog.simos.info/how-to-easily-run-graphics-accelerated-gui-apps-in-lxd-containers-on-your-ubuntu-desktop/
#
config:
environment.DISPLAY: :0
raw.idmap: both 1000 1000
user.user-data: |
#cloud-config
runcmd:
- 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
- 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
packages:
- x11-apps
- mesa-utils
- pulseaudio
description: GUI LXD profile
devices:
PASocket:
path: /tmp/.pulse-native
source: /run/user/1000/pulse/native
type: disk
X0:
path: /tmp/.X11-unix/X0
source: /tmp/.X11-unix/X0
type: disk
mygpu:
type: gpu
name: gui
used_by:
#!/bin/bash
# Run once as regular user (with sudo powers) to install profile and map sub(u|g)ids if necessary.
# Check user status
if [ $UID -eq 0 ]; then
echo "Run as sudo-enabled, regular desktop user, not as root."
exit l
fi
# Check sub(u|g)d mapping
if [[ -z "$(grep "root:$UID:1" /etc/sub*id)" ]]; then
echo "root:$UID:1" | sudo tee -a /etc/sub*id
fi
# Cat the above profile yaml file into lxd
cat gui-profile.yaml | lxc profile edit gui
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment