Ubuntu Server Virtual Guest Creation

By sean on Aug 02, 2012

For anyone looking to setup a virtual environment, this post should save you a bit of headache. There are quite a few paths you can choose when looking to setup some type of virtual management system: Virtualbox, VMware, and KVM just to name a few. Personally, I feel as if KVM is the easiest to use and manage plus it’s free on top of being extremely easy to use via command line. Through out this tutorial you’ll see Resource links; when I was attempting to do this myself I used several sites to accomplish the subject at hand – these resources are what I used as a guide and may be able to assist you further than I can. Instead of spending hours upon hours googling, I figured it would be nice to include them here

Also red text is the hostname of the guest you wish to create, it will be referenced several times and this is just an easier way to point it out. You can name it anything you like.

okay so first we’ll need to install the vm builder package

sudo apt-get install ubuntu-vm-builder

now if we wanted to, we could create the ( very basic, with all options set to default ) guest. but let’s not do that

sudo ubuntu-vm-builder kvm hardy --libvirt qemu:///system

The above command simply tells the ubuntu-vm-builder that we want to create a virtual guest from the ubuntu hardy build and that we want to use virsh to manage it. Now there are several other arguments you can pass which will help define your guest more so than the default. Below is a link that can help you in setting up your virtual guest along with how I’ve setup mine. Also keep in mind, you will need to append −−libvirt qemu:///system to the end of the code you receive from the link provided below as it won’t be included.
Resource: https://help.ubuntu.com/community/KVM/CreateGuests
Param Builder: http://thebwt.com/ubuntu-vm-builder.html

sudo ubuntu-vm-builder kvm hardy --arch 'amd64' --mem '128' --rootsize '4096' --swapsize '1024' --kernel-flavour 'generic' --hostname 'server' --mirror 'http://archive.ubuntu.com/ubuntu' --components 'main' --name 'sean' --user 'sean' --pass 'mypassword' --ip '' --mask '' --net '' --bcast '' --gw '' --dns '' --addpkg 'openssh-server' --libvirt qemu:///system
This process could take a few minutes depending on your internet connection. Oddly, the tutorial on Ubuntu’s help site claims you can use a local mirror to speed up the process, although I’ve yet to get it to work properly. Most of the arguments are self explanatory. −−user would be the username you want use along with −−pass for the password. −−hostname would be the hostname for the guest etc. etc. −−addpkg is for any additional packages you’d like to install; as you can see we have openssh-server because for some reason it wasn’t installed by default – and you can add as many packages as you’d like, just separate them by space.
ex: −−addpkg ‘openssh-server nano bind9′

For all intents and purposes you’re done – you could simply launch virsh and start the guest but, there’s a few more things you’ll probably want to accomplish before getting to that step: such as getting your guest to access the LAN otherwise half the arguments you passed to the vm-builder would have been for nothing. So what we’re going to do is create a bridged interface for your guest to access.
Resource: http://wiki.libvirt.org/page/Networking#Debian.2FUbuntu_Bridging

You’ll need to edit your network interfaces

sudo nano /etc/network/interfaces

Now find your main interface, for this example we are using eth0, and remove the “allow-hotplug eth0″ line replacing it with “auto br0″. Then change the next line from “iface eth0″ to “iface br0″. Afterward, define the interface as being a bridge and specify its ports.

Your configuration should now look something like this:

auto br0
iface br0 inet static
        bridge_ports eth0
        bridge_stp off
        bridge_maxwait 5

Once that’s done, save and exit then bring up the new interface

ifup br0

Finally append the following lines to ‘/etc/sysctl.conf’ using your favorite text editor.

net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0

Now we load the new settings

sysctl -p /etc/sysctl.conf

You should now have a “shared physical device”, to which guests can be attached and have full LAN access. Now we just need to edit the guest and inform it to use the bridge we just created. Edit ‘/etc/libvirt/qemu/server.xml’ and look for a line that begins with: .

sudo nano /etc/libvirt/qemu/server.xml
Your going to need to change ‘network’ to ‘bridge’ then look for and change ‘network’ to ‘bridge’ and ‘default’ to ‘br0′. Afterward, append and you don’t need to edit the mac address.
Resource: https://help.ubuntu.com/community/KVM/Networking#Configuring%20ubuntu-vm-builder%20to%20create%20bridged%20guests

So that bracket should now look like this – your mac address will be different

<interface type='bridge'>
      <mac address='52:54:00:f3:60:2a'/>
      <source bridge='br0'/>
      <model type='virtio'/>

You’re pretty much done, simply open virsh and start your new guest.
Resource: http://docs.sun.com/source/820-3838-10/chapter3.html

sudo virsh

Now that we have virsh open you need to define your new guest

define /etc/libvirt/qemu/server.xml
Afterward, turn your new virtual guest on
start server
Once you’ve gotten to this point, simply wait a moment or two for the guest to startup ( like you would any machine ), then you should simply be able to SSH into it using the IP you specified within the initial ubuntu-vm-build statement.

Additional Resources:


Sign in to comment.
sean   -  Aug 09, 2012

Nope, never seen it work like that anywhere. It just would have been nice to be able to manually color objects in code rather than switching to quote tags.

Hawkee   -  Aug 09, 2012

@sean Not sure if it can be handled that way. This is just a standard bbcode encoder. Have you see other sites where it works?

sean   -  Aug 09, 2012

@Hawkee It would be cool if the color bbcode worked within code tags :P

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.