Skip to content

Instantly share code, notes, and snippets.

@kedazo
Created November 28, 2019 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kedazo/1fd160d2f54640da54ca1c6563009d43 to your computer and use it in GitHub Desktop.
Save kedazo/1fd160d2f54640da54ca1c6563009d43 to your computer and use it in GitHub Desktop.
auto install and configure lxd
#!/bin/bash
# Run this script as root ( or sudo ) and pass username as argument.
# Version v0.1 (initial)
# David Kedves <kedazo@severalnines.com>
USERNAME=$1
apt-get install -y snapd
# /snap/bin must be in path
grep '/snap/bin' /etc/profile 2>/dev/null || echo 'export PATH=/snap/bin:${PATH}' >> /etc/profile
grep '/snap/bin' /root/.bashrc 2>/dev/null || echo 'export PATH=/snap/bin:${PATH}' >> /root/.bashrc
grep '/snap/bin' ~${USERNAME}/.bashrc 2>/dev/null || echo 'export PATH=/snap/bin:${PATH}' >> ~${USERNAME}.bashrc
# also export here in the script as well
export PATH=/snap/bin:${PATH}
# NOTE: apt repo only contains a way old 2.x LXD, we prefer 'snap'
dpkg -P lxd lxd-client || true # get rid of any old version(s) first
snap install lxd || apt-get -y install lxd lxd-client
# pre-seed file for LXD 3.x
cat - > /root/lxdinit.yaml <<EOF
config: {}
# Storage pools
storage_pools:
- name: default
driver: dir
config:
source: /var/lib/lxd/storage-pools/default
# Network devices
networks:
- name: lxdbr0
type: bridge
config:
ipv4.address: auto
ipv6.address: none
# Profiles
profiles:
- name: default
devices:
root:
path: /
pool: default
type: disk
eth0:
name: eth0
nictype: bridged
parent: lxdbr0
type: nic
EOF
cat /root/lxdinit.yaml | lxd init --preseed || lxd init --auto
# add the user to LXD group, so he can use the LXD client 'lxc' command
gpasswd -a ${USERNAME} lxd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment