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
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
now if we wanted to, we could create the ( very basic, with all options set to default ) guest. but let’s not
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.
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 '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. 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.
You’ll need to edit your 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:
Once that’s done, save and exit then bring up the new interface
Finally append the following lines to ‘/etc/sysctl.conf’ using your favorite text editor.
Now we load the new settings
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: <interface type=’network’>.
sudo nano /etc/libvirt/qemu/server.xml
Your going to need to change ‘network’ to ‘bridge’ then look for <source network=’default’/> and change ‘network’ to ‘bridge’ and ‘default’ to ‘br0′. Afterward, append <model type=’virtio’/> and you don’t need to edit the mac address.
So that bracket should now look like this – your mac address will be different
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 your new virtual guest 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.