Virtualization

= KVM Installation =

= Ubuntu/Debian =

egrep -o '(vmx|svm)' /proc/cpuinfo vmx vmx
 * Check hardware support for Virtualization:

sudo apt-get install qemu-kvm libvirt-bin virt-manager bridge-utils kvm-ok sudo kvm-ok
 * Install KVM:

sudo adduser `id -un` libvirtd
 * Add your user to the libvirtd group:

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

virsh -c qemu:///system list
 * Verify:

virt-manager -c qemu:///system kvmhost
 * The ID Name and State fields should empty

CentOS/ RedHat
Source: cyberciti.biz, computingforgeeks.com

lscpu | grep Virtualization
 * Check Virtualisation support

yum install qemu-kvm libvirt libvirt-python libguestfs-tools virt-install
 * Install kvm

systemctl enable libvirtd systemctl start libvirtd
 * Start the libvirtd service:

lsmod | grep -i kvm
 * Verify kvm installation

brctl show virsh net-list virsh net-dumpxml default
 * Configure bridged networking

vim br10.xml
 * Create KVM bridge with virsh command.

Add bridge details to the file:

To define a network from an XML file without starting it, use: $ sudo virsh net-define br10.xml

To start a (previously defined) inactive network, use: $ sudo virsh net-start br10

To set network to autostart at service start: $ sudo virsh net-autostart br10

Check to Confirm if autostart flag is turned to yes – Persistent should read yes as well. $ sudo virsh net-list --all

Confirm bridge creation and IP address. $ ip addr show dev br10

sudo virt-install \ --name=syslog \ --description="CentOS Syslog" \ --disk path=/var/lib/libvirt/images/CentOS-7-x86_64-GenericCloud.SYSLOG.qcow2,bus=virtio,format=qcow2 \ --network=bridge=br10,model=virtio \ --graphics none \ --console pty,target_type=serial \ --vcpus=1 --cpu host --ram=1024 \ --os-type=linux \ --os-variant=rhel6 \ --import --autostart --noautoconsole


 * Increase bash Columns & Rows

nano .bash_profile

Migrate Disk from VirtualBox to KVM
VBoxManage clonehd --format RAW windowsxp.vdi windowsxp.img qemu-img convert -f raw windowsxp.img -O qcow2 windowsxp

Test:

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

=Convert VDI,IMG,VMDK HD image formats=

VMDK to KVM 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:

Requirements

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 reboot or nano /etc/sysconfig/network-scripts/ifcfg-eth0 HWADDR= reboot

= 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
Source howtogeek.com

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

=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.