apt remove lxd lxd-client
snap install lxd

# create zfs dataset on pool rpool
zfs create rpool/lxd

# create lxd storage called zfspool using previous defined dataset
lxc storage create zfspool zfs source=rpool/lxd

# define default storage pool
lxc profile device add default root disk path=/ pool=zfspool

# initialize network
sudo lxd init

Because group membership is only applied at login, you then either need to close and re-open your user session or use the “newgrp lxd” command in the shell you're going to interact with lxd from

newgrp lxd
lxc-prepare (chmod +x)
lxc image show $ALIAS >/dev/null 2>&1
if [ ! $? = 0 ]; then
    echo lxc image copy images:ubuntu/xenial/amd64 local: --alias xenial
    exit 0
if [ ! -f /etc/apt/apt.conf.d/proxy.conf ]; then
    sudo apt install apt-cacher-ng
    PROXY=$( lxc network show lxdbr0 | sed -n 's/\s\+ipv4.address: \([0-9\.]\+\).*/\1/p' )
    echo "Acquire::http::Proxy \"http://$PROXY:3142\";" | sudo tee /etc/apt/apt.conf.d/proxy.conf
    echo "PfilePattern = .*" | sudo tee -a /etc/apt-cacher-ng/acng.conf
    echo "PassThroughPattern: .*" | sudo tee -a /etc/apt-cacher-ng/acng.conf
    systemctl restart apt-cacher-ng
lxc info $NAME >/dev/null 2>&1
if [ ! $? = 0 ]; then
    lxc launch $ALIAS $NAME
if [ -f /etc/apt/apt.conf.d/proxy.conf ]; then
    lxc file push /etc/apt/apt.conf.d/proxy.conf $NAME/etc/apt/apt.conf.d/
lxc file push /etc/inputrc $NAME/etc/

list remote images

lxc image list images:

auto update remote images

lxc config set images.auto_update_cached true

import image

lxc image copy images:ubuntu/xenial/amd64 local: --alias xenial

create profile

lxc profile create juju-default
cat profile.yaml | lxc profile edit juju-default


name: juju-default
  boot.autostart: "true"
  security.nesting: "true"
  security.privileged: "true"
  linux.kernel_modules: openvswitch,nbd,ip_tables,ip6_tables
    mtu: "9000"
    name: eth0
    nictype: bridged
    parent: br-mng
    type: nic
    path: /dev/kvm
    type: unix-char
    path: /dev/mem
    type: unix-char
    path: /
    type: disk
    path: /dev/net/tun
    type: unix-char

create container from local image

lxc image list
lxc launch xenial test1 --profile juju-default

create container from remote image

lxc launch images:ubuntu/xenial/amd64 xenial1
lxc config set xenial1 boot.autostart false
lxc list

create custom image from local container

lxc publish local-container --alias mycustomimage

create container from previous image

lxc launch mycustomimage newcontainer

bash inside

lxc exec trusty1 -- /bin/bash

stop and delete

lxc stop trusty1
lxc delete trusty1

autostart on host boot

lxc config set <name> boot.autostart true

show container configuration

lxc config show <name>


apt install apt-cacher-ng
lxc file push /etc/apt/apt.conf.d/proxy.conf $NAME/etc/apt/apt.conf.d/
Acquire::http::Proxy "";
lxc network create br0
lxc network show br0
lxc network edit br0

static IP container


lxc stop $instance
lxc network attach lxdbr0 $istance eth0 eth0
lxc config device set $istance eth0 ipv4.address
lxc start $istance

prepare lxd server

# bind to port 8443
lxc config set core.https_address "[::]" 

# password
lxc config set core.trust_password some-password

from client add remote server

lxc remote add myserver <ip address or DNS>

run command

lxc exec myserver:trusty1 -- bash

create container

lxc launch images:ubuntu/bionic/amd64 $NAME

install simpler X program

