How to deploy LXD on CentOS 7 with Snap

Posted on 312 views

LXD is a next generation system container manager built around a very powerful REST and offers a user experience similar to virtual machines but using Linux containers instead. LXD uses pre-made Linux images which are available for a wide number of Linux distributions.

In this guide, I’ll show you simple steps to install and use LXD on CentOS 7 server/Desktop. The installation will make use of Snap, which was covered on How to Install Snapd and Snap applications on CentOS 7 guide.

Features of LXD

From the official LXD website, these are the biggest features of LXD are mentioned:

  • Secure by design (unprivileged containers, resource restrictions and much more)
  • Scalable (from containers on your thousands thousand of compute nodes)
  • Intuitive (simple, clear API and crisp command line experience)
  • Image-based (with a wide variety of Linux distributions published daily)
  • Support for Cross-host container and image transfer (including live migration with CRIU)
  • Advanced resource control (cpu, memory, network I/O, block I/O, disk usage and kernel resources)
  • Device passthrough (USB, GPU, Unix character and block devices, NICs, disks, and paths)
  • Network management (bridge creation and configuration, cross-host tunnels, …)
  • Storage management (support for multiple storage backends, storage pools, and storage volumes)

How to Install LXD on CentOS 7 with Snap

Now let’s start the installation of LXD on CentOS 7 by following the steps below

Step 1: Install snapd on CentOS 7

You need to install snapd which will provide snap command line tool used to install LXD package. Install snapd on CentOS by following the guide How to Install Snapd and Snap applications on CentOS 7

Once you have snapd installed, go to step 2

Step 2: Configure Kernel Parameters

Some Kernel options are required by LXD to be enabled on the system. Configure them by running the following commands on your terminal. Run these commands as root user.

grubby --args="user_namespace.enable=1" --update-kernel="$(grubby --default-kernel)"
grubby --args="namespace.unpriv_enable=1" --update-kernel="$(grubby --default-kernel)"
echo "user.max_user_namespaces=3883" > /etc/sysctl.d/99-userns.conf

You’ll need to reboot the system after making the changes.

sudo reboot

Once the system is up, proceed to step 3

Step 3: Install ZFS (Optional)

If you would like to use ZFS with your LXD containers, you need to install it. If you’re not using ZFS, skip this step.

sudo yum install
sudo yum-config-manager --disable zfs
sudo yum-config-manager --enable zfs-kmod
sudo yum install zfs

Step 4: Install the lxd snap on CentOS 7

Finally, install LXD snap from snap store

$ sudo snap install lxd
lxd 3.4 from 'canonical' installed

The installation should take short time if you have a good internet connection. You can confirm package installation using:

# snap list
Name        Version    Rev   Developer             Notes
core        16-2.34.3  5145  canonical             core
lxd         3.4        8415  canonical             -

# snap services
Snap   Service  Startup   Current
lxd    daemon   enabled   active

Step 5: Launching a test LXD container

Let’s add our user account to the grouplxd for it to manage LXD containers without permission errors.

sudo usermod -aG lxd jmutai
sudo newgrp lxd

Configure LXD environment using

$ sudo 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 (btrfs, ceph, dir, lvm) [default=btrfs]: 
Create a new BTRFS pool? (yes/no) [default=yes]: 
Would you like to use an existing block device? (yes/no) [default=no]: 
Size in GB of the new loop device (1GB minimum) [default=15GB]: 
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]: 
Would you like LXD 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]:

A listing of containers should return an empty list

# lxc list

Create a test CentOS 7 container by running:

# lxc launch images:centos/7/amd64 cent7
Creating cent7
Starting cent7

Launch Ubuntu container by running:

# lxc launch ubuntu:18.04 ubuntu18
Creating ubuntu18
Starting ubuntu18

List your containers:

# lxc list
|   NAME   |  STATE  |         IPV4          |                     IPV6                     |    TYPE    | SNAPSHOTS |
| cent7    | RUNNING | (eth0) | fd42:4c5:f0c7:1550:216:3eff:fe8f:8fdf (eth0) | PERSISTENT |           |
| ubuntu18 | RUNNING | (eth0) | fd42:4c5:f0c7:1550:216:3eff:fe2c:a03 (eth0)  | PERSISTENT |           |

Stop, start, restart, delete, check info a container

lxc start container
lxc stop container
lxc restart container

Get info about a container using info command option

lxc info container

Sample output:



For more command line options, run

lxc --help
lxc command --help e.g lxc start --help

You have successfully installed LXD on CentOS 7 from snap and created an lxc container. Thanks for using our guide. If you have any issue, don’t hesitate to drop a comment.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.