Logo.png
Logo.png

We will ex­plore the syn­tax of man­ag­ing LXC us­ing PVE. Use com­mands that are com­monly used by sys­tem ad­min­is­tra­tors and cover the ba­sics of cre­at­ing, re­mov­ing, and man­ag­ing LXC in PVE.


What's LXC?

LXC is a user space in­ter­face for the Linux ker­nel con­tain­ment fea­tures. Through a pow­er­ful API and sim­ple tools, it lets Linux users eas­ily cre­ate and man­age sys­tem or ap­pli­ca­tion con­tain­ers.


Template Image

Cre­at­ing an LXC in PVE is to down­load a tem­plate im­age. A tem­plate im­age is a pre­con­fig­ured im­age of an op­er­at­ing sys­tem that can be used to cre­ate new LXC quickly.

The first step up­date con­tainer tem­plate data­base:

pveam update

List avail­able im­ages:

pveam available

Also fil­ter the out­put:

pveam available --section system

The fol­low­ing com­mand down­loads a tem­plate im­age of an Ubuntu 22.04 op­er­at­ing sys­tem and saves it in the stor­age pool named "vol­ume01":

pveam download volume01 vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst

List­ing Tem­plate Im­ages
To see a list of all the tem­plate im­ages stored in the stor­age pool named "vol­ume01," use the fol­low­ing com­mand:

pveam list volume01
NAME SIZE
vol­ume01:vztmpl/​ubuntu-22.04-stan­dard­_22.04-1_amd64.tar.zst 123.81MB

Creating an LXC

Now that we have a tem­plate im­age, we can cre­ate a new LXC.

pct create 403 volume01:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst \
  --storage volume01 --rootfs volume=volume01:16 \
  --ostype ubuntu --arch amd64 --password P@ssw0rd --unprivileged 1 \
  --cores 2 --memory 1024 --swap 0 \
  --hostname lxc-ubuntu \
  --net0 name=eth0,bridge=vmbr0,ip=dhcp,firewall=1,type=veth \
  --start true

Con­fig­ur­ing the LXC

ParameterDescription
pct createcreates a new LXC with ID 403 and the image from the storage "volume01.
--storage volume01specifies the storage pool to be used for storing the LXC's disks.
--ostype ubuntu --arch amd64specify the operating system and architecture of the LXC.
--password P@ssw0rd --unprivileged 1set the root password for the LXC and enable unprivileged mode.
--cores 2 --memory 1024 --swap 0specify the number of CPU cores, amount of memory and swap space allocated to the LXC.
--hostname lxc-ubuntuThis option sets the hostname of the LXC to "lxc-ubuntu".
--net0 name=eth0,bridge=vmbr0,ip=dhcp,firewall=1,type=veththe interface name set to eth0 and bridge to vmbr0 from the host, enable firewall and the network type value is: veth.
--start trueThis option starts the LXC after it has been created.

about veth

This type of net­work in­ter­face al­lows the LXC (con­tainer) or vir­tual ma­chine to com­mu­ni­cate with other de­vices on the net­work as if it were a phys­i­cal de­vice on the net­work. The veth in­ter­face also al­lows for net­work iso­la­tion be­tween dif­fer­ent LXC or vir­tual ma­chines run­ning on the same host sys­tem.

Launch a shell for the LXC

En­ter the con­tainer:

pct enter 403

Up­date the sys­tem:

apt update && apt upgrade

In­stall some pack­ages:

apt install -y curl git tmuxvim

Set Vim as de­fault ed­i­tor:

update-alternatives --set editor /usr/bin/vim.basic

Cre­ate user:

useradd -m user -s /bin/bash

Switch to user:

su - user

Cleaning up

Stop the LXC

pct stop 401

De­stroy­ing an LXC

To re­move an LXC from the sys­tem, use the fol­low­ing com­mand:

pct destroy 401 --purge

This com­mand de­stroys the LXC with ID 401 and re­moves its con­fig­u­ra­tion files from the sys­tem.

Re­mov­ing a Tem­plate Im­age
If you want to re­move a tem­plate im­age from the stor­age pool, use the fol­low­ing com­mand:

pveam remove volume01:vztmpl/vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst

Conclusion:

We cov­ered the ba­sics of man­ag­ing LXC in Prox­mox Vir­tual En­vi­ron­ment (PVE).

Looked at how to down­load a tem­plate im­age, cre­ate an LXC, and con­fig­ure it with var­i­ous op­tions. We also saw how to re­move an LXC from the sys­tem.

PVE of­fers many more com­mands and op­tions for man­ag­ing LXCs, and we en­cour­age you to ex­plore them fur­ther to get the most out of this pow­er­ful vir­tu­al­iza­tion plat­form.


Reference:


Related: