Yearly Archives: 2011

Currency Signs

Euro sign “€”
Dollar sign “$”
Pound sign “£”


Ubuntu 11.10 (Oneiric Ocelot): Installing KVM 2

Without any additional comments, we managed to install KVM over a fresh installation of Ubuntu 11.10 (Oneiric Ocelot).

To do this we installed the following packages from the repositories and added our user to the libvirtd group.

We called kvm-ok to make sure that our hardware supports KVM properly and thus having better performance.
Installation Commands:

sudo apt-get install kvm libvirt-bin
sudo adduser $USER libvirtd
sudo apt-get install virt-viewer
sudo apt-get install python-vm-builder
sudo apt-get install bridge-utils
sudo apt-get install virtinst #for cloning

After these we created a virtual machine with the following command:

sudo vmbuilder kvm ubuntu --suite oneiric --flavour virtual --arch amd64 --mem 1024 --cpus 2 -o --libvirt qemu:///system --ip --hostname uranus --part vmbuilder.partition --user userName --name MyName MySurname --pass myPassword --addpkg unattended-upgrades --addpkg acpid --addpkg nano

where in general, what it does is, create an Ubuntu Oneiric Ocelot JeOS virtual machine that has an AMD64 architecture, 1GB of RAM, 2 Virtual CPUs, it’s name is uranus, has a user with the username userName, has pre-installed some applications like nano and enabled automatic updates for the system.

C: How to tell the status of a socket

If you are trying to check if a socket is empty but you cannot use select(), because what you need is to check the write buffers instead of the read ones just to be sure that you have successfully managed to send all data to your peers before terminating, or if you want to tell if a socket buffer is full.

You can use the ioctl to find out.

To check a write buffer if it empty (assuming you have already put data there and want to check if they were consumed):

ioctl(fd, SIOCOUTQ, &pending);

Where fd is the socket’s file descriptor and pending the variable were the remaining size of data will be returned.

To check a read buffer if it empty (assuming someone has already put data there and you want to check if they there is any without consuming them):

ioctl(fd, SIOCINQ, &pending);
*note the difference on the second parameter, where we change the flag from SIOCOUTQ to SIOCINQ

Among other includes be sure to add these:

#include <sys/ioctl.h>
#include <linux/sockios.h>

How to setup DNS service for DHCP-enabled KVM guests

So you’ve set up KVM on your machine and you have installed a few guests to run on top, now it’s the time to access them.

Since KVM can run without a GUI, you might want to control these guests from the command line. But, how can you do it if you do not know the IP of the guests?

You can either connect to the guest using virt-viewer:

virt-viewer -c qemu:///system $MACHINE &

which requires more bandwidth since it will open up a VNC session.

Or, use ssh to connect using the guest’s name, like this:


which doesn’t require that you know the IP beforehand.

To achieve this, access guest machines using their hostname only, you can do the following: Edit /etc/resolv.conf and add the line nameserver right after the search entries .

Your file should look something like this afterwards:

Then you are ready to go! No restarts needed no extra steps.


  • After restarting (and some times periodically), the /etc/resolv.conf file will return to its original form because it is updating each time you restart the host machine from data it gets via the network DHCP server.
  • For this tutorial to work as is, your host machine needs to have the virtual IP (the default IP of your host in libvirt — NOT THE IP of eth0, it’s a totally different thing). If you have a different libvirt IP use that one in the /etc/resolv.conf file.
  • Use your host’s IP as your first nameserver in /etc/resolv.conf to achieve name resolution for your guests.

A note on installing a Linux based system on a two hard disks machine

The Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in Linux operating systems and according to that, there should be a directory called /var/ where variable files, files whose content is expected to continually change during normal operation of the system, such as logs and spool files should be stored there.

It might be a good idea to have this directory on a separate disk from / and /swap since all these folders have lots of I/O operations and it is a known fact that hard disks have limited capabilities and usually hard disk are slowing down a system. By having /var on another disk it should help increase the I/O capabilities of the system drastically and improve system performance.

How to change hostname (computer name) in Ubuntu (or Ubuntu Server)

If you do not have Unity/Gnome/KDE/or some other window manager, to do this you need to be familiar with a command line text editor like vi/emacs/nano.

To change your hostname simply edit /etc/hostname and restart the machine.

The /etc/hostname file should only contain the actual hostname, which makes editing it quite simple since you will just replace the hostname in the file with the one you want to assign.

NOTE: Elevated privileges are required, only administrators can edit this file.

bash: killall: command not found — A solution 1

On some systems like the JeOS version of Ubuntu, some commands that we consider trivial are not installed and usually there is an alternative that we are not aware of (e.g instead of nano there is vi).
In this case there is the pkill command that will send a specified signal (or SIGTERM if not specified) to all processes that match the name (more options are available).
For example instead of

killall badProcess

you can use

pkill badProcess

which is also pretty easy and straightforward.

Another solution,

would be of course to install it. If you have enough access you can install the package psmisc using the following command (in Ubuntu / Debian):

apt-get install psmisc

For RHEL – Red Hat / Fedora:

yum install psmisc

This package contains the following useful programs:

  • fuser – identifies what processes are using files.
  • killall – kills a process by its name, similar to a pkill Unices.
  • pstree – Shows currently running processes in a tree format.
  • peekfd – Peek at file descriptors of running processes.