Most examples for beginners using Qemu/KVM assume that the user is starting up guest operating systems from a desktop running some sort of X11 windowing environment. As I need to host guests on servers with the servers having a minimal installation, this article reflects the very easy experience of running a guest and connecting to it with out the safety net of an X11 installation.
In a previous article,
Virtualization on Opensource Platforms,
I discussed the steps of installing the Qemu/KVM virtualization tools on Debian Wheezy. I was able to immediately
start up with a local image in a local console.
This time, I want to create a new install of a guest Debian Wheezy on my existing Debian Wheezy host. The first step
was to wget the latest Debian Wheezy iso and put it into a sub-directory called iso.
An image file needs to be created from which the guest will run. There are various ways of doing this from
a thin/thick/sparse/initialized-with-0 perspective, but I'll use the shortest way of getting it going:
qemu-img create images/test.img 4g
This creates a file in called test.img in the sub-directory images, and makes the file 4G in file.
The next step is to boot from the iso and install to the img file. At the same time, I want to access the console
remotely. To do this, one uses the vnc protocol. The base tcp port for vnc is 5900. As there may be multiple
guests running, each needs a unique instance number. I ran the following command line:
qemu -hda images/test.img -cdrom iso/debian-testing-amd64-netinst.iso \
-boot d -m 512 -cpu kvm64 -name test -vnc :2 -no-reboot -enable-kvm
This associates the image file with drive hda, associates the cdrom device with the iso, d says boot from the
cdrom, :2 says use display 2 with vnc, which translates into tcp port 5902, and when the install is done,
I don't want to reboot automatically.
On another machine, I can connect to the host machine with a suitable vnc viewer, connect to port 5902, and
am able to see the console of the installer.
Once the install is complete, I restart the guest with the following command line:
qemu -hda images/test.img -boot c -m 512 -cpu kvm64 -name test -vnc :2 -enable-kvm
This boots from the drive, and reconnects the vnc server to the same port.
I now have a fully functional guest running in a NAT'd environment on a host. The next article will
get bridged networking up and running.
In preparation for more virtualization functionality, some other sites in which i've come across:
- Virtual Square: Discusses
the various aspects of VDE, the virtual Distributed Ethernet tool package, which gets guests across different hosts
communicating with each other. This, I think, is from where a bunch of network based redundancy and resiliency will arise.
- Hardware virtualization with QEMU: A good intro to Qemu and networking, but unfortunately, rather than discussing KVM, it uses
some lesser known hardware virtualizer. Other than that, there is some good discussion about the network side of things.