Azitech

Azimout's Linux weblog

KVM

leave a comment »

I’d say the 4 main virtualization technologies for Linux are the following:

  1. KVM (RedHat)
  2. VMWare (EMC)
  3. VirtualBox (Oracle)
  4. Xen (Citrix)

The thing is, VMWare is proprietary, VirtualBox is proprietary if you want USB or RDP, and Xen requires a special kernel (rather than a kernel module, like KVM). So to me, the choice is easy…

Basics

  1. First, check if your CPU supports virtualization, and if it’s enabled in the BIOS (run egrep '(vmx|svm)' /proc/cpuinfo --colour, vmx means Intel VT-x, svm means AMD-V).
  2. Then, install some packages: sudo aptitude install qemu-kvm libvirt-bin virt-manager
  3. Regarding disk storage, you have storage pools and storage volumes. I use a directory-based pool and qcow2 volumes.
  4. The xml configuration files for each VM will either be under ~/.libvirt/qemu or under /etc/libvirt/qemu
  5. You really want to use virtio for better disk and network I/O performance
  6. To get a screen resolution > 800×600, change the video device from “cirrus” to “vga”
  7. To avoid filling up your main partition, create a virtual link for the directory countaining the virtual machine images: sudo ln -s -d path_to_folder /var/lib/libvirt/images

Virtio in Windows XP

  1. download the driver while in the VM
  2. shut down the VM
  3. add a (dummy) virtio storage volume to the VM
  4. run the VM
  5. it will ask you to install the driver; provide the driver downloaded in step 1
  6. shut down the VM
  7. remove the dummy volume, remove the actual IDE volume of the VM
  8. add a virtio volume pointing to the same file
  9. run the VM

Editing an image

To mount the guest image volume (.img) from the host (as long as the guest is NOT running), do the following:

  1. sudo losetup /dev/loop0 path_to_img_file
  2. sudo kpartx -av /dev/loop0
  3. sudo mount /dev/mapper/loop0p1 mount_point
  4. do whatever you want to do
  5. sudo umount mount_point
  6. sudo kpartx -dv /dev/loop0
  7. sudo losetup -d /dev/loop0

Resizing an image

Resizing (growing) an existing qemu machine image is trivial:

  1. Convert from qcow2 to raw format:
    qemu-img convert -f qcow qcow2_image -O raw raw_image
  2. Create an empty qemu image of the size that is the amount you want to grow your image:
    qemu-img create -f raw temp_image 10G
  3. Concatenate the two images to a new one:
    cat raw_image temp_image > new_image
  4. Convert the new image from raw back to qcow2
    qemu-img convert -f raw new_image -O qcow final_image
  5. Boot your virtual machine with the new image. Use (format) the empty disk space at will.

Notes:

  • If you’re using raw images instead of qcow2, you can obviously skip steps 1 and 4.
  • I saw some people suggesting using the dd command to replace steps 2 and 3, but others are saying it’s slower. Haven’t tried it myself.
  • If you want to grow the root partition’s filesystem rather than create a new partition in the image, you can add the image to an existing Linux virtual machine and use gparted. Some are suggesting downloading the gparted livecd and booting a VM with that as a CD and your image as an HDD, then doing the resizing, shutting down and booting back into your normal VM.

Renaming a VM

  • Edit the corresponding .xml file under /etc/libvirt/qemu
  • sudo service libvirt-bin restart

References

Advertisements

Written by azimout

20/05/2010 at 19:06

Posted in Reference

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: