LXC/LXD Setup Cheatsheet

From: Getting started with LXD Containerization (Full Guide!)

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.

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

2. Add the user to the sudo group

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.

sudo apt install snapd

Verify snap is installed.

which snap

6. Look at the snap packages that may 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 "lxc".

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

Useful Host Tools, Etc

sudo apt install ufw