This project provides a simple way to create and manage KVM virtual machines with cloud-init
on Ubuntu.
The system is designed around a single management script (VM_manager.sh
) that handles image preparation, VM creation, and VM removal.
- Automatically downloads the official Ubuntu 22.04 (Jammy) cloud image.
- Converts the downloaded base image to
qcow2
format for snapshots and efficient storage. - Creates VM disks as overlays, preserving the base image.
- Integrates with
cloud-init
for automated user and configuration setup. - Provides a helper script to show the VM's IP address.
- Ubuntu with KVM/QEMU installed
cloud-utils
,genisoimage
,libvirt-clients
,qemu-utils
Install prerequisites:
sudo apt update
sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager \
cloud-utils genisoimage qemu-utils
Each VM requires a corresponding directory under:
~/vm/cloud-init/
Inside this directory, place your cloud-init
files:
meta-data
user-data
For example:
~/vm/cloud-init/home-lab/user-data
~/vm/cloud-init/home-lab/meta-data
When creating a VM, the folder name (for example home-lab
) must match the VM name.
sudo ./VM_manager.sh create home-lab
This will:
- Ensure the base Ubuntu Jammy image is present and prepared
- Create a
qcow2
disk overlay for the VM - Generate a
seed.iso
with your cloud-init configuration - Launch the VM with
virt-install
sudo ./VM_manager.sh destroy home-lab
This will shut down the VM, remove its disk, and clean up related files.
Use the helper script:
sudo ./VM_show_ip.sh home-lab
This will display the current IP assigned to the VM.
- Currently, only Ubuntu 22.04 (Jammy) is supported as the base image.
- VM names must correspond exactly to the directory names in
~/vm/cloud-init/
. - The project defaults to using
~/vm
as the root folder for all VM data. - Path to VM directory location is hardcoded, so don't forget to change it.
- Also don't forget to change SSH key