Create Ubuntu Server Virtual Guest
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 a great option due to ease of use and it’s free!
Through out this tutorial you’ll see Resource links; when I going through this I used several sites as a reference — these resources can certainly provide deeper insight. Instead of wasting additional time googling, I figured it may be nice to include them here :)
I named my server
salamander; so that it's easily recognizable throughout this tutorial (feel free to name yours as you please).
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 configure your virtual guest, along with the parameters I used for mine.
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.
sudo ubuntu-vm-builder kvm hardy --arch 'amd64' --mem '128' --rootsize '4096' --swapsize '1024' --kernel-flavour 'generic' --hostname 'salamander' --mirror 'http://archive.ubuntu.com/ubuntu' --components 'main' --name 'sean' --user 'sean' --pass 'zyos' --ip '192.168.1.101' --mask '255.255.255.0' --net '192.168.1.0' --bcast '192.168.1.255' --gw '192.168.1.1' --dns '192.168.1.1' --addpkg 'openssh-server' --libvirt qemu:///system
This process could take a few minutes depending on your internet connection. 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 name for the guest.
−−addpkg is for any additional packages you’d like to install; as you can see we have openssh-server (for some reason it's not installed by default). 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 could be done here. 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.
Creating a Bridged Interface
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 a bridge and specify its ports.
Your configuration should now look something like this:
iface br0 inet static
Once that’s done, save and exit then bring up the new interface using:
ifup br0ifup br0
Finally append the following lines to
net.bridge.bridge-nf-call-ip6tables = 0
net.bridge.bridge-nf-call-iptables = 0
net.bridge.bridge-nf-call-arptables = 0net.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/salamander.xml and look for a line that begins with:
Your going to need to change
bridge then look for
<source network='default'/> and change
br0. Afterward, append
<model type='virtio'/> and you don’t need to edit the mac address.
Resource: https://help.ubuntu.com/community/KVM/Networking#Configuring ubuntu-vm-builder to create bridged guests
So that bracket should now look like this — your mac address will be different
Start ‘er up!
You’re pretty much done, simply open virsh and start your new guest.
Now that we have virsh open you need to define your new guest
Afterward, turn it on
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.
Originally published at seanwragg.com on March 31, 2010.