Friday, January 28, 2011

Getting a VM to work...the hard way


What am I talking about? I still don't really understand the concept of a computer running inside a computer. And I don't mean a laptop running inside a desktop case! I'm talking about Virtual-Machines. Loading an OS from a recently acquired image and then making it run in the background of an already running OS. Sounds like I might need a faster computer. Or get some liquid N2 and just frost up the bottom of my laptop. At least my palms wouldn't get hot. It does sound like a bit much.

Kernel-based Virtual Manager looks like a decent package. A bare bones kind of software that hopefully won't weigh down the running system. Problem is that I don't know how to use it, and I think that it runs from a command-line, which is what I want. There is an ever-so-useful HowTo at there site, and I'm testing that the procedures do work as I type this. I should go to bed.

Install the packages below as a start.
sudo apt-get -y install kvm qemu bridge-utils uml-utilities
sudo modprobe kvm
sudo apt-get -y install libvirt-bin
sudo apt-get -y install virt-manager

The last one is meant to be some sort of GUI but I have no idea how to use it, yet. The modprobe line reloads KVM without having to restart your computer, even though I've restarted mine several times before even getting this far.

Next, is you'll want to create a disk image for the guest-image, or in other words, a place where the virtual machine will live/sleep. From what I gather, Qcow2 is some sort of tool which creates a standalone image from a cluster of memory which is then scanned by the header when it needs to be read. I don't know. It's a thing. Create one like this:

/path/on/computer/where/it/will/live create -f qcow2 imagename.img 10G

Qcow2 will do it's thing, the last paramater is the size of the image, 10G -- I haven't played around with this much. When you have finally downloaded your Free and Open Source Linux distro that you so desire, just go ahead and install it.

sudo qemu-system-x86_64 -hda imagename.img -cdrom /path/where/.iso/is -m 512

There is meant to be some sort of read error and the host os will be unable to determine if the system you are installing is 32 or 64 bit, so by assigning qemu-system-x86_64 as the pathway, no one gets confused. Although, it might actually be part of the command, not sure. The final -m tells qemu how much RAM you want to allocate to the VM. I'm finding out now that maybe I should have used -m 1024, 36mins57s remaining...uhg!

1:29:40AM - Still waiting...

1:34:46AM - Meanwhile, test that the printer works

1:49:05AM - Printer works, going to bed, check the install in the morning.

5:35:19AM - Still going, stupid WINS param...

8:54:24AM - Yay! It's working! I'm now running Debian 2.22.3

Lastly, when you need to start up the VM from scratch, it is a simple call of the OS file created and the image memory, or whatever you want to call it. As you will probably find out, it's much simpler to create a directory and store both of these files there, that's what I did.
qemu-system-x86_64 -hda /path/to/imagename.img

So that's it. The system seems to be working fine. I have somehow lost track of where the KVM functionality is taking place, as Qemu seems to be doing all the work. My understanding of KVM has been rewritten, again - I must have missed something.

1 comment:

  1. Great post I use KVM all the time and I have been compiling a thread on using KVM myself, though you beat me to the punch. My article more or less revolve around the Server, though I am going to check this out for Desktop too.

    As a piece of information to make the building more easy there is an assisted GUI for KVM that is in the market place. It is called the Virtual Machine Manager. good stuff and definitely makes life with KVM easier when building non-Ubuntu Systems with KVM.

    Keep up the great posts..

    ReplyDelete