Tuesday, 26 May 2015

Convert VMware Virtual Machine to KVM



In this tutorial, we will convert a VMware Virtual disk 'Metasploitable.vmdk' to QCOW2 format and install in KVM.

Follow the following steps:
1) Download the Metasploitable 2 zip file from the Internet.

2) Extract the zip file in a folder.

[root@meru iso]# unzip metasploitable-linux-2.0.0.zip
Archive:  metasploitable-linux-2.0.0.zip
   creating: Metasploitable2-Linux/
  inflating: Metasploitable2-Linux/Metasploitable.nvram 
  inflating: Metasploitable2-Linux/Metasploitable.vmdk 
  inflating: Metasploitable2-Linux/Metasploitable.vmsd 
  inflating: Metasploitable2-Linux/Metasploitable.vmx 
  inflating: Metasploitable2-Linux/Metasploitable.vmxf 


3) Convert 'vmdk' to 'qcow2' format.

[root@meru iso]# qemu-img convert -f vmdk Metasploitable2-Linux/Metasploitable.vmdk -O qcow2 Metasploitable.qcow2


4) Change ownership so that 'libvirt' can read the file.
4.1) Change file owner to 'qemu'. 
[root@meru iso]# chown qemu:qemu Metasploitable.qcow2

4.2) The directory should have execute permission for user 'qemu'
[root@meru ~]# setfacl -m u:qemu:x /iso
                OR
[root@meru ~]# chmod o+x /iso

5) Convert 'vmx' file (VM's settings) to 'xml' file using 'vmware2libvirt'. Download 'vmware2libvirt' from here 

[root@meru iso]# python vmware2libvirt -f Metasploitable2-Linux/Metasploitable.vmx > Metasploitable.xml


6) Use 'virsh' to import into KVM. Unfortunately, in this step, virsh is looking for /usr/bin/kvm and the binary is actually installed as /usr/libexec/qemu-kvm, so we need to make a symlink first.

[root@meru iso]# ln -s /usr/libexec/qemu-kvm /usr/bin/kvm

[root@meru iso]# virsh -c qemu:///system define Metasploitable.xml
Domain Metasploitable2-Linux defined from Metasploitable.xml


7) Locate the new Virtual Machine.

[root@meru iso]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 -     kali                           shut off
 -     Metasploitable2-Linux          shut off
 -     onion                          shut off
 -     oserver1                       shut off
 -     oserver2                       shut off


8) Edit the config file for the VM and modify entry for the virtual disk file and change file type to 'qcow2'

[root@meru iso]# virsh edit Metasploitable2-Linux

Locate the following lines:

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/iso/Metasploitable2-Linux/Metasploitable.vmdk'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>


And make the following changes:

    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/iso/Metasploitable.qcow2'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>

Save the changes and exit.



9) The Virtual Machine is now ready. Start the VM.

[root@meru iso]# virsh start Metasploitable2-Linux
Domain Metasploitable2-Linux started


3 comments:

  1. chown: invalid user: ‘qemu:qemu’
    I got this error message.Can you please help me with this

    ReplyDelete
  2. Thank you for your useful guild line.

    ReplyDelete
  3. Hi All!

    I'm selling fresh & genuine SSN Leads, with good connectivity. All data properly checked & verified.
    Headers in Leads:

    First Name | Last Name | SSN | Dob | Address | State | City | Zip | Phone Number | Account Number | Bank Name | DL Number | Routing Number | IP Address | Reference | Email | Rental/Owner |

    *You can ask for sample before any deal
    *Each lead will be cost $1
    *Premium Lead will be cost $5
    *If anyone wants in bulk I will negotiate
    *Sampling is just for serious buyers

    Hope for the long term deal
    For detailed information please contact me on:

    Whatsapp > +923172721122
    email > leads.sellers1212@gmail.com
    telegram > @leadsupplier
    ICQ > 752822040

    ReplyDelete