debian snippets

Changing the default terminal emulator the Debian way.

Tagged default terminal, debian, ubuntu, x11, linux  Languages bash

Use this to change the terminal emulator that comes with the default installation of Debian (and Ubuntu).

sudo update-alternatives --config x-terminal-emulator

Choose your emulator from the list and hit enter.

How to change the default editor in Debian

Tagged default editor, debian, ubuntu, standard editor, oletuseditori  Languages bash

This command changes the default editor system wide. It should work in all Debian derivatives.

sudo update-alternatives --config editor

Quick step by step on creating a xen environment in Debian Etch

Tagged xen, debian, etch, stable, virtualisointi, virtualisering  Languages bash

Jumpstart with Xen out-of-the-box in Debian Etch stable.

sudo apt-get install xen-tools xen-hypervisor linux-image-xen-amd64 bridge-utils iproute sysfsutils
# [reboot into xen kernel now]
sudo xen-create-image \
--size=10Gb --swap=256Mb --ip= \
--netmask= --gateway= \
--force --dir=/work/vserver --memory=512Mb \
--arch=i386 --kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
--debootstrap --dist=etch \
--mirror= \
sudo xm create /etc/xen/

Creating a local Debian mirror for your Xen servers

Tagged xen, debian, etch, local mirror, amd64, anonftpsync, nginx  Languages bash

Once you've bought a dual or quad Xeon and started to experiment with virtualization you will soon want to create your local mirror to make installs lightning fast. This is a step-by-step how i did it.

First create the Xen that will be our mirror server. The size requirements can be found here: Debian mirror sizes The combined size of amd64 architecture and architecture independent files was 39Gb on 1.9.2007. So I made the image 50Gb big. Remember to change this mirror to a location near you.

xen-create-image \
--size=50Gb --swap=256Mb --ip= \
--netmask= --gateway= \
--force --dir=/work/vserver --memory=256Mb \
--arch=amd64 \
--kernel=/boot/vmlinuz-2.6.18-5-xen-amd64 \
--debootstrap --dist=etch \

Then ssh into your new Xen as root.

ssh -l root

Make base configurations for a fresh Xen.

apt-get update && apt-get install locales console-data && dpkg-reconfigure locales

Then get the mirror synchronization script from Debian.

wget ""
chmod a+x anonftpsync

Then install dependencies for anonftpsync script. Otherwise the script will fail with a -bash: lockfile: command not found error.

apt-get install procmail

Install nginx.

apt-get install nginx

Configure anonftpsync with your favorite editor and change the lines below. These settings will setup a mirror only for amd64 files. You could remove i386 from the excluded architectures, but then a 50Gb image won't fit all the files.

ARCH_EXCLUDE="alpha arm hppa hurd-i386 i386 ia64 m68k mipsel mips powerpc s390 sh sparc source"

Make the log directory.

mkdir -p /var/log/mirroring

