KVM
Jump to navigation
Jump to search
Here are some recommendations for creating new virtual machines (VMs).
Prerequisites
Working with libvirt is much easier than working with the raw QEMU commands, so make sure to have it installed:
apt install qemu-system libvirt-clients libvirt-daemon-system virtinst
VM Creation
Let's say we want to create a new VM for progcom. First, create a new volume for it:
lvcreate -L 40G vg0 --name progcom
Next, run virt-install:
virt-install \ --connect qemu:///system \ --name progcom \ --virt-type kvm \ --memory 8192 \ --vcpus 4 \ --cpu host \ --disk path=/dev/vg0/progcom,format=raw,bus=virtio \ --network bridge=br0,model=virtio \ --graphics none \ --video virtio \ --serial pty \ --extra-args 'console=ttyS0,115200n8' \ --os-type linux \ --os-variant debian10 \ --location http://mirror.csclub.uwaterloo.ca/debian/dists/stable/main/installer-amd64
This will start the Debian installer on your console. It should be possible to automate the installation using preseeding.
Post-creation
Make sure you run through the steps outlined in New CSC Machine. After you do that, you should be able to ditch the virsh console and SSH in from anywhere.
Optional, but recommended: if the VM will be used by potentially untrusted people, it is a good idea to apply libvirt firewall rules to the VM to prevent IP/MAC/ARP spoofing.