LXC/LXD Setup

The following setup steps are done on the Linux system where you will create and run LXC containers. The steps assume you are using ssh to access a remote system.

There are many Linux distros available; I use Linux Mint. To see my initial desktop configuration click HERE ..

0. Logon to the Linux host system (server)

ssh mylxcserver
...

1. Create a user (non-root) account

Do not run as root. Create a regular account to execute LXC/LXD operations.

whoami
adduser tommy

Note: Depending how things were install, you may already be in a non-root account. Is it going to be your LXD account? (Remember this is a test/learning server, not the real thing.)

2. Add the user to the sudo group

sudo usermod -aG sudo tommy

3. Switch to non-root user

su - tommy

4. Update all packages on the server

sudo apt update && sudo apt dist-upgrade

If packages were install, reboot to get a fresh system.

sudo reboot

5. Install snapd

This install method may not work on your Linux system. You may need to research the proper steps to install snapd for your Linux distribution.

Is snap already installed?

which snap

NO, install the snapd package

From Linux Mint 20 onward, installing Snap is blocked by a file called nosnap.pref in the directory /etc/apt/preferences.d/. This file needs to be removed from the directory before Snap can be installed. Perhaps save it somewhere so it can be restored if needed?

cd /etc/apt/preferences.d sudo mv nosnap.pref somewhere-safe

sudo apt update

sudo apt install snapd

Verify snap is installed.

which snap

6. List at the snap packages that are already be installed

snap list

7. If LXD is not already installed, install it

sudo snap install lxd

When you install LXD, it sets up a system-wide daemon that provides a REST API for managing Linux Containers (LXC). It also installs the lxc command-line tool, which allows you to interact with the daemon and manage your containers.

8. Which version of lxd are you using?

lxd version

or
snap info lxd | grep installed

9. Add user account to the LXD group

This will enable you to interact with LXC without using sudo or root.

groups sudo usermod -aG lxd tommy groups

Note: The "groups" command shows which groups the current account is in. It should include "sudo" and "lxd".

10. Logout, then login

This will insure the account you are using has all of the group memberships and the proper privileges.

logout ssh mylxcserver ...

Note: You can also accomplish this by rebooting and logging in.

11. Display all snap packages currently installed

snap list

12. Initialize lxd

For learning purposes and to get started quickly select the defaults except were specified; i.e. always select the default except for storage backend. (To select a default enter nothing.)

sudo lxd init Would you like to use LXD clusters? (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(zfs, ceph, btrfs, dir, lvm) [default=zfs]: dir 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 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]:

Congrats, you are now setup to use LXC/LXD

Limit Container Resources?

You may want to limit the system resources available to containers. For more information, click this link: Setting CPU Resource Limits With LXC

Useful Tools

sudo apt install ufw