How to Install LXD on Ubuntu 24.04 LTS

Hello Techies, in this blog post, we will explain how to install LXD on Ubuntu 24.04 LTS. We will also demonstrate how to create containers using the lxc command and access the LXD UI.

What is LXD?

LXD is a powerful container manager designed to run Linux containers (LXC) with enhanced functionality. Unlike traditional containers, LXC containers offer virtual machine-like features, including snapshots, storage pools, and advanced networking capabilities. While LXC containers retain data even after being stopped, similar to virtual machines, Docker containers are stateless by default, meaning data isn’t persistent. LXC leverages Linux kernel features like cgroups and namespaces for isolation and resource control. It’s important to note that LXD serves as a management layer, making it easier to manage LXC-type Linux containers efficiently.

Prerequisites

  • A system running Ubuntu 24.04
  • Local user with sudo privileges.
  • An active internet connection.
  • Basic command-line knowledge

Without any further delay, let’s deep dive into the installation steps. Login to your Ubuntu 24.04 LTS system and follow the beneath steps.

1) Update Your System

Install the available updates including security, run the following apt commands.

$ sudo apt update
$ sudo apt upgrade -y

Once all the updates are installed, reboot your system once.

$ sudo reboot

2) Install Snap

Recommended way to install LXD via snap, universal package manager for Linux. Snap typically comes pre-installed on Ubuntu systems, in case it is not installed then you can install it using beneath command,

$ sudo apt install snap -y

Install LXD on Ubuntu 24.04

3) Install LXD On Ubuntu 24.04  LTS

Now install lxd using the following snap command.

$ sudo snap install lxd

Install lxd on Ubuntu 24.04

Output above confirms snap has installed latest and stable version of lxd (5.21). You can also verify the lxd version by running the command.

$ lxd --version
5.21.2 LTS
$

4) Add your Local User to LXD Group

Add your local user to the lxd group so that it can run lxc commands without switching to root or appending sudo.

$ sudo usermod -aG lxd $USER
$ newgrp lxd
$ id
$ lxc list

Add Local User To LXD Group

5) Initialize LXD

Once installed, initialize LXD to configure it for your environment. Use the following command:

$ lxd init

It will ask series of questions, so based on your requirement answer them.

  • When it asks about clustering, choose ‘no’ (unless you’re setting up a cluster)
  • For storage, I recommend saying ‘yes’ to a new storage pool
  • The ‘dir’ backend is fine for beginners
  • Say ‘yes’ to a network bridge
  • Choose ‘yes’ to make LXD sever available over the network.
  • Address to bind lxd , use default
  • Port to bind lxd “8443”

Initialize LXD On Ubuntu 24.04

Once lxd is initialized successfully, we can verify the information using following set of commands.

$ lxc profile list
$ lxc network list
$ lxc storage list

LXC Storage Networking Profile Ubuntu

In order to list all available images, run

$ lxc image list images:

In order to list specific images like Debian or alpine, run beneath commands.

$ lxc image list images: | grep -i 'debian/12'
$ lxc image list images: | grep -i alpine

Output of ‘lxc image list images:’ will show images of containers and virtual machines of the respective Linux distributions.

List LXC Images Ubuntu

6) Allow LXD Network Bridge in Firewall

In case firewall (ufw) is enabled on your ubuntu system, then allow network bridge incoming and outgoing traffic using the following command.

$ sudo ufw allow in on lxdbr0
$ sudo ufw route allow in on lxdbr0
$ sudo ufw route allow out on lxdbr0
$ sudo ufw reload

Allow LXD Network Bridge in UFW Firewall

7) Create Your first container

After initialization, test your LXD setup by launching a container. Syntax to launch a container is shown below:

$ lxc launch remote:image containername

For example, to create and launch an Ubuntu container, run

$ lxc launch ubuntu:24.04 demo-container

This will pull the image locally and will start the container.

Next, run ‘lxc list’ command to view container

$ lxc list