Configure nginx by modifying /etc/nginx/nginx.conf with your favorite editor. Just add the autoindex line into server { location / { context

# abbreviated start of file for clarity...
    server {
        listen       80;
        server_name  localhost;

        access_log  /var/log/nginx/localhost.access.log;

        location / {
            root   /var/www;
            # add the line below to allow directory listing
            autoindex  on;
            index  index.html index.htm;
   # abbreviated end of file for clarity...

Do the synchronizing. And wait... for a long while. On a 8/1Mbit cable the first synchronize took roughly 20 hours.


Now modify your /etc/apt/sources.list on existing Xen images to use your local mirror. And remember to create new Xen images using your new mirror :) In the above case the URL is

NB: there is no public available... sorry.

Fix for "Failed to find an unused loop device" when using xen

Tagged xen, debian, xen source, loop devices  Languages bash

If you use Xen and get an error "Failed to find an unused loop device" when you try to create a guest then you are probably using disk images and have run out of loop devices. Each guest uses at least two loop devices. Modify (or create) a file called /etc/modprobe.d/local-loop and add this line:

options loop max_loop=64

Use a number suitable for your needs. With 64 loop devices you can run up to 32 guests on your host, assuming you aren't using loop devices for any other purposes.

Custom kernel for Debian Etch

Tagged linux, debian, custom kernel, kustomoitu kerneli, kustomiserad kernel, deb  Languages bash

Sometimes you just need a kernel that is newer than the package manager has to offer. For me it was the bug fixes for the driver of the sound card in x61s. Here's how to do it "the debian way".

tar xjvf linux- -C /usr/src
rm /usr/src/linux && ln -s /usr/src/linux- /usr/src/linux
cd /usr/src/linux
zcat /proc/config.gz > .config
make xconfig

Now turn on and configure the new features you are looking for in the new kernel, save the configuration and finally quit.

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-custom-13.10.2007 kernel_image kernel_headers
cd ..
sudo dpkg -i linux-image-
sudo dpkg -i linux-headers-

The --append-to-version parameter appends the given value into the kernel signature, so that it is easily recognized. If you compile a kernel with the exactly same name as a previous kernel you have then you must move away the directory /lib/modules/your-kernel-name-here.

Check if a file or directory exists with bash

Tagged nginx, daemon, bash, linux, debian  Languages bash

This script tests if nginx exists and is executable. The script prints a warning and exits, if nginx doesn't exists or isn't executable:

if [ ! -x $DAEMON ]
   echo "Couldn't find $DAEMON. Please set path to DAEMON."
   exit 0

See man test for more information on how to use the test command.

Installing nginx on Debian

Tagged nginx, install, debian  Languages bash


Find latest version of nginx

Install a compiler otherwise: ./configure: error: C compiler gcc is not found

The command:

sudo apt-get install build-essential

Install pre-requisites otherwise you'll get:

Configuration summary + threads are not used + PCRE library is not found + OpenSSL library is not found + md5 library is not used + sha1 library is not used + zlib library is not found

The command:

sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

Much better:

Configuration summary + threads are not used + using system PCRE library + using system OpenSSL library + md5 library is not used + sha1 library is not used + using system zlib library

Compile and install nginx

$ ./configure \
        --sbin-path=/usr/local/sbin \
        --conf-path=/etc/nginx/nginx.conf \
        --pid-path=/var/run/ \
        --error-log-path=/var/log/nginx/error.log \
        --http-log-path=/var/log/nginx/access.log \
        --with-http_ssl_module \
        --http-client-body-temp-path=/tmp/nginx_client \
        --http-proxy-temp-path=/tmp/nginx_proxy \
$ make
$ sudo make install

Run the install script

cd /usr/local/src


tar zxvf nginx-0.5.35

cd nginx-0.5.35

Create an nginx user and group

$ useradd -g www-data -d /var/www nginx

Create the web server directory

mkdir /var/www
chown root.www-data /var/www
chmod ug=rwx,o= /var/www

Test configuration

nginx -t
2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf syntax is ok
2008/03/09 20:51:05 [info] 5034#0: the configuration file /etc/nginx/nginx.conf was tested successfully

Start nginx


Compiling Ruby with OpenSSL, Zlib and Readline support on Debian

Tagged ruby, readline, ssl, zlib, debian  Languages ruby

DRAFT... From

Install pre-requisites

apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev

Download and install

cd /usr/local/src


tar zxvf ruby-1.8.6.tar.gz

cd ruby-1.8.6.tar.gz

./configure --prefix=/usr/local --with-openssl-dir=/usr --with-readline-dir=/usr --with-zlib-dir=/usr

make install

ruby -ropenssl -rzlib -rreadline -e "puts :success"

Installing Rails, mongrel and mongrel_cluster on Debian

Tagged rails, ruby, debian, install, sqlite3, mongrel, mongrel_cluster  Languages bash


Install RubyGems

tar zxvf rubygems-1.0.1.tgz

cd rubygems-1.0.1

ruby setup.rb

Install Rails

gem install rails

Install sqlite3 (optional)

apt-get install sqlite3 libsqlite3-dev
gem install sqlite3-ruby

Install mongrel and mongrel_cluster

$ gem install mongrel mongrel_cluster

$ mongrel_rails cluster::configure -e production \
  -p 8000 \
  -a \
  -N 3 \
  -c /var/www/xyz/current

$ mongrel_rails cluster::start

$ useradd -g www-data -d /var/www mongrel

Surviving reboots

sudo mkdir /etc/mongrel_cluster

sudo ln -s /var/www/xyz/config/mongrel_cluster.yml /etc/mongrel_cluster/xyz.yml

sudo cp /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster /etc/init.d/

sudo chmod +x /etc/init.d/mongrel_cluster

sudo /usr/sbin/update-rc.d -f mongrel_cluster defaults

mongrel_cluster_ctl status

Stale pids

If your mongrels crash or if you kill them, mongrel_cluster won't start your mongrels because mongrel_cluster believes the processes are still running, instead mongrel_cluster complains and does nothing:

** !!! PID file tmp/pids/ already exists.  Mongrel could be running already.  Check your log/mongrel.8000.log for errors.
** !!! Exiting with error.  You must stop mongrel and clear the .pid before I'll attempt a start.

To fix this simply add the --clean switch to the /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5/resources/mongrel_cluster startup script:

mongrel_cluster_ctl start -c $CONF_DIR --clean