install lxd on debian

How to Install LXD on Debian 11

In this article, you’ll learn how to install LXD on Debian to manage remote and locate Linux instances. Continue reading this tutorial to learn more about LXD.

LXD Container Manager

LXD Container and Virtual Machine Manager is a container management application to manage local or remote instances. In addition, it offers a simple CLI and REST API for container management. Apart from that, it uses images of various Linux distributions.

Here are some of the features of LXD Container Manager:

  • Easy integrations with several deployment tools 
  • Lightweight containers which are secure by default
  • A great alternative to virtual machines running Linux on Linux
  • Use UEFI and secure-boot by default
  • Can handle up to 50 LXD servers with the same APIs

Apart from these features, LXD containers can run unmodified versions of Debian, Arch, CentOS, Ubuntu, and many other Linux distributions. Furthermore, it can also mimic different cloud platforms, such as AWS, for deployment and testing purposes.

How to Install LXD on Debian

In this section, we’ll discuss the procedure for how to install LXD on Debian. We’ll cover both container and GUI virtual machines. 

Update the Debian Machine

The first step is to update the machine using the APT package manager. Specifically, type:

sudo apt update
sudo apt upgrade


Update debian machine

After that, reboot the machine. For example:

sudo reboot

Install Snap on Debian

Since LXD is not available as a part of the APT package format, you’ll install Snapd first. For this step, use the APT package manager to install Snapd. For instance, type:

sudo apt install snapd


Install Snap on Debian

After that, you’ll install snap core using the snap command as shown below:

sudo snap install core

Next, you’ll add the /snap/bin path in the $PATH variable. Specifically, type:

export PATH=$PATH:/snap/bin

Install LXD on Debian

Once you’ve finished installing Snapd and snap core, you’ll now install LXD. For instance, type:

sudo snap install lxd

Wait for the installation to complete. To ensure that LXD has been installed successfully, type:

lxd --version

Or view the snap list to ensure the LXD installation:

snap list

The output should look something like this:

Add user

Next, execute the command given below to add ZFS support. ZFS is a zettabyte file management system that provides volume management along with file system support. 

codename=$(lsb_release -cs);echo "deb $codename-backports main contrib non-free"|sudo tee -a /etc/apt/sources.list

Once done, update the system and install the following dependencies required for LXD:

sudo apt update
sudo apt install linux-headers-amd64
sudo apt install -t bullseye-backports zfsutils-linux

Add LXD to the User Group

Now, you’ll add the current user to the lxd group, so you don’t need the root privilege to run LXD. For this step, use the adduser command. Specifically, type:

sudo adduser {USER-Name-Here} lxd
# add a regular user named sidrah to group lxd #
sudo adduser sidrah lxd

Furthermore, verify that the user has been added by using the grep command or id command. For instance, type:

id sidrah
grep '^lxd' /etc/group

Lastly, you’ll refresh the Linux group memberships as shown below:

newgrp lxd
id sidrah

Now, you can test the users with the lxc command. For this step, type:

lxc list

Initialize LXD Server on Debian

To start the LXD server, type:

sudo lxd init

You’ll get a series of questions related to the LXD configuration: 

Initialize lxd container

For default options, press the “Enter” key. However, you can also specify your requirements. 

To view the information related to the container, execute:

sudo lxc profile list
sudo lxc profile show default

The output should look like this:

View lxd profile on Debian

In addition, you can also view the information related to the current storage pool as shown below:

sudo lxc storage list
sudo lxc storage show default

To view the network information of the LXD container, type:

sudo lxc network list
sudo lxc network show lxdbr0


View LXD

View LXD Containers on Debian

Once you’ve completed the configuration, it is time to build the containers on LXD. Prebuilt containers are already present in the LXD repository. To view prebuilt images, type:

lxc image list images:

If you want to view a specific distribution image, pipe the grep command after the lxc image command. Specifically, type:

lxc image list images: | grep -i debian
lxc image list images: | grep -i centos
lxc image list images: alpine

You should get a similar output:

View lxd images on debian

Similarly, you can also view several images followed by an “OR” (|) operator. For example:

lxc image list images: | grep -i -E 'centos|ubuntu|opensuse'

Create Containers Using LXD on Debian

Now, to create your first container, you’ll use the launch images command. The syntax looks something like this:

sudo lxc launch images:{distro}/{version}/{arch} {container-name}

For instance, if you want to create a container for Ubuntu and Debian respectively, type:

sudo lxc launch images:ubuntu/focal distroid-con1
sudo lxc launch images:debian/10 distroid-con2


install lxd on debian

Here, you’ve created two containers: distroid-con1 and distroid-con2 respectively. You can also view the containers by executing this command:

sudo lxc list

Furthermore, you can also give shell access to your containers. For this step, type:

sudo lxc exec distroid-con1 bash
sudo lxc exec distroid-con2 bash

You’ll notice that the prompt changes once you’ve granted the shell access. 

Get a Public Cloud Instance Using LXD

Similarly, you can also get a public cloud instance on your LXD container. For this step, launch the container for the particular distribution. The syntax for this command is:

lxc launch -t {type} {os/version} {container-name}
lxc launch -t {type} images:{os/version/arch} {container-name}

For instance, to create an EC2 instance with 1 CPU and 1024 GB RAM having Debian or Ubuntu image and titled as aws-dev-t2-micro-{ubuntu,debian}, you’d type:

lxc launch -t t2.micro ubuntu:22.04 aws-dev-t2-micro-ubuntu
lxc launch -t t2.micro images:debian/11/amd64 aws-dev-t2-micro-debian

You can also verify the existence of containers from the lxc list. Specifically, type:

lxc list

To get the information of a particular cloud instance, use the info command. For instance:

lxc info aws-dev-t2-micro-debian

To exit the container, type:


Manage LXD Containers on Debian

Since you’ve learned how to install LXD on Debian, in this section, we’ll discuss some commands that you can use to manage LXD containers. First, to view the existing running LXD containers, type:

sudo lxc list

However, if you want to view the detailed information about a container, execute the command given below:

sudo lxc info container-name


View lxd container info

Make sure to replace the container-name with the container that you’ve created. 

In addition, if you want to stop a container, use the stop command. Specifically, type:

sudo lxc stop container-name

Again, you’ll have to replace the container-name with your container name.

Furthermore, to view either the STOPPED or RUNNING container, you’ll use these flags. For instance:

sudo lxc list | grep -i STOPPED
sudo lxc list | grep -i RUNNING

You should get a similar output:

install lxd on debian

Apart from that, you can also manually start the LXC containers. For example, to start the distroid-con1, type:

sudo lxc start distroid-con1

Final Thoughts

In this article, you learned how to install LXD on Debian 11. In addition, you also learned to set up and manage LXD Linux containers on Debian machines. For more information, check out the LXD guide.

If this guide helped you, please share it.

Related Posts