{"id":23497997,"url":"https://github.com/freedomben/vmware-to-kvm","last_synced_at":"2025-04-22T19:28:55.430Z","repository":{"id":69605522,"uuid":"504350604","full_name":"FreedomBen/vmware-to-kvm","owner":"FreedomBen","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-17T02:09:51.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-16T14:59:13.266Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FreedomBen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-17T00:58:44.000Z","updated_at":"2022-06-17T00:59:03.000Z","dependencies_parsed_at":"2023-05-31T12:52:09.459Z","dependency_job_id":null,"html_url":"https://github.com/FreedomBen/vmware-to-kvm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreedomBen%2Fvmware-to-kvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreedomBen%2Fvmware-to-kvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreedomBen%2Fvmware-to-kvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreedomBen%2Fvmware-to-kvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FreedomBen","download_url":"https://codeload.github.com/FreedomBen/vmware-to-kvm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250307807,"owners_count":21409149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-25T05:17:47.499Z","updated_at":"2025-04-22T19:28:55.415Z","avatar_url":"https://github.com/FreedomBen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Notes on converting a VMware VM to KVM\n\nMuch help from:  http://linux-hacking-guide.blogspot.com/2015/05/convert-vmware-virtual-machine-to-kvm.html\n\n## Example Conversion of Metasploitable 2 VM\n\nDownload zip file from:  https://sourceforge.net/projects/metasploitable/files/Metasploitable2/\n\nSome documentation about the VM:  https://docs.rapid7.com/metasploit/metasploitable-2/\n\n```bash\ncd ~/Downloads\n\n# Unzip the file\nunzip metasploitable-linux-2.0.0.zip\n\ncd Metasploitable2-Linux/\n\n# Convert the vmdk file to a qcow2\nqemu-img convert -f vmdk Metasploitable2-Linux/Metasploitable.vmdk -O qcow2 Metasploitable.qcow2\n```\n\nWe're gonna move to a new directory where we can easier permissions\n\n```bash\ncd ~/\nmkdir vmisos\nmv ~/Downloads/Metasploitable2-Linux/Metasploitable.qcow2 vmisos/\n\n# Chown the qcow2 file and vmisos dir so libvirt can read it\nsudo chown qemu:qemu -R vmisos\nchmod o+x vmisos\n```\n\nDownload the python script for converting vmx to libvirt's xml style.  Use the python script in the repo at `vmware2libvirt.py` to convert the vmx file to libvirt's xml\n\n```bash\n../vmware-to-kvm/vmware2libvirt.py -f ../Metasploitable2-Linux/Metasploitable.vmx \u003e Metasploitable.xml\n\n# The python script buggers the UUID, so we need to fix it\n# Remove the `b'` and `'` from the uuid in the xml file\nsed -i -e \"s|\u003cuuid\u003eb'|\u003cuuid\u003e|g\" Metasploitable.xml\nsed -i -e \"s|'\u003c/uuid\u003e|\u003c/uuid\u003e|g\" Metasploitable.xml\n```\n\nOn Fedora, need to symlink because `kvm` is not in `/usr/bin/kvm` like `virsh` expects it to be.  It's in `/usr/bin/qemu-kvm`\n\n```bash\nln -s \"$(which qemu-kvm)\" /usr/bin/kvm\n\n# Example:\nln -s /usr/bin/qemu-kvm /usr/bin/kvm\n```\n\nImport the new machine using `virsh`.  Might need to `dnf install libvirt-client` first:\n\n```bash\n# Make sure you're in the right hypervisor connection\nvirsh -c qemu:///session list --all\n# or\nvirsh -c qemu:///system list --all\n\n# Import into the session hypervisor connection (that's where my gnome boxes VMs are)\nvirsh -c qemu:///system define Metasploitable.xml\n```\n\nBefore booting the VM, we gotta fix the disk type and location.  See \"Original instructions for fixing settings\" below for more details\n\nNote:  If you put the qcow2 file in a different directory (like we did above), you will need to modify the location.  You can make the changes manually using `virsh edit Metasploitable2-Linux`\n\n```bash\n# Automated\nvirsh dumpxml Metasploitable2-Linux \u003e ms2.xml\nsed -i -e \"s|\u003cdriver name='qemu' type='raw'|\u003cdriver name='qemu' type='qcow2'|g\" ms2.xml\nsed -i -e \"s|\u003csource file='qemu' type='raw'|\u003cdriver name='qemu' type='qcow2'|g\" ms2.xml\nvirsh define ms2.xml\n\n# Manual\nvirsh edit Metasploitable2-Linux\n# Change \u003cdriver name='qemu' type='raw'/\u003e to \u003cdriver name='qemu' type='qcow2'/\u003e\n# and \u003csource file='/home/ben/Downloads/Metasploitable2-Linux/Metasploitable.vmdk'/\u003e\n# to \u003csource file='/home/ben/Downloads/isos/Metasploitable.qcow2'/\u003e\n```\n\n### Fix selinux permissions.\n\nIf you can't boot it due to a permission error, you probably need to fix selinux permissions.\n\nEasiest way is to just move the files somewhere already set up and `restorecon` them:\n\n```bash\n# List approved places\nsemanage fcontext -l | grep -i svirt\n\n# mv Metasploitable.qcow2 ~/.local/share/gnome-boxes/\nmv Metasploitable.qcow2 ~/.local/share/libvirt/images/\n\nrestorecon -R ~/.local/share/libvirt\n```\n\n```bash\n# Look for the relevant error message\nsudo ausearch -m avc\n\n# Export to a file\nsudo ausearch -m avc --raw \u003e metasploitable-qcow2-selinux.txt\n\n# Edit the file to remove events that aren't the one we care about\nvim metasploitable-qcow2-selinux.txt\n\n# Pipe to audit2allow\ncat metasploitable-qcow2-selinux.txt | audit2allow -M metasploitable-qcow2-selinux\n\n# Look at policy for sanity:\nvim metasploitable-qcow2-selinux.te\n\n# Apply policy\nsemodule -i metasploitable-qcow2-selinux.pp\n\n# Or add label\nsemanage fcontext -a -t svirt_home_t \"/home/[^/]+/Downloads/vmisos(/.*)?\"\nrestorecon -R /home/ben/Downloads/vmisos/\n\n# If need to delete the label\nsemanage fcontext -d -t svirt_home_t \"/home/[^/]+/Downloads/vmisos(/.*)?\"\n```\n\nProfit!\n\n\n#### Original instructions for fixing settings:\n\nFrom:  http://linux-hacking-guide.blogspot.com/2015/05/convert-vmware-virtual-machine-to-kvm.html\n\n8) Edit the config file for the VM and modify entry for the virtual disk file and change file type to 'qcow2'\n\n```\n[root@meru iso]# virsh edit Metasploitable2-Linux\n```\n\nLocate the following lines:\n\n```xml\n    \u003cdisk type='file' device='disk'\u003e\n      \u003cdriver name='qemu' type='raw'/\u003e\n      \u003csource file='/iso/Metasploitable2-Linux/Metasploitable.vmdk'/\u003e\n      \u003ctarget dev='hda' bus='ide'/\u003e\n      \u003caddress type='drive' controller='0' bus='0' target='0' unit='0'/\u003e\n    \u003c/disk\u003e\n```\n\n\nAnd make the following changes:\n\n```xml\n    \u003cdisk type='file' device='disk'\u003e\n      \u003cdriver name='qemu' type='qcow2'/\u003e\n      \u003csource file='/iso/Metasploitable.qcow2'/\u003e\n      \u003ctarget dev='hda' bus='ide'/\u003e\n      \u003caddress type='drive' controller='0' bus='0' target='0' unit='0'/\u003e\n    \u003c/disk\u003e\n```\n\nSave the changes and exit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreedomben%2Fvmware-to-kvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreedomben%2Fvmware-to-kvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreedomben%2Fvmware-to-kvm/lists"}