Moving to KVM virtual machines
By Leo Gaggl
Installing VirtualBox is getting increasingly painful on Ubuntu due to the problems with UEFI Secure Boot and the VirtualBox kernel modules. Another reason for an alternative is that running VirtualBox VM’s completely in the background is not as straightforward as it could be.
From the available alternatives I looked into (VMWare, Xen & KVM) it was KVM that fitted my needs (casual VM usage with mostly headless VM’s for testing purposes). Main reasons:
- Well supported by Ubuntu
- Easy, straightforward install
- Background VM’s are simple as
- Moving VM’s from one host to another is a breeze
Checking system
To check if the CPU can actually support
egrep -c '(svm|vmx)' /proc/cpuinfo
If the number returned is > 0 your systems should be capable to run.
You will also enable your BIOS for virtualisation (in Security settings of most BIOS’s) if that has not already be done. You will get an error if not enabled if you are trying to run an install. The Install of KVM will work fine.
Installation
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager<br></br>sudo addgroup libvirtd<br></br>sudo adduser libvirtd<br></br>sudo service libvirtd start<br></br>sudo service libvirtd status<br></br>sudo virt-manager
Moving VM’s to another host
Source Host
virsh shutdown VMNAME<br></br>virsh dumpxml VMNAME > /tmp/VMNAME.xml<br></br>scp /tmp/VMNAME.xml TARGETHOST:/tmp/VMNAME.xml<br></br>scp /var/lib/libvirt/images/VMNAME.qcow2 TARGETHOST:/var/lib/libvirt/images/VMNAME.qcow2
Target Host
virsh define /tmp/vm.xml<br></br>virsh start vm
Once you have confirmed operation you probably want to remove the source VM from the Source Host.
virsh undefine VMNAME<br></br>rm /var/lib/libvirt/images/VMNAME.qcow2