4.3 KiB
4.3 KiB
kvm-cloudimage
Use cloud images on baremetal using libvirt/kvm
Actually, you can select these base OS for Guests
- Debian 12
- Ubuntu 20.04
- Ubuntu 22.04
- FreeBSD 14.3 with UFS filesystem
- FreeBSD 14.2 with ZFS filesystem
Pre-requisites
openssharpwgetcurllibvirt
In order to create openbsd images you will also need
python3sudosignify(Debian:signify-openbsdandsignify-openbsd-keys)qemu-system-x86_64
Links and credits
In order to get libvirt installed
Inspirational sites for the project
- https://blog.programster.org/create-debian-12-kvm-guest-from-cloud-image
- https://earlruby.org/2023/02/quickly-create-guest-vms-using-virsh-cloud-image-files-and-cloud-init/
- https://sumit-ghosh.com/posts/create-vm-using-libvirt-cloud-images-cloud-init/)
For openbsd vm with cloud init, hcartiaux's openbsd-cloud-image project is used.
Preparing host
- Define variables file (env_scripts/common.sh). It's recommended to use a folder on your home directory to avoid libvirt permission problems.
- launch install.sh
AppArmor exception
If needed
ln -s /etc/apparmor.d/usr.sbin.libvirtd /etc/apparmor.d/disable/
apparmor_parser -R /etc/apparmor.d/usr.sbin.libvirtd
Examples
Command usage
NAME
./vm_manage.sh
USAGE
Usage: ./vm_manage.sh create -n NAME [-b BRIDGE] [-r RAM] [-c VCPUS] [-s DISK] [-v]
./vm_manage.sh delete NAME
./vm_manage.sh info NAME
./vm_manage.sh connect NAME
./vm_manage.sh list
ACTIONS
create Create a new virtual machine
delete Delete a virtual machine
list List all defined virtual machines
info Show information about a virtual machine
connect Connect to the console of a virtual machine
OPTIONS
-h Show this help message
-n NAME Host name (required)
-b BRIDGE Bridge interface name
-r RAM RAM in MB (default: 1024)
-c VCPUS Number of VCPUs (default: 1)
-s DISK Disk size in GB (default: 10)
-v Verbose mode
AUTHOR
Victor Gracia Enguita <victor@burufalla.ovh>
COPYRIGHT
This is free software; see the source for copying conditions.
Create VM
./vm_manage.sh create -ntestMachine
A VM will ve created with default values. you can set then on env_scripts/common.sh file.
./vm_manage.sh create -ntestMachine -r4098 -c4 -s100
A VM will be created with 4098 MB of RAM, 4 vCPUs and 100Gb of storage
List VMs
./vm_manage.sh list
Id Nombre Estado
-------------------------------
7 debianTest ejecutando
8 ubuntuTest ejecutando
Connect to an VM
./vm_manage.sh connect debianTest
Get ip of VM
./vm_manage.sh info ubuntuTest
192.168.122.234
Delete VMs
Use as parameter machine name
./vm_dmanage.sh delete ubuntuTest
Are you sure you want to remove the VM 'ubuntuTest' (y/N)? y
Domain 'ubuntuTest' destroyed
Domain 'ubuntuTest' has been undefined
VM 'ubuntuTest' removed successfully.
TODO
- Maybe add more BSD flavours guests support
- add non debian linux derivatives guests support