Install LXD on Ubuntu

LXD is a tool to manage LXC (Linux Containers). lxd allow you to create and manage lightweight Linux containers, it is like docker, but more like an actual virtual machine. LXD is more user-friendly than using LXC directly, has more features like clustering of servers.

On Ubuntu/Debian, run

apt install -y lxd lxd-client

Before you start using lxd, run

lxd init --auto --storage-backend=dir

Or

lxd init

Just press enter for all questions. Defaults should work. lxd is a demon, only used one time during “lxd init”. After this, you will be using lxc command for everything.

Example

root@b24:~# lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]: 
Name of the storage backend to use (dir, lvm, ceph, btrfs) [default=btrfs]: 
Create a new BTRFS pool? (yes/no) [default=yes]: 
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]: 
Size in GB of the new loop device (1GB minimum) [default=30GB]: 
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: none
Would you like the LXD server to be available over the network? (yes/no) [default=no]: 
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] 
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: 
root@b24:~# 

When it ask for IPv6, I selected “none”, everything else is the default.

To create a container, run

lxc launch ubuntu:22.04 vm-1

Create CentOS container

lxc launch images:centos/7 vm-2

Create Debian 10 container

lxc launch images:debian/10 vm-3

To list all containers, run

lxc ls
lxc list containers

To stop a VM, run

lxc stop VM-NAME

To start VM,

lxc start VM-NAME

To see information about a container

lxc info VM-NAME

Folders

/var/snap/lxd/

To see storage, run

lxc storage ls

All containers share the following disk image.

/var/snap/lxd/common/lxd/disks/default.img
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *