LXC Containers LXD How to Install and Configure Tutorial Ubuntu Debian Mint

If you are using mint, delete the preference that stops snap from installing (as it is required for lxc)

sudo rm /etc/apt/preferences.d/nosnap.pref
 

1. Install lxd:

sudo apt install lxd

Issues install lxd or errors? Click here

Debian at this time does not have lxd so you'll need to use snap:

sudo apt install snapd && sudo snap install core && sudo snap install lxd

*Restart your terminal/SSH session otherwise lxd won't work/be found in the PATH

 2. Configure lxd

lxd init

#defaults are normally fine

You may want to consider changing storage backend to use "dir" which literally means in the existing userspace, rather than relying on loopback devices with a fixed size (eg. like 30GB we made below).

3.) List Available Images for LXC

#note the colon : at the end below, it is needed or it won't show the available images, but rather images on your machine already which will be none at this point

lxc image list images:

This will show ALL images but perhaps it's not what you want, maybe you just want to see what Debian or Ubuntu is available?

lxc image list images:debian:

There's still a lot of images, let's just say we wanted only Debian 10 images shown?

sudo lxc image list images:debian/10

 

4.) Create our first Debian 10 container!

lxc launch images:debian/10 gluster01
Creating gluster01
Starting gluster01        
                  

The above creates a container called "gluster01" with the image "debian/10"

5.) Working with lxc

How can we see what containers are running and what their IPs are?

lxc list

 

Now you can enter and work with gluster01 like this:

Replace gluster01 with your container name.

lxc exec gluster01 bash

 

 

How to Make Config Changes to LXC Containers?

The command below is going to edit the config of container "gluster01" and enable the features security.nesting and security.privileged for more features for other applications like docker.

lxc config set gluster01 security.nesting=1 security.privileged=1
 

 

Issues installing lxd?

snap lxd install error:

snap install lxd
error: cannot perform the following tasks:
- Mount snap "lxd" (23339) (snap "lxd" assumes unsupported features: snapd2.39 (try to update snapd and refresh the core snap))

This will fix it:

snap install core

snap install lxd --channel=latest/stable
Warning: /snap/bin was not found in your $PATH. If you've not restarted your
         session since you installed snapd, try doing that. Please see
         https://forum.snapcraft.io/t/9469 for more details.

lxd 5.4-82d05d6 from Canonical✓ installed

 

 

Make sure that you use the 4.0 or newer track, as 3.0/older is usually not supported/non-existent and will cause the install to fail:

==> Installing the LXD snap from the 3.0 track for ubuntu-20.2
error: requested a non-existing branch on 3.0/stable for snap "lxd": ubuntu-20.2

Manually install with snap like this to fix it/solution:

snap install lxd --channel=latest/stable

2022-05-20T14:12:05-07:00 INFO Waiting for automatic snapd restart...
lxd 5.1-1f6f485 from Canonical✓ installed



Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  snapd
The following NEW packages will be installed:
  lxd snapd
0 upgraded, 2 newly installed, 0 to remove and 377 not upgraded.
Need to get 34.3 MB of archives.
After this operation, 147 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 snapd amd64 2.54.3+20.04.1ubuntu0.3 [34.3 MB]
Get:2 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 lxd all 1:0.10 [5,532 B]
Fetched 34.3 MB in 3s (12.0 MB/s)
Preconfiguring packages ...
Selecting previously unselected package snapd.
(Reading database ... 422832 files and directories currently installed.)
Preparing to unpack .../snapd_2.54.3+20.04.1ubuntu0.3_amd64.deb ...
Unpacking snapd (2.54.3+20.04.1ubuntu0.3) ...
Setting up snapd (2.54.3+20.04.1ubuntu0.3) ...
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.apparmor.service → /lib/systemd/system/snapd.apparmor.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.autoimport.service → /lib/systemd/system/snapd.autoimport.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.core-fixup.service → /lib/systemd/system/snapd.core-fixup.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.recovery-chooser-trigger.service → /lib/systemd/system/snapd.recovery-chooser-trigger.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.seeded.service → /lib/systemd/system/snapd.seeded.service.
Created symlink /etc/systemd/system/cloud-final.service.wants/snapd.seeded.service → /lib/systemd/system/snapd.seeded.service.
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.service → /lib/systemd/system/snapd.service.
Created symlink /etc/systemd/system/timers.target.wants/snapd.snap-repair.timer → /lib/systemd/system/snapd.snap-repair.timer.
Created symlink /etc/systemd/system/sockets.target.wants/snapd.socket → /lib/systemd/system/snapd.socket.
Created symlink /etc/systemd/system/final.target.wants/snapd.system-shutdown.service → /lib/systemd/system/snapd.system-shutdown.service.
snapd.failure.service is a disabled or a static unit, not starting it.
snapd.snap-repair.service is a disabled or a static unit, not starting it.
Selecting previously unselected package lxd.
(Reading database ... 422929 files and directories currently installed.)
Preparing to unpack .../archives/lxd_1%3a0.10_all.deb ...
=> Installing the LXD snap
==> Checking connectivity with the snap store
==> Installing the LXD snap from the 3.0 track for ubuntu-20.2
error: requested a non-existing branch on 3.0/stable for snap "lxd": ubuntu-20.2
dpkg: error processing archive /var/cache/apt/archives/lxd_1%3a0.10_all.deb (--unpack):
 new lxd package pre-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 /var/cache/apt/archives/lxd_1%3a0.10_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

 


Tags:

lxc, containers, lxd, install, configure, tutorial, ubuntu, debian, mintif, mint, delete, preference, installing, sudo, rm, etc, apt, preferences, nosnap, pref, errors, init, defaults, backend, quot, dir, existing, userspace, relying, loopback, devices, eg, gb, images, colon, container, gluster, creating, creates, ips, exec, bash, newer, supported, existent, requested, manually, info, snapd, restart, canonical, installed, lists, dependency, additional, packages, upgraded, newly, mb, archives, disk, http, archive, focal, updates, amd, fetched, preconfiguring, selecting, previously, unselected, database, directories, currently, preparing, unpack, snapd_, _amd, deb, unpacking, symlink, systemd, multi, user, apparmor, rarr, lib, autoimport, fixup, chooser, seeded, timers, repair, timer, sockets, socket, shutdown, disabled, static, lxd_, _all, connectivity, dpkg, processing, var, cache, installation, subprocess, encountered, usr, bin,

Latest Articles

  • How To Upgrade Debian 8,9,10 to Debian 12 Bookworm
  • Linux dhcp dhclient Mint Redhat Ubuntu Debian How To Use Local Domain DNS Server Instead of ISPs
  • Docker dockerd swarm high CPU usage cause solution
  • Docker Minimum Requirements/How Efficient is Docker? How Much Memory Does Dockerd Use?
  • qemu-nbd: Failed to set NBD socket solution qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end-of-file before all bytes were read
  • apache2 httpd apache server will not start [pid 22449:tid 139972160445760] AH00052: child pid 23248 exit signal Aborted (6) solution Mint Debian Ubuntu Redhat
  • How to use the FTDI USB serial cable to RJ45 adapter to connect to the console on Cisco/Juniper Switch Router Firewall in Linux Ubuntu Debian Redhat
  • How To Setup Python3 in Ubuntu Docker Image for AI Deep Learning
  • How to Configure NVIDIA GPUs with Docker on Ubuntu: A Comprehensive Guide for AI Deep Learning CUDA Solution
  • Linux Ubuntu Mint how to check nameservers when /etc/resolv.conf disabled solution
  • Docker cannot work on other overlayfs filesystems such as ecryptfs won't start overlayfs: filesystem on '/home/docker/overlay2/check-overlayfs-support130645871/upper' not supported as upperdir
  • Linux How To Access Original Contents of Directory Mounted Debian Mint CentOS Redhat Solution
  • ecryptfs how to manually encrypt your existing home directory or other directory
  • How to Reset CIPC Cisco IP Communicator for CME CUCM CallManager
  • Internet Explorer Cannot Download File "Your security settings do not allow for this file to be downloaded." Security Settings Solution
  • Linux How To Upgrade To The Latest Kernel Debian Mint Ubuntu
  • Firefox how to restore and backup saved passwords and history which files/location
  • Linux How To echo as root solution to use tee permission denied solution Ubuntu Debian Mint Redhat CentOS
  • Linux how to keep command line bash process running if you are disconnected or need to logout of SSH remotely
  • Linux swapping too much? How to check the swappiness and stop swapping