Ubuntu Server KVM and LVM

I obtained the latest version (3rd  Edition) of The Official Ubuntu Server Book a couple of days ago and in just my first browsing of this new tome on Ubuntu Servers, I found a complete section dedicated to implementing KVM on Ubuntu Server.  KVM is an acronym for Kernel Virtualized Machine which qemu/ovirt to implement something called libvirt.  This system allows you to implement virutal machines that are easy to build and configure and they run fast, provided you have a capable 64 bit VT enabled hardware.  Forget about VirtualBox or VMware Workstation unless you are running Windows.  KVM also provides something called paravirtualization which means you don't have to install extensions or do guest installs on your virtual machine so that they can connect properly and use the hardware resources provided by the host system.  I knew from previous work, that I could install  the KVM virtual manager on my Ubuntu machines and manage my virtual machines that were being hosted on Red Hat and Fedora machines but it wasn't a full implementation and there were some things I couldn't do from the Ubuntu KVM Virtual Manager.  Long story made short, the Server Book provided so much information on implemeting KVM at the command line, I had to give it a try.

My first run at KVM on Ubiuntu was to install the 12.04 LTS Server version that came with the book.  This went well but the book seemed to be missing some information as to the complete process.  These are the steps I took as the root user to get KVM installed on the server at the command line.  No desktop is installed with the server version so using Virtual Manager to create, configure, and manage my virtual machines was out of the question.  Here's the short list:

Note: You must first become root in a terninal session (gnome-terminal, terminal, xterm) or at the login shell, if not desktop.  Once you have a terminal session open or have logged into your server as your regular user, on Ubuntu, you must type sudo su - and then your regular password, at which time you become the root user.  You cannot login directly as root on Ubuntu as that is disabled in the default installation.

I also had a question on useing the KDE desktop in doing this.  To install the KDE desktop on a server or as an alternate desktop, see this link:  https://help.ubuntu.com/community/InstallingKDE Then enter apt-get install kubuntu-desktop to do the actual installation.

Continuing:

apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder
Edit the /etc/network/interfaces as follows using vim or your favorite text editor:

# The primary network interface
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

/etc/init.d/networking restart
verify that br0 for bridged networking is present by entering ip addr and see if br0 is shown in the output onthe screen
apt-get install libcap2-bin

Edit the /etc/security/capability.conf file by adding the line as shown below for your user ID with your favorite text editor:
cap_net_admin  tinslecl

Then:
setcap cap_net_admin=ei

Finally:
/usr/bin/qemu-system-x86_64
exit
reboot the computer to get everything started properly.

You should now be able to build and configure kvm virtual machines at the command but it is a bit complicated:auto eth0
You can test your acces logged in as your user by simply entering: virsh -c qemu:///system list
If this works without error, you are in business.

I tried using Ubuntu's vmbuilder for kvm but not very succesfully from examples in the book:
vmbuilder kvm ubuntu --suite precise --flavour virtual --arch=amd64 --hostname test1 --libvirt qemu://system --rootsize=2048 --swapsize=256 --user ubuntu --pass insecure -d test1-kvm.
This would fail, I would later find another  example in the Ubuntu Unleased 2013 Edition that would build the kvm using vmbuilder and it looked good until I ran it.  I would just run the virutual machine to 100% CPU utiliization where it would just sit, no virtual console login or anything: 
vmbuilder kvm ubuntu --suite precise --flavour virtual --arch i386 -o --libvirt qemu:///system --ip 192.168.0.100 --hostname lovelace --bridge br0
virsh -c qemu:///system start lovelace to test it.

Since I was familiar with the KVM Virtual Machine Manager and the ease with with you can build, configure, and use the virtual machines, I decided to install the LXDE (Lubuntu) desktop along with Virtual Manager.  The server install provides a text based tool called tasksel (command line) which allows you to select certain package groups for installation including LAMP server and the LXDE desktop.  Once the desktop was installed and I was logged into the desktop (a reboot maybe required), I then went back to the command line to do the finish work:
apt-get install virt-manager
virt-manager

Then using the KVM Virtual Machine Manager (under system on the Menu is LXDE), I was able to build a KVM Guest using the 64 bit of LinuxMint 13 (12.04/Precise) and was able to configure it for bridged networking as well as nat.  Things worked well but things like bridged network configuration were not easy and infact, the Virtual Machine manager would even tell you that "Network Interface" management was not supported in the tool but I have br0 bridged networking implemented and it did work following the steps above.

Fast forward to Ubuntu 13.10, I had  12.10 Unity running on another laptop so I decided to bite down hard and upgrade this to 13.10, the current supported release of Ubuntu.  This was not as easily done as my upgrade from Fedora 17 to 19 and it almost broke my system but I sort of got it working at 13.04 and then did another upgrade that took the machine to 13.10; these operations took about 2 hours to get done with all the glitches.  In retrospect, perhaps I should have done just a clean install of 13.10.  I also implemented Lubuntu/LXDE as my alternate desktop for this project.  It was a lot easier to  get kvm installed and working on 13.10 plus the KVM Virtual Machine Manager seems to do everything it should including managing Network Interfaces and when I install LinuxMint 13 64 bit on this machine, my bridged interface (br0) was there at installation time.  The KVM experience on Ubuntu was now the same as my experiece using KVM in the Red Hat Enterprise Linux environment.  Cool!  Here are the steps I took to get KVM installed and working on Ubuntu 13.10:

apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder

Edit the /etc/network/interfaces as follows using vim or your favorite text editor:

# The primary network interface
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_fd 9
bridge_hello 2
bridge_maxage 12
bridge_stp off

Then restart the network with the command: service networking restart
ip addr
apt-get install libcap2-bin

Edit the /etc/security/capability.conf file by adding the line as shown below for your user ID with your favorite text editor:
cap_net_admin  tinslecl

Exit and reboot your computuer.

apt-get install virt-manager
apt-get install virt-viewer
reboot

After doing this, I was able to use the KVM Virtual Machine Manager from the desktop and build/configure/use my virtual machines.  Life is good!

On Logical Volume Manger, when I installed the Ubuntu Server 12.04 LTS version that came with the book, I discovered that on a new install, it uses LVM "out of the box" so agan, I had a deja vue experience in that here again, I could work the same as I do on Red Hat Enterprise Linux!  Wow!  Those operations that I detailed in the Boise Linux Group October report and  demonstrated at the meeing now work on 12.04 LTS and subsequent releases.

Reading some more in that new "Official Ubuntu Server Book" third edition, I found more similarities betwen Ubuntu Server and Red Hat Enterprise Linux as the next chapter after the KVM one was on Cloud technologies including OpenStack.  I now have three  books on Ubuntu 12.04 and later.  Unfortunately, there are technical ommissions in all three but the still serve as good references in learning how to implement and use these technologies on Ubuntu Server:  The titles are:

Ubuntu Unleashed 2013 Edition, SAMS pjublishing, Ubuntu 12.10 and 13.04.

Ubuntu 12.04 Server Administration and Reference, Petersen.  (No reference here to KVM techologies.

The Officia Ubuntu Server Book, Third Edition, Prentice Hall.

I am hoping that at future meeting, I will be able to demonstrate some of this to the group but in the meantime, take a look at these books and learn about all the technology that is now available on Ubuntu Server in the Enterprise Environment.