Skip to content

Instantly share code, notes, and snippets.

@kennwhite
Last active October 23, 2021 17:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennwhite/be023860ec3150129e694ba4c3d6a7a4 to your computer and use it in GitHub Desktop.
Save kennwhite/be023860ec3150129e694ba4c3d6a7a4 to your computer and use it in GitHub Desktop.
LXC v4 notes (2/2021) for Ubuntu
# Good tips here: https://www.cyberciti.biz/faq/install-lxd-on-ubuntu-20-04-lts-using-apt/
# List all running services
systemctl list-units --all --type=service --no-pager | grep running
# Clean install of lxc (on host) - first lxd system, then lxc command line tools
sudo apt-get update
sudo apt-get upgrade
sudo apt install lxd
sudo adduser YOURUSERID lxd # (probably already there)
sudo apt install lxc-utils
# COMPLETELY NUKE lxc installs and all config/data/containers (on host):
# sudo apt-get purge --auto-remove lxc-utils
# sudo rm -rf /var/lib/lxc/*
# sudo rm -rf /var/cache/lxc/*
# Useful lxc admin commands on Ubuntu (here 20.04):
ls -lh /usr/bin/lxc*
# List all host system network devices, including virtual bridges
ifconfig | grep ': '
lxc init # (defaults are fine, but set storage new loop device size to "100GB", and new bridge to "lxdbr1")
# "available over the network" is asking if you want to make your local LXD service remotely manageable (not on your laptop)
lxc profile list
lxc profile show default
lxc network list
lxc storage list
lxc storage show default
lxc image list images: | grep -i ubuntu
# To create an Ubuntu 20 container
lxc launch images:ubuntu/focal/amd64 ubuntu-focal-c1 # c1 is just convention for container 1
lxc list --fast # (arch, create date, profile)
lxc list # (IP addresses & snapshot count)
lxc exec ubuntu-focal-c1 bash # As root
useradd -m demo # *inside container*
passwd demo
usermod -aG sudo demo
lxc exec ubuntu-focal-c1 -- su -s /bin/bash - demo # As normal user, with proper shell
# TO REMOVE AN INSTALLED CONTAINER: nuke the image, nuke the network, nuke the storage
# Note that "lxcbr0" may be used outside of lxc command line for, e.g., virtmgr, older Docker etc.
# If you *really* want to nuke it:
# sudo brctl delbr lxcbr0
lxc network list
lxc network delete xxxx # (a "MANAGED" network device)
ifconfig lxcbr0 down
lxc-create -t download -n ubuntu20 -- -d ubuntu -r focal -a amd64
lxc list
lxc delete ubuntu-bionic-c4B --force
lxc list
lxc storage list
lxc storage delete default
Error: The storage pool is currently in use
# Push a blank profile to the default, then you can delete all storage
lxc storage delete default
############################
# Create a new Ubuntu 20.04 CLI container
$ sudo lxc-create -t download -n ubuntu20 -- -d ubuntu -r focal -a amd64
Setting up the GPG keyring
Downloading the image index
Downloading the rootfs
Downloading the metadata
The image cache is now ready
Unpacking the rootfs
---
You just created an Ubuntu focal amd64 (20210213_07:42) container.
To enable SSH, run: apt install openssh-server
No default root or user password are set by LXC.
############################
$ lxc list
+-------------------+---------+---------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+-------------------+---------+---------------------+-----------------------------------------------+-----------+-----------+
| ubuntu-bionic-c4B | RUNNING | 10.96.85.111 (eth0) | fd42:cf66:3430:5ff5:216:3eff:fe04:88fb (eth0) | CONTAINER | 0 |
+-------------------+---------+---------------------+-----------------------------------------------+-----------+-----------+
############################
lxc storage info default
info:
description: ""
driver: zfs
name: default
space used: 3.52GB
total space: 289.17GB
used by:
images:
- 7bd2f48db1fda09b1da8682fd2648b7aef12ba14d63724de405bbf1f4e3d34aa
instances:
- ubuntu-bionic-c4B
profiles:
- default
@bitzorbites
Copy link

bitzorbites commented Feb 26, 2021

lxc storage delete default Error: The storage pool is currently in use

# Push a blank profile to the default, then you can delete all storage
lxc storage delete default

push a blank profile? whats the command for that

@falves1
Copy link

falves1 commented Oct 23, 2021

I need exactly this but for Centos 8.
Can it be done?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment