TWiki> CF Web>Linux>UbuntuInCS>VirtualMachines (revision 4)EditAttach

Installation and Configuration of Virtual Machines

Introduction

Wikipedia (virtual machines) states that a virtual machine is a software implementation of a machine or computer, in particular, we shall deal with virtual machines capable of running various well known operatings systems like Windows and Linux to name a few. The real computer on which the virtual machines are running is called the host computer or host operating system. Any virtual machines running operating systems are called guests.

Our discussion will cover various implementations of virtual machines including qemu, virtualbox, and vmware running on a real machine running some version of Ubuntu.

Vmware

See Vmware.

If you want to startup a Vmware virtual host from the command you can do

   vmware-cmd /virtual_machines/vmware/cscfprint1/cscfprint1.vmx start
where the host in question is on trainer.cscf. Basically look for the file that ends with .vmx, it is a executable =#!/usr/bin/vmware# shell script.

QEMU

Installation and Configuration on host computer

The real host vmhost206.cscf is used to run the various virtual machines. We begin by installing the requisite packages, namely qemu, kqemu=common and kqemu-source where the latter two packages allow for kernal module that permits greatly improved performance of any virtual machines installed in qemu. Alas the required device file /dev/kqemu is not generated automatically. To do this we do the following
  • create the file in /etc/udev/rules.d/60-kqemu.rules with the contents
         KERNEL=="kqemu", NAME="kqemu", OWNER="root", GROUP="kqemu", MODE="0660"
         
    Then reload udev configuration by running /etc/init.d/udev reload. (NOTE. This does not cause the /dev/kqemu file file, see below for what will.)
  • The GROUP specification dictates we should create a UNIX group with that name, and any users who wish to launch any virtual machines into that group
           addgroup --system kqemu
           adduser cscf-adm kqemu
         
  • edit /etc/modprobe.d/kqemu (part of the =kqemu-common) package so that the contents look like
         options kqemu major=0
         
    (Aside: Not sure why this is necessary)
  • load the kernal module kqemu by running
         modprobe -r kqemu
         
    This will cause the /dev/kqemu device to be created (udev responds to event requests, so we probably shouldn't be surprised this step was necessary for the creation of /dev/kqemu. Ideally the package qemu-common should have done this for us, I have reported this as a bug in https://bugs.launchpad.net/ubuntu/+source/kqemu/+bug/159340).

Installation and booting of virtual machines

First create a virtual disk file using qemu-img, say =gutsy-i386.img. Then install from iso image, namely run (because we are on an AMD64 machine)
      qemu-system-x86_64 -cdrom ubuntu-7.10-server-i386.iso   -hda ./gutsy-i386.img -m 512 -boot d
     
Then boot the newly installed machine via
      qemu-system-x86_64    -hda ./gutsy-i386.img -m 512 -boot c
     
By default any virtual machine can access the network that the host machine is attached to. In particular if you installed ssh on the host, you can ssh to any host on the network and it will look like you are connecting from the host computer.

It is possible to assign a network configuration to the virtual machine. For example

     qemu-system-x86_64 -hda /vmdata/qemu/gutsy-i386.img -m 512 -boot c -net nic -net tap
     
(Aside: To run this as a non-root you need to be in the group vde-net as the device permits users in this group rw access t /dev/net/tun) By default the network configuration in qemu will read the script /etc/qemu-ifup unless a different script is specified on the command line.

Connecting the GuestOS to the same network as the HostOS

For simplicity we shall assume our hostOS is connected via eth0 to the outside internet. First we reconfigure the hostOS's interfaces by creating a bridge br0 with the IP configuration of eth0 and we disable any configuration on =eth0. Next we join eth0 to the bridge and restart networking.

To connect the guestOS to the network of the hostOS start it up with the command line above which will result in the execution of /etc/qemu-ifup which consists of

   #!/bin/sh
      echo "Executing /etc/qemu-ifup"
      echo "Bringing up $1 for bridged mode"
      sudo  -p "Password for $0:" /sbin/ifconfig $1 0.0.0.0 promisc up
      echo "Adding $1 to br0..."
      sudo  -p "Password for $0:" /usr/sbin/brctl addif br0 $1
      sleep 2
   
We probably could just setup a tap0 interface in /etc/network/interfaces? Note the above script adds the qemu generated tap interface to the bridge when the virtual machine starts up.

Finally configure the guestOS by editing /etc/network/interfaces in the manner you would a real host with an IP address that is on the same network that the bridge br0 has been configured with.

Qemu console

You can access the qemu console by typing CTRL+ALT+2 in the qemu console running any machine. Typing help is gives a list of commands. As an example stop will suspend any machines and cont resumes them.

External References

Edit | Attach | Watch | Print version | History: r8 | r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r4 - 2008-05-05 - WalterTautz
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback