We will explore the syntax of managing LXC using PVE. Use commands that are commonly used by system administrators and cover the basics of creating, removing, and managing LXC in PVE.
What’s LXC?
LXC is a user space interface for the Linux kernel containment features. Through a powerful API and simple tools, it lets Linux users easily create and manage system or application containers.
Template Image
Creating an LXC in PVE is to download a template image. A template image is a preconfigured image of an operating system that can be used to create new LXC quickly.
The first step update container template database:
|
|
List available images:
|
|
Also filter the output:
|
|
The following command downloads a template image of an Ubuntu 22.04 operating system and saves it in the storage pool named “volume01”:
|
|
Listing Template Images To see a list of all the template images stored in the storage pool named “volume01,” use the following command:
|
|
NAME SIZE volume01:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst 123.81MB
Creating an LXC
Now that we have a template image, we can create a new LXC.
|
|
Configuring the LXC
Parameter | Description |
---|---|
pct create | creates a new LXC with ID 403 and the image from the storage “volume01. |
--storage volume01 | specifies the storage pool to be used for storing the LXC’s disks. |
--ostype ubuntu --arch amd64 | specify the operating system and architecture of the LXC. |
--password P@ssw0rd --unprivileged 1 | set the root password for the LXC and enable unprivileged mode. |
--cores 2 --memory 1024 --swap 0 | specify the number of CPU cores, amount of memory and swap space allocated to the LXC. |
--hostname lxc-ubuntu | This option sets the hostname of the LXC to “lxc-ubuntu”. |
--net0 name=eth0,bridge=vmbr0,ip=dhcp,firewall=1,type=veth | the interface name set to eth0 and bridge to vmbr0 from the host, enable firewall and the network type value is: veth. |
--start true | This option starts the LXC after it has been created. |
about veth
This type of network interface allows the LXC (container) or virtual machine to communicate with other devices on the network as if it were a physical device on the network. The veth interface also allows for network isolation between different LXC or virtual machines running on the same host system.
Launch a shell for the LXC
Enter the container:
|
|
Update the system:
|
|
Install some packages:
|
|
Set Vim as default editor:
|
|
Create user:
|
|
Switch to user:
|
|
Cleaning up
Stop the LXC
|
|
Destroying an LXC
To remove an LXC from the system, use the following command:
|
|
This command destroys the LXC with ID 401 and removes its configuration files from the system.
Removing a Template Image If you want to remove a template image from the storage pool, use the following command:
|
|
Conclusion:
We covered the basics of managing LXC in Proxmox Virtual Environment (PVE).
Looked at how to download a template image, create an LXC, and configure it with various options. We also saw how to remove an LXC from the system.
PVE offers many more commands and options for managing LXCs, and we encourage you to explore them further to get the most out of this powerful virtualization platform.