An opinionated and simple cli suite for creating and destroying VMs, in my homelab, from cloud images and cloud-init with libvirt and KVM.
The whole libvirt/kvm/qemu ecosystem is quite flexible and powerful. It, like many long running opensource ecosystems, suffers from a huge amount of old, out of date documentation on the internet.
I needed a simple way to spin VMs up and down in my homelab without having to search for the various commands and nuances for each guest OS type.
- a Linux based host running libvirt and kvm
- ability to resolve static dns for new VMs (I switched off the libvirt/dnsmasq integration)
- a user that is in the
libvirt
group - jq, virsh, virt-install and qemu-img installed and available in the $PATH
I built this for my homelab to be able to simply spin up and down VMs.
- public cloud images in qcow2 format
- cloud-init (not available for editing before creating a VM)
- Network options:
- VM on NAT interface using DHCP (default) OR
- VM on bridge interface using DHCP
- VM on bridge interface with static IP
- new standalone qcow2 image per VM
This is only tested with the following combination:
- Single, Ubuntu 20.04 (x86_64) server install as a KVM host
- a single NIC bridged to the local LAN
- directory based storage volume pools
Note: I built my homelab with aussielunix/vmlab (coming soon)
Run the following and further, optional instructions will follow.
bin/vms init
vms
is a cli suite with sub commands. It has documentation and command completion built in to help you learn about all the options and their defaults.
[user@vm] (main) -> vms commands
[user@vm] (main) -> vms help
[user@vm] (main) -> vms help new
First, you need to setup templates of the Cloud Images.
[user@vm] (main) -> vms sync ubuntu
[user@vm] (main) -> vms sync debian10
[user@vm] (main) -> vms sync debian11
To get a new Ubuntu Focal (20.04 LTS) server VM with a static IP of 192.168.20.77
using the sane defaults for all other options:
[user@vm] (main) -> vms new -n mynewvm -i 77
Creating new ubuntu20.04 VM - mynewvm
Type virsh console mynewvm to see when it is finished being created.
To get a new Debian 11 server VM on the NAT bridge, using the sane defaults for all other options:
[user@vm] (main) -> vms new -n mynewvm -o debian11
Creating new debian11 VM - mynewvm
virsh console mynewvm to see when it is finished being created.
[user@vm] (main) -> ssh mynewvm
Bug reports and pull requests are welcome on GitHub.
- Fork this repository
- Create a branch:
git checkout -b <branch_name>
- Push your branch:
git push -u origin <branch_name>
- Create a pull request with
WIP
at the start of the subject - Make your changes and commit them: git commit -m '<commit_message>'
- Push to your branch:
git push
- Edit pull request and remove
WIP
from the title and comment it is ready for review
Thanks to the following people who have contributed to this project:
This command suite was built quickly using the great sub.
The is available as open source under the terms of the MIT License.