Installing and configuring LXD on Ubuntu 20.04 and 18.04

In this post I will show you how to install and configure LXD on Ubuntu 20.04 and 18.04.
(Update 21-05-2020: Ubuntu 20.04)

Update Ubuntu:

apt-get update -y && apt-get upgrade -y

Add new user:

adduser <USER>

Apt remove LXD & add the LXD Group:

apt remove --purge lxd lxd-client
groupadd --system lxd
usermod -G lxd -a <USER>

Update the permissions:

newgrp lxd

Install LXD:

snap install lxd

Install zfsutils-linux:

sudo apt-get install zfsutils-linux

LXD initialization process:

sudo lxd init

The installation has been completed. Let’s start with the first container with your <USER>!

Launch Ubuntu 18.04:

lxc launch ubuntu:18.04 CTNAME

Limit the CPU Cores:

lxc config set CTNAME limits.cpu 2

Limit CPU Usage (Max %):

lxc config set CTNAME limits.cpu.allowance 10%

Limit Memory/RAM:

lxc config set CTNAME limits.memory 1024MB

Set disksize to 50GB:

lxc config device add CTNAME root disk path=/ pool=default size=50GB

(Optional) Set disksize for all containers to 50GB:

lxc profile device set default root size 50GB

Stop & start the container

lxc stop CTNAME && lxc start CTNAME

Limit Disk I/O (40MB Read / 20MB Write):

lxc config device set CTNAME root 40MB
lxc config device set CTNAME root limits.write 20MB

Check the configuration:

lxc config show --expanded CTNAME

Set up a route for the container (124.x.x.5/32 = Public Container IP):

lxc network set lxdbr0 ipv4.routes 124.x.x.5/32

Check the routing table:

route -n

Output example:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface         124.x.x.1         UG    0      0        0 enp4s0   U     0      0        0 lxdbr0
124.x.x.1 UH    0      0        0 enp4s0
124.x.x.5 UH    0      0        0 lxdbr0

Login to your container as root:

lxc exec CTNAME bash

Browse to your network cfg’s:

cd /etc/network/interfaces.d

Edit the cfg file:

nano 50-cloud-init.cfg

Add the next line with your public IP-address at the bottom of the cfg file:

post-up ip -4 addr add dev eth0 124.x.x.5/32 preferred_lft 0

Restart the container and you’re ready to go!

lxc restart CTNAME

The installation & configuration has been completed!

2 thoughts on “Installing and configuring LXD on Ubuntu 20.04 and 18.04

  1. hristian

    Hello. Thanks for the instructions. Unfortunately, in my case, it did not change anything. And actually Ubuntu 18.04 I had to install ifupdown because this OS does not use it any longer.

    1. Tom van Brienen Post author

      Hello Hristian,

      Can you tell us more about the situation? You can use netplan in Ubuntu 18.04.
      cd /etc/netplan/
      nano configname.yaml

      Please check:

      What kind of hypervisor do you use?


Leave a Reply

Your email address will not be published.