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…
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:
- Host OS (Ubuntu): ~2GB Reserved (System stability)
- VM Main (Gateway/App): 2 GB RAM / 2 CPU
- VM Small 1 (Worker): 2 GB RAM / 2 CPU
- 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=2GiB2. 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=2GiBStep 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_IPB. 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=trueStep 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 output2. 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
Shelllxc exec vm-name -- bash
List VMslxc list
Stop VMlxc stop vm-name
Delete VMlxc delete vm-name