How To Create A Debian VM With Qemu

July 7th, 2010

I would like to post my notes as a little tutorial here. I am usually using these virtual machines as cheap staging servers. The first part of this tutorial, you hopefully need to do only once: creating a fresh Debian system. In the second part we will build on this image to create many different servers.

Creating A Base Debian System

We will create a Qemu machine and install Debian Lenny on it first:

# Download Debian image
wget http://debian.osuosl.org/debian-cdimage/current/i386/iso-cd/debian-504-i386-businesscard.iso

# Create base VM image
qemu-img create -f qcow2 debian.qcow2 2G

Our disk image will have a 2 Gigabyte size limit. You can pick a different size if you need.

Now we need to power on our VM and install Debian:

# Install Debian
qemu -enable-kvm -k tr -cdrom debian-504-i386-businesscard.iso -hda debian.qcow2 -boot d

You don’t need to allocate a large swap disk, 128MB should do just fine for a file/web server. Also I wouldn’t bother creating a seperate partition for /home/.

Next let’s log in as the user (www here) we have created to make final changes:

# logged in as user
dpkg-reconfigure console-data
aptitude install ssh sudo
echo "www ALL=(ALL) ALL" >> /etc/sudoers

At this point you might want to take a backup of debian.qcow2. (Even though we will open it only read-only from now on)

Creating The Actual VM

To save time and space we will use copy-on-write disks and re-use debian.qcow2.

# Create the actual VM's disk
qemu-img create -f qcow2 -o backing_file=debian.qcow2 actual.qcow2

Actually we are done. You can log in to your VM using the following command and start installing/configuring/running:

qemu -enable-kvm -k tr -hda actual.qcow2 -net user -net nic \
                                         -redir tcp:5022::22 \
                                         -redir tcp:9080::80

A few things to note about the command above:

  • -enable-kvm is meaningful only if you have kvm kernel module installed. It improves performance a great deal, so it’s highly recommended.
  • You probably need to change -k tr according to your keyboard’s layout.
  • We are setting up two TCP redirections. 22 is for SSH and 80 is for HTTP. You can add more ports if you need.

Finally, I suggest you to prefer SSHing your VM instead of logging in directly:

# SSH into the VM
ssh -p 5022 www@localhost

I hope some of you find this useful.

Bookmark and Share

How to Install MySQL with Fabric

May 22nd, 2010

I just want to share a small fabfile snipplet that installs mysql-server package on a Debian machine if it’s not already installed. Actually it should have been quite straightforward; just issue an apt-get command, right? But during configuration it displays a curses dialog for MySQL root password. This of course blows your automated configuration plans. We will seed this value to debconf database to avoid this dialog.

First let’s have a look at the supporting code:

from __future__ import with_statement
from fabric.api import *
from fabric.utils import warn

def apt_get(*packages): sudo('apt-get -y --no-upgrade install %s' % ' '.join(packages), shell=False)

Our apt_get fabric command issues apt_get install that answers yes to all questions and does not upgrade if the requested package is already installed. Now let’s take a look at the main command that installs mysql-server:

def install_mysql():
    with settings(hide('warnings', 'stderr'), warn_only=True):
        result = sudo('dpkg-query --show mysql-server')
    if result.failed is False:
        warn('MySQL is already installed')
        return
    mysql_password = prompt('Please enter MySQL root password:')
    sudo('echo "mysql-server-5.0 mysql-server/root_password password ' \
                              '%s" | debconf-set-selections' % mysql_password)
    sudo('echo "mysql-server-5.0 mysql-server/root_password_again password ' \
                              '%s" | debconf-set-selections' % mysql_password)
    apt_get('mysql-server')

First we want to make sure mysql-server is not already installed. For this reason we issue dpkg-query --show mysql-server. Note that if this command fails then mysql-server is not installed and we can proceed otherwise we want to return. We hide the ugly error messages by running our dpkg-query command within a settings context:

with settings(hide('warnings', 'stderr'), warn_only=True):
    result = sudo('dpkg-query --show mysql-server')
if result.failed is False:
    warn('MySQL is already installed')
    return

The rest of the code is pretty straightforward. We prompt to the user running fabric for the root password and seed its value twice into the debconf database.

sudo('echo "mysql-server-5.0 mysql-server/root_password password ' \
                            '%s" | debconf-set-selections' % mysql_password)
sudo('echo "mysql-server-5.0 mysql-server/root_password_again password ' \
                            '%s" | debconf-set-selections' % mysql_password)
apt_get('mysql-server')

Finally, having finished our little dance, we install mysql-server. I hope this helps some automated deployment believer out there.

Bookmark and Share

My Idea Of The Django Blogging App™

April 28th, 2010

I am not going to talk about yet another Django-based blogging engine in this post. There are a number of blogging apps which try to be like turn-key solutions, like a WordPress blog. I have skimmed through the code of many such apps, but haven’t used one yet. Some of them are really high quality apps. What I have in mind is somewhat different though. I would like an app that would allow me to build a blog that satisfies my projects specific requirements.

Let me reiterate the last sentence. Having a Django-based blog just because Django is fashinable is a little dumb in my opinion. If Django-based X blogging engine suits you better than anything else, use it. Why not? But my personal choice of blogging engine is WordPress1. The value of a Django blogging app, for me, is in adding a blog to a Django project. And different projects might have different requirements. So my idea of a Django blogging app is one that is highly configurable and highly extendable.

