Showing posts with label KVM. Show all posts
Showing posts with label KVM. Show all posts

Migrating Windows XP Virtual Machine from ESX to KVM

Before converting any Windows Virtual Machine we have to enable IDE in the registry and uninstall VMware tools form VM.


1. Uninstall VMware tools form VM

2. Below is the process to enable IDE in Windows registry.

Login into the VM which you want to migrate, extract the Atapi.sys, Intelide.sys, Pciide.sys, and Pciidex.sys files from the

%SystemRoot%\Driver Cache\I386\Driver.cab file, and copy into the %SystemRoot%\System32\Drivers folder.

Now we will Import new registry settings into windows registry

Open regedit-->Go to file-->Export-->Give a file name-->Click save to save a registry file.

Right Click on saved reg file and click-->Edit-->Open below link-->Copy each line from below link-->Replace copied data into Opened registry file-->Save the registry file

3. Shutdown the VM and Copy VMDK,Flat.VMDK and VMX files to KVM machine.

#scp 10014-1001.vmdk 10014-1001-flat.vmdk 10014-1001.vmx user@KVM Server ip:/var/lib/libvirt/images/

4. Now we will convert .vmx to .xml and .vmdk to .qcow2. We will use vmware2libvirt to convert .vmx file to .xml .

Below command to install virt-goodies in your KVM system.

#apt-get install virt-goodies

5. Convert 10014-1001.vmx to file.xml

#vmware2libvirt -f ./10014-1001.vmx > file.xml

Above command converts the VMware '10014-1001.vmx' file to the libvirt compatible 'file.xml'.

6. Define xml file

# virsh -c qemu:///system define file.xml

Above command imports file.xml into libvirt. The imported .xml files are stored in /etc/libvirt/qemu.


7. Now we will convert .vmdk file to qcow2 format

#qemu-img convert 10014-1001-flat.vmdk -O qcow2 new-diskname.qcow2


Now we have converted .vmx to .xml and .vmdk to .qcow2 file, we need to edit VMNAME, OS Arch & Disk name or source file name in xml file. Please find below is the sample of a xml file. Open the converted xml file and Change VM name as you want, change "type arch" to x86_64, change source file name.

Below command will open file.xml to edit.

#virsh edit file.xml

In the above XML you can see my disk is pointed new-diskname.qcow2 which we have converted to qcow2 format.


Note:While vmware2libvirt works well on simple virtual machines, there are limitations because .vmx files don't always contain enough information, and also because vmware2libvirt tries not to make too many assumptions about what it finds. A couple of things to look out for: While vmware2libvirt attempts to detect a 64-bit guest, be sure that your 64-bit guest has in its .xml file:


hvm


vmware2libvirt only detects and uses the first ethernet interface found. Additional interfaces can be added from within virt-manager.

Currently the first scsi disk is used if found, otherwise the first ide disk. Additional disks can be added from within virt-manager.

The converted virtual machine is hard-coded to use 1 cpu. This can be changed with:

2


8. Define the xml file and start the VM.

#virsh -c qemu:///system define file.xml

#virsh start vmname

Above command imports file.xml into libvirt. The imported .xml files are stored in /etc/libvirt/qemu.Next command will start VM.

Redhat Virutulization KVM Faq's and commands

Min configuration 6GB disk space, 2GB RAM
Recommended   6GB+ Guest OS size , 2GB + Ram required for Guest OS

Check Intel® VT virtualization extensions are enabled .

xm dmesg | grep VMX

example output

(XEN) VMXON is done
(XEN) VMXON is done


VMXON in the output tells that it is on.

Check AMD-V architectures

xm dmesg | grep SVM

example output

(XEN) AMD SVM Extension is enabled for cpu 0
(XEN) AMD SVM Extension is enabled for cpu 1


Installing Redhat Virtulization with yum
----------------------------------------------------------
install "xen" and "kernel-xen" packages

# yum install xen kernel-xen
# yum install virt-manager libvirt libvirt-python libvirt-python python-virtinst

Installing guest with virt-install
---------------------------------------------
# virt-install --name fedora9 --ram 512 --file=/var/lib/xen/images/fedora9.img \
 --file-size=3 --vnc --cdrom=/path=to/fedora9.iso

Giving location of ISO file

virt-install --name nare-Cmd-Ubuntu --ram 512 --file=/var/ns-ubuntu.img   --file-size=8  --cdrom /home/kvm/ubuntu-9.04-desktop-i386.iso 


# virt-install -n rhel5PV -r 500 -f /var/lib/xen/images/rhel5PV.dsk -s 3 --vnc -p

-l\ftp://10.1.1.1/trees/RHEL5-B2-Server-i386/

sudo virsh reboot rhel5PV


--vnc opens a GUI window installation

creating guests with virt-manager
-------------------------------------------------
$ sudo virt-manager &








Note : Use default location for Guest  which is "/var/lib/xen/images/. "
          if you choose different location make sure it is added to your SELinux policy and  relabeled before you  continue with the installation

Creating XML configuration for installed VM

virsh dumpxml NS-test-ubuntu> naresh.xml
Cat naresh.xml will give show the xml file
 
After creating xml file of a VM 
 
virsh --connect qemu:///system
to get connected to virsh prompt and then define the Virtual machine. 
virsh # define /var/lib/libvirt/images/naresh.xml
 
after defining the VM we can issue commands like
 
 
virsh # shutdown NS-test-ubuntuDomain NS-test-ubuntu is being shutdown
 
 
virsh # start NS-test-ubuntuDomain NS-test-ubuntu started
 
 
virsh # list
 Id Name                 State
----------------------------------
  1 storage              running
  8 NS-test-ubuntu       running 
 
nice link for virtulization with KVM on ubuntu-9.10