Following are just some notes on how to “do things” with virtuals, especially converting from one form to another
One nice thing about some hypervisors it the ability to move a virtual machine (vm) from one physical machine to another. There are two main ways to do this, shutting down the running vm, or doing it while the vm is still running.
In the following sections, source is the hypervisor moving from, target is the hypervisor being moved to, and 'vm' is the virtual machine being moved.
This method has the least limitations, but takes longer and may require significant manual intervention. The configuration of the source and target may be different, and the block devices do not need to be on a shared system. It is even feasible to have Xen running on the source and KVM running on the target, in theory.
Live Migration rapidly migrates a running vm from source to target, in many cases with no downtime detectable by the end user.
This generally has some limitations imposed. For example, migrating a running Xen machine must have Xen on both source and target, and the version of Xen must be very close on both machines. Same with KVM and virtlib. The CPU's on both machines should be similar also.
But, if you have compatible systems, you can migrate machines with little or no impact on end users, either as precursor to maintenance, or simply to manually load balance your hypervisors.
ssh target 'ls'
should give you a listing of all files in /root on target
virsh -c qemu+ssh:%%//%%target/system list
should return a list of running virtuals on target
xl migrate vm targetmachine
virsh migrate --live //vm// qemu+ssh://target/system
Oracle VirtualBox uses their own format for the disk back end. In order to move the block device from VirtualBox to something something else, the image needs to be converted to a raw format, then optionally converted to a qcow2 format to conserve disk space. Note: in each case below, the commands need to be executed from a machine which has the virtualization tool installed. VBoxManage is only available on a VirtualBox machine, and qemu-img is only available on a machine which uses it, ie something that has had virt-manager, kvm, xen or qemu installed.
Also, note that neither of these commands modify the original disk image. They convert the image, copying the converted file to a new one.
The following code will take VirtualBox's sparse disk and convert it to a raw format, in essence a disk image with no compression. In other words, if you have a 40G disk image, but are only using 2.4G of disk space because VirtualBox realizes you are only using that much space, /target/disk.raw will require the full 40 gigabytes.
VBoxManage clonehd /source/disk.vdi /target/disk.raw --format raw
Virt-Manager can work with qcow2 formatted disk images, which are similar to VirtualBox's vdi (sparse) format, so we would really like to convert the raw image above to qcow2 whenever disk space is important. To do this, issue the following command:
qemu-img convert -f raw /path/to/raw/disk.raw -O qcow2 /path/to/qcow/disk.qcow2
You can now delete the original and intermediate files when you feel confident the process has gone well
virt-manager defaults to NAT on the networking. I find this useful on my laptop, where I don't always have a DHCP server available and the running virtuals should be private to my laptop. However, the dhcp server will occasionally give a different IP to the same machine.
To get around this, find the MAC address of the virtual, then set the network to always give it the same IP address. By default, the dhcp server built into virt-manager sets up an entire /24 range except for the primary IP, so we'll need to adjust that range also.
First, find the MAC address of the virtual you want to set up this way, and get the network list (usually “default”)
# get network name virsh net-list # get MAC address of a virtual's network interface virsh dumpxml //vm_name// | grep 'mac address'
Now, edit the DHCP server
# change default to whatever you got in net-list, if it is different virsh net-edit default
Look through this list and find the XML block which defines the DHCP server. Adjust the range for automatic assignments to give you room to add your reservations, then add a new line within the dhcp block to assign a sticky IP based on MAC address found above. Below, we have adjusted the range start address ufrom 192.168.122.2 to 192.168.122.100. .2-.99 are then available for sticky IP reservations. We then added three lines for vm1, vm2 and vm3, giving them an IP based on their mac addresses
<dhcp> <range start='192.168.122.100' end='192.168.122.254'/> <host mac='52:54:00:6c:3c:01' name='vm1' ip='192.168.122.11'/> <host mac='52:54:00:6c:3c:02' name='vm2' ip='192.168.122.12'/> <host mac='52:54:00:6c:3c:03' name='vm3' ip='192.168.122.12'/> </dhcp>
Save your work, then you need to do something to get it all to begin work. https://serverfault.com/questions/627238/kvm-libvirt-how-to-configure-static-guest-ip-addresses-on-the-virtualisation-ho#627245, where I stole this idea, has a lot of things to do, but I just rebooted the damned thing and it began working just fine.