The Minimalist Home Lab: Running Lightweight LXD VMs on Ubuntu 24.04

Modern servers are powerful, but efficient resource management is an art. If you have a modest server (e.g., 8 CPUs, 16 GB RAM), standard…

The Minimalist Home Lab: Running Lightweight LXD VMs on Ubuntu 24.04
Photo by Gabriel Heinzer / Unsplash

Modern servers are powerful, but efficient resource management is an art. If you have a modest server (e.g., 8 CPUs, 16 GB RAM), standard heavy virtual machines (such as VirtualBox or VMware) will quickly exhaust your resources.

LXD provides a “system container” feel, but can also run full KVM Virtual Machines. This guide shows you how to carve up a 4GB server into three distinct, usable servers using LXD limits and clever networking.

The Architecture

We will split your 4GB RAM server into four parts:

  1. Host OS (Ubuntu): ~2GB Reserved (System stability)
  2. VM Main (Gateway/App): 2 GB RAM / 2 CPU
  3. VM Small 1 (Worker): 2 GB RAM / 2 CPU
  4. VM Small 2 (Worker): 2GB RAM / 2 CPU

Step 1: Prerequisites & Installation

Before creating VMs, ensure your CPU supports virtualisation.

# Check for KVM support 
kvm-ok 
# If output says "KVM acceleration can be used", proceed.

Install and Initialise LXD:

Ubuntu 24.04 includes LXD, but let’s ensure it’s up to date.

sudo snap install lxd 
sudo lxd init 
# Press ENTER for all defaults.

Step 2: Create the Lightweight VMs

We use the --vm flag to create real Virtual Machines (running their own kernel), and pass -c flags to strictly limit resources immediately upon creation.

1. Create the Main VM (2GiB RAM):

lxc launch ubuntu:24.04 vm-main --vm -c limits.cpu=2 -c limits.memory=2GiB

2. Create the Satellite VMs (2GiB RAM):

lxc launch ubuntu:24.04 vm-small-1 --vm -c limits.cpu=2 -c limits.memory=2GiB 
lxc launch ubuntu:24.04 vm-small-2 --vm -c limits.cpu=2 -c limits.memory=2GiB

Step 3: Configure External Access (SSH Port Forwarding)

LXD VMs exist on a private network (e.g. 240.x.x.x). To access them from your laptop, we must "punch a hole" through the host using proxy devices.

Critical Rule: LXD Proxy devices in VM mode require NAT, and NAT requires a Static IP on the VM and a specific listen IP on the host.

A. Assign Static IPs

Run these commands to lock the VMs to their current internal IPs:

# Get the current dynamic IPs 
lxc list
# Lock them (replace IP_ADDRESS below with the actual IPs you see) 
lxc config device override vm-main eth0 ipv4.address=YOUR_VM_MAIN_IP 
lxc config device override vm-small-1 eth0 ipv4.address=YOUR_VM_SMALL1_IP 
lxc config device override vm-small-2 eth0 ipv4.address=YOUR_VM_SMALL2_IP

B. Forward Ports

We will map ports 2201, 2202, and 2203 on your Host to port 22 inside the VMs.

(Replace 192.168.100.9 with your Host Server's actual LAN IP).

# VM Main -> Host Port 2201 
lxc config device add vm-main ssh-proxy proxy listen=tcp:192.168.100.9:2201 connect=tcp:YOUR_VM_MAIN_IP:22 nat=true
# VM Small 1 -> Host Port 2202 
lxc config device add vm-small-1 ssh-proxy proxy listen=tcp:192.168.100.9:2202 connect=tcp:YOUR_VM_SMALL1_IP:22 nat=true 
# VM Small 2 -> Host Port 2203 
lxc config device add vm-small-2 ssh-proxy proxy listen=tcp:192.168.100.9:2203 connect=tcp:YOUR_VM_SMALL2_IP:22 nat=true

Step 4: Authentication (The “Keys” to the Kingdom)

LXD images disable password login by default. You must inject your SSH public key.

1. On your Laptop/PC (The Client):

Copy your public key:

cat ~/.ssh/id_rsa.pub 
# Copy the output

2. On the Host Server:

Inject that key into the VMs:

# For Main VM 
lxc exec vm-main -- bash -c "echo 'PASTE_KEY_HERE' >> /home/ubuntu/.ssh/authorized_keys"
# For Small VMs 
lxc exec vm-small-1 -- bash -c "echo 'PASTE_KEY_HERE' >> /home/ubuntu/.ssh/authorized_keys" 
lxc exec vm-small-2 -- bash -c "echo 'PASTE_KEY_HERE' >> /home/ubuntu/.ssh/authorized_keys"

3. Connect:

You can now SSH from your laptop:

ssh -p 2201 ubuntu@192.168.100.9


Summary Command Cheatsheet

Shell
lxc exec vm-name -- bash

List VMs
lxc list

Stop VM
lxc stop vm-name

Delete VM
lxc delete vm-name

Subscribe to Digital Lab

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe