This page describes how to create new virtual machines on the infra/api hosts running KVM/libvirt, with Virtual Machine Manager or with CLI tools.
In order for any of this to work, it is required that one or more hosts are installed with the role::kvm puppet role.
Virtual Machine Manager
Install Virtual Machine Manager
$ apt install virt-manager ssh-askpass-gnome
Connect to the remote KVM host
- Start Virtual Machine Manager, and click
File -> Add Connection...
- Select:
- Hypervisor = QEMU/KVM
- Connect to remote host
- Method = SSH
- Username = <your username at the remote host>
- Hostname = <kvmhost.domain.net>
- Autoconnect
- You will be prompted for you password at the remote host. Enter it, and hit OK.
- You should now see something like this, and you're all set to create virtual machines!
Creating a virtual machine
- Select the remote server, and click the
Create a new virtual machine
button - Ensure that the remote server is selected in the
Connection
dropdown, and selectNetwork Boot (PXE)
- Select the correct OS type and version. In most cases, this should be
Linux
andUbuntu 16.04
- Choose the RAM and CPU settings you need
- Select
Enable storage for this virtual machine
andSelect or create custom storage
and clickManage..
- Select
vmvg
in the left menu, and click the green button with a plus sign - Give the disk a name, preferably the same name as your new virtual machine, enter a sufficient disk size, and click
Finish
- Ensure that the newly created volume are selected, and click
Choose volume
- Give the virtual machine a name, and check
Customize configuration before install
. Also, select the network your virtual machine should connect to. In most cases, you should select one of the options starting withVirtual network
. - In the customization menu, select
Boot Options
and ensure thatStart virtual machine on host boot up
are selected, and that both the NIC and Disk are selected underBoot device order
. The NIC should be first. Click Apply, and thenBegin Installation.
- Your new virtual machine is now ready to go, and is set up for PXE booting. It's now probably smart to take a note of the MAC adress on the virtual NIC.
CLI-tools (virt-install)
Log on to the KVM host. First list the available networks
$ virsh net-list Name State Autostart Persistent ---------------------------------------------------------- management active yes yes services active yes yes
Then; create a new machine
$ virt-install --name <vm-name> --memory <RAM in MB> --vcpus <cpus> --cpu host --pxe --boot network,hd --os-variant ubuntu16.04 --disk size=<disk size in GB>,pool=vmvg -w network:<net-name> --autostart --noautoconsole --wait 0
To find the MAC-address
$ virsh domiflist <vm-name> Interface Type Source Model MAC ------------------------------------------------------- - network management virtio 52:54:00:e8:8d:1c
Start/stop/reset machine
$ virsh start <vm-name> # start a shutdown machine $ virsh destroy <vm-name> # Force stop a machine $ virsh shutdown <vm-name> # Gracefully shutdown a machine $ virsh reboot <vm-name> # Gracefully reboot a machine $ virsh reset <vm-name> # Hard reset / cold boot a machine
Important note
If you know that the VM you're creating is supposed to run a keepalived instance, enable allmulticast on the VM's vtap interface:
root@infra1# ip link set dev macvtap<N> allmulticast on