Skip to content
On this page

LXD Installation Guide

If your host does not have an IPV6 subnet and you want to assign IPV6 addresses to containers, then please check the Customize partition in the LXD module for the Attach a free IPV6 address segment to the host, and attach an IPV6 subnet to the host before installing the environment.

One-Click Installation


If this is a new server, make sure that both apt update and apt install curl are working properly before executing this script. It is recommended to pre-install btrfs-progs to speed up the subsequent installation process, after installation it is recommended to reboot the system to load the settings, if it is not pre-installed it is no problem, just follow the prompts to execute the script.


It's recommended to wait for at least 5 minutes after the system boots up before executing the following commands. This is to avoid the script being executed by the default system settings, which could cause issues with apt sources.

  • Prerequisites: Ubuntu 18+ (recommended), Debian 8+ (x86_64 architecture only)
  • The virtual memory here is talking about the size of the SWAP to be opened, and the storage pool is the sum of the sizes of the disks occupied by all your servers to be opened
  • The server needs to be restarted after the environment installation process to load some default configurations
  • By default, lxd's lxcfs-related configuration is enabled, so that in-container querying of container information changes to information about the container itself rather than the host


curl -L -o && chmod +x && bash

Example of initialization configuration:

If there is 18GB of unused disk space on the system disk, after deducting the space already occupied, and you want to allocate 2GB of virtual memory (2048MB of SWAP) and a 15GB storage pool, then following the prompts in the command line, enter 2048 and 15.

Manual Installation

Recommended for beginners to avoid potential troubleshooting. However, if you're experienced and comfortable with debugging bugs, you can also use the above one-click installation method for convenience.

Disable Firewall

apt update
apt install curl wget sudo dos2unix ufw jq -y
ufw disable

Enabling Virtual Memory SWAP

The amount of memory depends on how many instances you want to run. If you want to run 8 instances and calculate, you'll need 2GB of memory. If your actual physical memory is 512MB, you'll need an additional 1.5GB. To be cautious, allocate 2GB of virtual memory.

Execute the following commands: Enter '1', then enter '2048'. This signifies allocating 2GB of virtual memory.


curl -L -o && chmod +x && bash

Installing LXD

Actually, the virtual memory allocated for swap should be twice the size of the actual memory. So, it's reasonable to allocate 1GB if the actual memory is 500MB. The scenario I described above is an excessive allocation.

apt install snapd -y
snap install lxd
/snap/bin/lxd init

If the following error occurs in the above command

(snap "lxd" assumes unsupported features: snapd2.39 (try to update snapd and refresh the core snap))

Use the command patch before installing lxd

snap install core

If there are no exceptions, the results of the above three lines of commands are as follows


Just enter the default for the normal options

Choose the size of the physical disk (hint: select the default option with a minimum of 1GB). Generally, I fill in the available disk space minus the memory size, then multiply by 0.95 and round down. Here, I entered 10GB.

Remember to select 'no' for options containing 'auto' when prompted to update the image, in order to avoid occupying the system.

Test whether symbolic links are functioning in LXC.

lxc -h

If an error is reported then execute the following command to soft connect the lxc command

! lxc -h >/dev/null 2>&1 && echo 'alias lxc="/snap/bin/lxc"' >> /root/.bashrc && source /root/.bashrc
export PATH=$PATH:/snap/bin

After connecting, test the lxc command again to see if there is an error about not being able to find it