Launch LXC Container On Ubuntu 24.04

To get more help on lxc launch command, run

$ lxc launch --help

8) Manage LXC Containers

Here are some basic commands to manage your LXC containers:

Access the console of container. Run

$ lxc exec demo-container -- bash

Access LXC Container Ubuntu

Stop a container:

$ lxc stop demo-container

Start a container:

$ lxc start demo-container

Delete a container:

$ lxc delete demo-container

9) Access LXD Web UI

If you have noticed carefully, during lxd initialization we have allowed LXD server over the network. It means we can LXD web ui using IP address of your system and port 8443. Make sure port no 8443 is allowed in the firewall.

$ sudo ufw allow 8443/tcp

$ sudo ufw reload

In the web browser, type the following URL:

https://<IP Address of Your Ubuntu System>:8443

As we are using self-signed certificates, so accept the risk and continue.

LXD Web UI Page Ubuntu 24.04

Click on ‘Create a new certificate’, it will take us to the following page,

Generate New Certificate LXD Web UI Ubuntu 24.04

Click on Generate and Choose Skip for adding password to the certificate.

Download CRT And PFX File For LXD UI

Next, Download the crt and pfx files on your system. Transfer crt file to your Ubuntu system and run the following command.

$ lxc config trust add lxd-ui.crt

Add Certificate to LXD Ubuntu 24.04

Head back to browser, follow the screen instructions to import pfx file in your browser.

Import Pfx File on Firefox for LXD UI

After importing the pfx file, refresh browser, click on “Use an existing certificate

Click on Use an existing certificate on LXD Web UI

It will take us to the following screen,

Import Token in LXD Web UI

Generate the token from your Ubuntu system, run

$ lxc config trust add --name lxd-ui

Generate Token for LXD Web UI

Copy the token and paste it in the import field and then click on Import. It takes us now to dashboard as shown below:

LXD UI Dashboard Ubuntu 24.04

Perfect, we can access the LXD UI. Explore it further and have fun 😊

That’s all from this post, I believe you have found it useful and informative. Feel free to post your queries and feedback in below comments section.

 

10 thoughts on “How to Install LXD on Ubuntu 24.04 LTS”

  1. William B Peckham

    So, what if Ubuntu is NOT your distribution of choice? How do you do each of these things for Debian, or Fedora, or Q4OS?

    1. For Debian and Fedora distributions, LXD is installed via snapd, steps are listed below:

      Debian :

      $ sudo apt install snapd
      $ sudo snap install lxd
      $ sudo lxd init

      Fedora :

      $ sudo dnf install snapd
      $ sudo snap install lxd
      $ sudo snap enable lxd
      $ sudo snap services lxd
      $ sudo lxd init

  2. This is fairly clear, but what if I need to expose the containers to my network? Say I do not want to use NAT and I want to be able to access each container from the lan, I cannot find useful/updated information about that for LXC, seems like everyone is happy with nat, but for my purposes is useless, I need them to get an IP adress from my existing DHCP server on my LAN and to access them without accessing the host

      1. lxc profile copy default lanprofile && lxc profile device set lanprofile eth0 nictype macvlan && lxc profile device set lanprofile eth0 parent “ETH PORT”

  3. Simple, eg:
    For bare metal Ubuntu host, you would create a br0 interface referencing your parent ethernet interface.
    Then apply to your LXC profile.

  4. lxc profile copy default lanprofile && lxc profile device set lanprofile eth0 nictype macvlan && lxc profile device set lanprofile eth0 parent “ETH PORT”

  5. EXAMPLE:
    lxc profile show lanprofile
    To start your first container, try: lxc launch ubuntu:18.04

    config: {}
    description: Default LXD profile
    devices:
    eth0:
    name: eth0
    nictype: macvlan
    parent: enp3s0f0
    type: nic
    root:
    path: /
    pool: default
    type: disk
    name: lanprofile
    used_by:

Leave a Comment

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