lxc exec $NAME -- apt install xterm
lxc exec $NAME bash
apt install mesa-utils x11-apps
# lxc config set $NAME environment.DISPLAY <ip-of-host-lxdbr0-bridge>:0
lxc config set $NAME environment.DISPLAY :0
lxc config device add $NAME X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0
lxc config device add $NAME Xauthority disk path=/root/.Xauthority source=${XAUTHORITY}

for gmd (ubuntu >= 17.10) or …


… or for lightdm

xserver-command=X -listen tcp

add ip of container on /etc/X0.hosts

lxc info $NAME | sed -n "s/\s*eth0:\s*inet\s\([0-9\.]*\).*/\1/p" >> /etc/X0.hosts

launch X application in container

xhost +
lxc exec $NAME -- xterm
lxc config device add <name> rfxcom unix-char path=/dev/ttyACM0
lxc config device set <name>  rfxcom  mode 666
# only first time
echo "root:$UID:1" | sudo tee -a /etc/subuid
echo "root:${id -d}:1" | sudo tee -a /etc/subgid
lxc profile set default security.privileged true

# for every share 
# lxc init stretch giano
lxc config set gianocop security.privileged true
lxc config set giano raw.idmap "both $UID $UID"
# source is on host, path is inside container
lxc config device add giano develop disk source=/mnt/giano path=/mnt/giano

on host-destination

lxc config set core.https_address
lxc config set core.trust_password PASSWORDhere

on host-origin

# add destination lxd
lxc remote add other-server <ip-address>

# take snap0 on gianocop container
lxc snapshot gianocop snap0
lxc copy gianocop/snap0 other-server:gianocop --verbose
lxc delete gianocop/snap0

on host-destination delete volatile in “lxc config”

volatile.base_image: 6adc9ca1a1124ebd954ba787e83dd9318866fd0b9ddce1cffc612559cfe3bc88
  volatile.eth0.hwaddr: 00:16:3e:50:f6:e8
  volatile.eth0.name: eth0
  volatile.idmap.base: "0"
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.idmap: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":true,"Isgid":false,"Hostid":166537,"Nsid":1001,"Maprange":64535},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":1000},{"Isuid":true,"Isgid":true,"Hostid":1000,"Nsid":1000,"Maprange":1},{"Isuid":false,"Isgid":true,"Hostid":166537,"Nsid":1001,"Maprange":64535}]'
  volatile.last_state.power: STOPPED
apt-get install vlan 
sudo modprobe 8021q 
sudo vconfig add eth1 10 
sudo ip addr add dev eth1.10 
ip addr del dev eth0 
sudo ip link set up eth1.10
 sudo su -c 'echo "8021q" >> /etc/modules'
auto eth1.10
iface eth1.10 inet static
    vlan-raw-device eth1 

On image hosts

lxc publish --force 'name of container" --alias 'new name' 


lxc publish --force 'lxc-limesurvey' --alias 'lxc-docuwiki' 

Export image

lxc image  export 'new name' 

Output is in efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz Show size of export

du -h efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz 
md5sum efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz > exportmd5.txt

cat exportmd5.txt | nc 1234

cat efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz | nc 1234

NB: is your new lxd host

1234 is a free port

nc -l 1234 > efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz
nc -l 1234 > exportmd5.txt 

check file

md5sum efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz 
md5sum -c exportmd5.txt 
 lxc image import efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz --alias lxc-docuwiki 

Transferring image: 100%

lxc launch image_name container_name 

Creating container_name Starting container_name

In some instances the publish command may lead to a split xz tar-ball — but both formats are supported. Simply import the meta-data and rootfs components with

  lxc image import <metadata tarball> <rootfs tarball> --alias image_name

Edit LXD default profile: networking

Put lxc network interface to host network

lxc stop lxc-docuwiki 
lxc profile device set default eth0 parent ens3
lxc profile device set  default eth0 nictype macvlan
service lxd restart
service lxd-containers restart 

launch your container

lxc start lxc-docuwiki 
lxc exec lxc-docuwiki /bin/bash
  • tips/lxd.txt
  • Last modified: 2019/11/19 19:12
  • by scipio