From Network Security Wiki

KVM Installation

Check hardware support for Virtualization:

egrep -o '(vmx|svm)' /proc/cpuinfo
sudo apt-get install qemu-kvm libvirt-bin virt-manager bridge-utils
sudo kvm-ok

Add your user to the libvirtd group:

sudo adduser `id -un` libvirtd

then logout and log back in to activate your group membership;


virsh -c qemu:///system list

The ID Name and State fields should empty

virt-manager -c qemu:///system kvmhost

Migrate from VirtualBox to KVM

VBoxManage clonehd --format RAW windowsxp.vdi windowsxp.img
qemu-img convert -f raw windowsxp.img -O qcow2 windowsxp


kvm -m 512 -usbdevice tablet -hda ubuntu.qcow

Convert VDI,IMG,VMDK HD image formats


qemu-img convert testvm.vmdk testvm.img

KVM to Virtualbox

VBoxManage convertfromraw --format VDI testvm.img testvm.vdi

KVM to VMware

qemu-img convert -O vmdk testvm.img testvm.vmdk

Virtualbox to KVM

vboxmanage internalcommands converttoraw testvm.vdi testvm.img

Converting VMware Image To Physical Machine

Cloning of the CentOS VM to an unpartitioned HDD:


VMware Workstation, Server or Player.
CloneZilla ISO image.
Unpartitioned HDD with enough space to hold your VM image.

VMware Configuration

Use CloneZilla ISO image to boot the VM. Add physical HDD as part of your existing VM and select the option Use entire disk.

CloneZilla Cloning Process

Start VMware and boot from CloneZilla image
Don't touch keymap
Select Start_clonezilla
Select device-device option
Select Beginner mode
Select disk to local disk
Select your source and target disk and click OK, then press Enter to continue.

A series of questions will appear. Answer yes to all this prompts. After the cloning process is finished power off the VM by pressing 0 on the CloneZilla menu. The cloning process is complete. Now install your new HDD to your physical machine.

Troubleshooting Physical Machine:

Filesystem corruption alert with the following error: Unexpected Inconsistency will occur. Login withroot password and run fsck -y.

Now fix the NIC by any one method:

cd /etc/udev/rules.d 
rm 70-persistent-net.rules


nano /etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR=<MAC address of the network interface>

Shrink VirtualBox HDD

Windows guest

1. Perform a hard disk defragmentation.

2. Download sdelete and run

 sdelete -c c:/

3. Shutdown the VM. Shrinking the VM: In your terminal type the following:

 vboxmanage clonehd Winxp-old.vdi winxp-new.vdi

4. Replace the new HD with the old one in VM settings.

Ubuntu Guest


  • Ensure You’re Using a Dynamic Disk
  • Install Zerofree in Ubuntu VM:
sudo apt install zerofree
  • Start Ubuntu VM in Recovery mode by pressing "SHIFT" key during bootup
  • Drop to Root Shell Prompt
  • Run Zerofree:
zerofree -v /dev/sda1
  • Shutdown VM:
sudo poweroff
  • Shrink the Disk:
VBoxManage modifymedium disk Ubuntu\ Server.vdi --compact

Virtualbox Stop Host Time Sync with Guests

First, find the name of the virtual machine:

vboxmanage list vms

Automatic time sync can be disabled with this command:

VBoxManage setextradata "VM Name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" "1"

Restart VM

Serial Port between Two VMs In VirtualBox

Host = Ubuntu 10.10 Guest= Windows XP and Debian Lenny

First Guest VM Serial Port Settings - Debian

Enable Serial Port check box: checked (enabled)
Port Number: COM1
Port Mode: Host Pipe
Create Pipe check box: checked (enabled)
Port/File Path: /tmp/vboxS0

Second Guest VM Serial Port Settings - Microsoft Windows XP

Enable Serial Port check box: checked (enabled)
Port Number: COM1
Port Mode: Host Pipe
Create Pipe checking box: unchecked (disabled)
Port/File Path: /tmp/vboxS0

Starting VirtualBox Machines

First start the VM with checked "Create Pipe" check box(Debian VM). Afterwards start the second machine(Windows XP VM). There will be an error if you try doing other way.

{{#widget:DISQUS |id=networkm |uniqid=Virtualization |url= }}