On the other hand I don’t need the convenience of clicking a checkbox on a polished UI. I can write a function. Or I don’t necessarily need it to, say, provide a navigation menu. There are apps that do that. Even if there wasn’t it shouldn’t be the blog app’s job. So I am not looking for an instant-blog. I have a Django app in my mind, nothing more.

What Should Be Left Out

Basically any feature that can be provided by another reusable app should be left out. Why should we re-implement something that is already done… and reviewed by others… and tested. Of course this doesn’t necessarily mean providing no convenience functions.

  • No admin. Because we already have one.
  • No theming. For the love of Flying Spaghetti Monster, you don’t need any theming other than what django.template offers. Pre-built themes are for turn-key solutions.
  • No comments or contact forms. (See django.contrib.comments and django-contact-form)
  • No official markup format (or formats). This can be handled in the templates without difficulty. But, maybe, pluggable content filters is a good idea. I haven’t made up my mind on this one entirely. It won’t use any markup format by default, that is for sure.

What Should Be Included

Remember, every project has a different set of needed features for its blog. Some need catagories, some need tags and some others need both. But it would end up as a disaster if we implemented each one of those features into a single app. Instead I think it should consist of many small apps that work together. But I wouldn’t want to end up having huge spaghetti of apps that all depend on one another, like Pinax does. A minimal amount of core apps2 and then everything else should be optional. By optional I mean you don’t have to install packages you won’t need.

I think the components (apps) should be activated via adding to INSTALLED_APPS and configured with settings. I can’t think of any parameter that needs to be changed dynamically, so why not use the established way of doing configuration in Django.

Two must have features for such a blogging app are previews and scheduled publishing. It is possible that you sometimes write a post quickly and publish it immediately. But I suppose nobody will say they don’t care about these two features.

Built-in feeds and sitemaps are also nice to have.

Multiple instances of this blogging app running on the same project? À la admin. I can’t make my mind on this one. Sure it would be a nice feature. But it could complicate the code. Peehaps too much for a not so common case.

What do you think about the general idea? Are there any other must-have features? Would you be willing to learn a new app when you are already comfortable with another blogging app?


1: Even though it’s written in the abomination called PHP. But since there are plugins for everything I don’t have to touch the code.

2: One sounds like a good number, if possible.

Bookmark and Share

Why Not To Localize Community Support

April 16th, 2010

If you are reading this, you know English. I would like to pose a question before we go any further; would you prefer community support in your native language over what international community offers?1

By community support, I mean free software support provided by the user community. Every successful project has some form of communication; mailing lists, forums, IRC, wikis, etc. And the preferred language is almost always English. Simply because you can reach more people. People who can use your code. Who can test it, file bugs, send patches, etc. It is the logical thing to do. But in the spirit of freedom, I think nobody should be forced to use a certain (natural or programming) language for something they have created.

Real Communities

I think having local communities is a great idea. I don’t know, because we don’t have any in Türkiye2. So I am just guessing they should be cultivating and fun at the same time. We do have many local pseudo-communities though. There is some activity, people come and go, some of them stay much longer than the others. But they never progress towards a community. I think this is because they make the fundamental mistake of localizing community support. They translate documentation intended for highly technical people and create new channels that no advanced user will bother to participate. In short, they attempt to sidestep the language barrier.

If want to be a programmer you need to know English. It is not optional. It is not a requirement of being a good programmer. You are at most an excellent script kiddie without proper English skills. Obviously, knowing perfect English doesn’t make you a great programmer instantly. It will increase the resources you can access dramatically, though. And most importantly it will give you the chance to know more about what you don’t know. Stay in your little world to play with your mates who know just as little as you do and you will never improve.

A Foolish Endeavour

Some people, who spend time with these pseudo-communities, know English well enough. They are probably acting with good intentions when they provide support in their native language. But they are actually wasting their time. Having been solved one specific problem doesn’t make the other person a better programmer. On the contrary they are giving local users another reason to avoid solving the real issue. The function of a community should be supporting each member’s continuous improvement. That doesn’t necessarily mean solving their technical problems for them3.

What is wrong with asking questions in a native language if on a local channel or face to face with local people? Nothing. There is absolutely nothing wrong with that. It would be silly to speak another language there. But if you really want to improve, you can tap into a greater source of information. It is your choice. Pseudo-communities will only take you so far. Because they are only generating more newbies, and not supporting newbies become experienced users. Do they produce anything but empty talk?

Why should a local community produce anything? What should the product be? I will probably write another post about this soon. But feel free to post your ideas and critics in the comments.


1: Obviously, it only makes sense if your native language is not English.

2: I would very much like to be proven wrong on this one. If you know any, please write a comment and don’t forget to include a website and date of the last meeting.

3: Also note that there is a difference between helping someone solve a problem and solving the problem. Spoonfeeding does more harm than good.

Bookmark and Share

Free Software & Linux Days 2010

March 29th, 2010

Free Software & Open Source Days of İstanbul Bilgi University and Linux & Free Software Festival of Linux Users Association are united under the name Free Software & Linux Days this year. If you have attended before, you will probably make no other plans for April 2-3.

If you have never been to this event, registration is free and can be done at the front desk. If you are remotely interested in free software or hackerdom you will want to be there. …and, of course, you are welcome.

I will be giving a Django presentation on Friday. Please come and say hello if you happen to be attending.

UPDATE: You can find the slides from presentation here. Slideshare’s importer failed to import the file I’ve uploaded properly. So please download and view the slides with Acrobat Reader.

Bookmark and Share