Post describes how to copy installed virtual machine from Fedora to another RedHat family host. This procedure consists of disk image copy and VM configuration in few steps. In other words, guest OS can be very easily copied or cloned to the new host and here is how:
- Does new host has hardware virtualization?
- Install virtualization software on new Fedora host
- Copy disk image to the new host
- Create a virtual machine on new host
1. Does new host has hardware virtualization?
First make sure that CPU on new Linux host has hardware virtualization (svm is for AMD, vmx for Intel). Virtualization Technology (VT) is a set of enhancements to newer processors that improve performance for running a virtual machine by offloading some of the work to the new cpu extensions. Run the following command from command line. If command returns a list then CPU has hardware virtualization (and that’s good).
# simple egrep "svm|vmx" /proc/cpuinfo # paint CPU flags grep -E "(vmx|svm)" --color=always /proc/cpuinfo
If CPU doesn’t have built in hardware virtualization, QEMU will still run with acceptable performance. In this case, KVM kernel driver will not be loaded.
What is KVM? KVM stands for Kernel-based Virtual Machine. In a Linux world, KVM is a full virtualization solution on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It offers guests the ability to use paravirtualized block and network devices, which leads to better performance and lower overhead.
2. Install virtualization software on new Fedora host
The most simple way is to install the KVM hypervisor with yum utility. The kvm package contains KVM kernel module providing the KVM hypervisor on the default Fedora kernel.
yum install kvm
Install the other recommended virtualization packages:
yum install virt-manager libvirt libvirt-python python-virtinst
… or you can prepare Fedora hypervisor with groupinstall option:
# list all software groups yum grouplist # install virtualization support yum groupinstall virtualization
3. Copy disk image to the new host
By default, disk images are located in /var/lib/libvirt/images directory. In my case I had 8GB WinXP.img disk image in RAW format. New hypervisor was next door Fedora so I made plain scp:
# cd to the images directory cd /var/lib/libvirt/images # copy disk image to the new host scp WinXP.img email@example.com:/var/lib/libvirt/images
4. Create a virtual machine on new host
To create new VM, use libvirt utility tool. Libvirt is collection of software that provides a convenient way to manage virtual machines and other virtualization functionality, such as storage and network interface management. Start VM manager from Application menu:
Applications -> System Tools -> Virtual Machine Manager
Before VM manager starts, password popup will appear. Enter root password to unlock VM manager. After VM manager is displayed, click on “New” icon and follow wizard in 5 easy steps. In scenario with copying VM, wizard will skip fourth step (so there will be only four steps).
Step 1: Enter your virtual machine details
In first step you will be notified if QEMU uses KVM or not. Here is case where QEMU initially did not find KVM and the following notification was displayed:
Step 1 of 5 - Warning: KVM is not available. This may mean the KVM package is not installed, or KVM kernel modules are not loaded. Your virtual machines may perform poorly.
To test if kvm kernel modules are loaded, run lsmod command. There should be two modules listed:
lsmod | grep kvm
If above command displays only kvm module, you can try manually load kvm_intel (or kvm_amd) module:
In my case output message was:
Error inserting kvm_intel (/lib/modules/18.104.22.168/kernel/arch/x86/kvm/kvm-intel.ko) Operation not supported
The problem was in disabled virtualization in BIOS. Here is how to enable virtualization for Fujitsu Siemens ESPRIMO P5730. Reboot computer (during boot press F2 key) and set:
System console Advanced Advanced Processor Options Virtualization Technology (VT-x) -> enabled
After Fedora booted, both modules kvm and kvm_intel were properly loaded and libvirt VM wizard wrote a nice message:
Connection: localhost (QEMU/KVM)
Everything is fine now and VM configuration can begin. In first step is important to input VM name and to choose type of guest OS installation.
Name: WinXP choose how you would like to install the OS: Import existing disk image
Step 2: Provide the existing storage path
Because of selected Import existing disk image option in first step, in second step is needed to input path to the existing disk image. Disk images are saved in default libvirt location:
After disk image location is entered, choose an operating system type and version. It should be the same type as is contained OS on disk image (in my case it is Windows XP).
OS type: Windows Version: Microsoft Windows XP
Step 3: Choose Memory and CPU settings
This step is simple. For Windows XP guest OS I set one CPU and 1GB or RAM – no more no less.
Memory (RAM): 1024MB CPUs: 1
Funny, step 4 was skipped and wizard jumped to the last step.
Step 5: Ready to begin installation
Step 5 is the last step and in this scenario there will be no guest OS installation. After powering on VM, Windows XP should boot immediately in exact state of the last shut down. Click on Customize configuration before install to set VirtIO disk and to add EvTouch device. Here are steps to set VirtIO disk. By default, disk will be set as IDE, but if QEMU uses KVM, then it’s possible to use paravirtualized drivers for disk and nic to boost better performances.
Click on Customize configuration before install (imported disk will be set as IDE):
- remove IDE disk
- click on add new hardware (choose Storage)
- click on “Select managed or other existing storage”
- browse to the location of disk image /var/lib/libvirt/images/WinXP.img
- set Device type as “Virtio disk”
- in case of RAW disk image set cache mode to “none”
- Device type: RAW / QCOW2 (the same format as is copied disk image)
And finally I added Input device “EvTouch USB Graphic Table”. A graphic tablet configured as the default pointer in the guest OS will ensure that the virtual cursor moves in sync with the local desktop cursor.