Pre-installation checklist

egrep -c ‘(vmx|svm)’ /proc/cpuinfo
If 0 it means that your CPU doesn’t support hardware virtualization.
If 1 or more it does – but you still need to make sure that virtualization is enabled in the BIOS.
you may execute:
which may provide an output like this:
INFO: /dev/kvm exists
KVM acceleration can be used

Installation of KVM

$ sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
$ sudo apt-get install libcap2-bin

Verify Installation

$ virsh -c qemu:///system list
Id Name                 State

—->qemu installation

—->kvm installation

Qemu/KVM base images

Base imaging was inherited from the qemu userspace component as an added feature of kvm. The idea behind the base image is simple. You build a disk image as you would build a normal image. You then build a new image using the first image as your base image, also known as the backing file. From this point on, kvm will only read from your base image (backing file). If anything needs to be written to your image, kvm will only write to the new image. It is, in effect, similar to a diff where all new data is written only to the new image while preserving the state of your backing file. As a sideffect, your working image will be the same size as your base image. This is where the qemu copy on write term came from.

Building your base image

Your base image should be based on a template disk image that is a practical starting point for your needs. Personally I like to start with a base image that is at a state right after a fresh install; no patches, no applications, just the state of the machine right after installation and registration of the OS if it requires registration. You would start by using the usual qemu-img command as you normally would for creating your base image. For example, to install your base image for a windows xp base image you would create the image with the following command.
qemu-img create -f qcow2 windows-master.qcow2 10G
kvm-img create -f qcow2 Windows7.img 20G

This image will be your base image. Once your image is created you boot the image and install the OS as you normally would with a command similar to the following:
qemu-system-x86_64  -hda  windows-master.qcow2  -m  512  -boot d  -cdrom /home/user/isos/en_winxp_pro_with_sp2.iso
kvm -m 4096 -cdrom Windows7.iso -drive file=windows7.img,if=virtio -boot d -drive file=virtio-win-0.1-30.iso,index=3,media=cdrom -device virtio-net-pci -net nic -net user -nographic -vnc :5
Install Using Floppy:
kvm -m 4096 -cdrom winxp.iso -drive file=wxp.img,if=virtio -boot d -drive file=winxp.iso,index=3,media=cdrom -fda  viostor-31-03-2010-floppy.img -device virtio-net-pci -net nic -net user -nographic -vnc :10
——->before executing the previous command copy the virtio iso file to the server and me ntion its path in the command.————

Install your OS to completion and back up this image immediately. This is your new base image and you will not have to ever boot this image in life again.

Create a new image from your template base image

Now that you have your base image you are ready to install a new image from this template. You would create your new image with the following command using the –b flag.
qemu-img create -b windows-master.qcow2 -f  qcow2   windows-clone.qcow2
kvm-img create -b windows-master.img -f  qcow2   windows-clone.img
This will create a new copy-on-write image called windows-clone.qcow2 which uses your original windows-master as your template base image. You don’t need to specify a filesize with this command as it will automatically set your new image to the same size as your base image. At this point run the following command on your new image and note the size of your new image.
qemu-img info windows-clone.qcow2
image: windows-clone.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 56K
cluster_size: 4096
backing file: windows-master.qcow2 (actual path: windows-master.qcow2)
Note the size of your new image is 10G , the size of your original base image and note how small your image is, 56 k. At this point, your new image is basically a clone of your base image and dependent on your base image being in the same state it was at the time your clone was created. For this reason, you should try to never boot your base image again as some data may be inadvertently be written to disk causing some inconsistencies. Boot up your new clone image with a command similar to the following
qemu-system-x86_64  -hda  windows-clone.qcow2  -m 2048
You new clone will boot up and you will see that it is a perfect clone of your original base image. As you install patches, applications and write data to your new image you can see it growing in size but your base image will always remain unchanged from it’s original state. You can use the qemu-img command to verify this. Try installing some applications on your new clone then run the following commands on both your base image and your new clone.
qemu-img info windows-master.qcow2
qemu-img info windows-clone.qcow2
You will see that your clone image is growing and your base image has remained the same size.
Using VIRT to connect to the clone:
virt-install –virt-type kvm –name vm_name –ram 2048 –cdrom=/var/lib/libvirt/images/Windows7.iso –disk path=/var/lib/libvirt/images/windows-clone.img –network network=default –graphics vnc,listen= –noautoconsole
Now using VIRSH .you can control VMs using Virsh list.
To attach CD ROM to VMs:-
virsh attach-disk winxp /var/lib/libvirt/images/samp.iso hdc –type cdrom –mode readonly
To attach Network interface card:-
virsh attach-interface winserv7 –type network –source default –persistent

Note:-A copy of the XML file is copied to the /etc/libvirt/qemu directory

Leave a Comment