Fr 11. Dez 18:22:55 CET 2009

Access partitions in loopback devices under linux

Ever needed to access a partition inside a block device not supporting partitions like /dev/loop or software raid? There exists multiple solutions like specifying the offset via losetup or patching the kernel. But this is error-prone and not very user friendly.

An easy and more user friendly way of supporting partition tables in any block device is kpartx. Besides the name, is has nothing to do with kde but is a tool from multipath tools to map partition tables to the device mapper.

After you installed kpartx you can easily create mappings from a block device with kpartx -a and delete them via kpartx -d. For example:

# echo p | fdisk /dev/loop0 
Command (m for help): 
Disk /dev/loop0: 102 MB, 102400000 bytes
255 heads, 63 sectors/track, 12 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

      Device Boot      Start         End      Blocks   Id  System
      /dev/loop0p1               1           5       40131   83  Linux
      /dev/loop0p2               6          12       56227+  83  Linux

# kpartx -a /dev/loop0
# ls /dev/mapper/loop0p*
/dev/mapper/loop0p1  /dev/mapper/loop0p2
# kpartx -d /dev/loop0
# ls /dev/mapper/loop0*
ls: cannot access /dev/mapper/loop0*: No such file or directory

To make a long story short: kpartx is a easy and handy solution for using partitions from any block device under linux making management of images for virtual machines quite simple.

Posted by Ulrich Dangel | Permanent Link | Categories: Shell stuff

Fr 18. Sep 15:50:44 CEST 2009

Bootstrapping Fedora to directories

Currently there is some discussion on debian planet about installing Centos/Fedora to an directory under debian.
As mentioned in the comments and another blog entry there exist several other simpler solutions.

febootstrap allows you to install centos/fedora really easily just like deboostrap.
Example to install centos in directory c5:

# febootstrap centos-5 c5
# .....
# chroot c5 cat /etc/redhat-release   
# CentOS release 5.3 (Final)

mach is another more generic way to bootstrap rpm based distributions to a directory. For an overview of the features just have a look at the README Example to install centos:

$ mach -r centos-5-i386-os setup base 

If you just want to install Fedora/Centos into some directory use febootstrap as it is quite simple and does the job.
But if you want to rebuild rpms or bootstrap any other rpm based distribution like SuSE, Yellowdog use mach

Posted by Ulrich Dangel | Permanent Link | Categories: Shell stuff

Fr 18. Sep 14:14:13 CEST 2009

Unit testing for shell scripts with shunit2

Recently I stumbled upon a bug of an funtion in a shellscript and wanted to make sure that this bug never happens again. So i searched around and found shunit2 a nice xUnit based test framework for shell scripts.

If you ever had thought about writing unit tests for your shell scripts, do it! Its really easy, and shunit2 also supports zsh
Example test sript:

#! /bin/sh
  assertEquals 1 1

. shunit2

For more examples have a look at the tests for grml-autoconfig or at the example directory of the shunit2 package

Posted by Ulrich Dangel | Permanent Link

Sa 29. Aug 19:45:30 CEST 2009

cdn for debian or location aware entry in /etc/apt/sources.list

The upcoming grml release will use per default in /etc/apt/sources.list to always use a mirror near to your location.

To use it, just replace existing host names with
deb stable main contrib non-free 

Posted by Ulrich Dangel | Permanent Link

Sa 20. Jun 03:38:59 CEST 2009

Automatic security updates for Debian based systems

unattend-upgrades is a debian package providing automatic security upgrades.

To use it, just install unattended-upgrades, modify /etc/apt/apt.conf.d/50unattended-upgrades to your needs like:

Unattended-Upgrade::Allowed-Origins { "Debian stable"; };
To automatically and unattended install security updates you also have to set
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
in /etc/apt/apt.conf or in a file located in /etc/apt/apt.conf.d/ (I use /etc/apt/apt.conf.d/60security)
For further details have a look at /usr/share/doc/unattended-upgrades/README or

Just setup unattended-upgrades and life becomes more easy as you dont have to remember to upgrade each of your machines.

Posted by Ulrich Dangel | Permanent Link | Categories: Shell stuff

Sa 20. Jun 03:10:56 CEST 2009

One command line interface for multiple RDBMS systems

sqlline a java based console program allows you to connect to any database with existing jdbc drivers replacing the original programs like mysql, sqlplus or psql.

Example to connect to an oracle database with sqlline:

$ java -cp ~/path/classpath/classes12.jar:/usr/share/java/sqlline.jar sqlline.SqlLine
sqlline version 1.0.2 by Marc Prud'hommeaux                
sqlline> !connect jdbc:oracle:thin:@hostname:1521:xe USER PASS
Connecting to jdbc:oracle:thin:@hostname:1521:xe
Connected to: Oracle (version Oracle Database 10g Express Edition Release -
2: jdbc:oracle:thin:@hostname:1521:xe> 

Posted by Ulrich Dangel | Permanent Link | Categories: Shell stuff, Stuff

Fr 20. Feb 20:04:37 CET 2009

Static ip assignment with libvirt

I just started to use libvirt and needed to have static ip assignment for some of the systems. Libvirt supports this but there is no documentation for this, a patch with documentation has just been send to the mailing list, but thats all (except the documentation in the *.c files ;-)

A simple example which assigns to the host with the mac AA:BB:CC:DD:EE:FF:
  <bridge name='intbr0' />
  <ip address='' netmask=''>
      <range start='' end='' />
      <host mac='AA:BB:CC:DD:EE:FF' ip='' name='foobar'/>

Posted by Ulrich Dangel | Permanent Link | Categories: Stuff

So 11. Jan 13:13:05 CET 2009

Short overview about mpris and command line tools

mpris player

media mlayer remote interface specification, short mpris is a specification to connect media players via dbus. This is quite useful as you can have one command for example to control Amarok, Audacious or any other mpris capable player.
This are all gui player, so lets have a look at mpd, a music daemon simple to control via commandline.
mpd natively does not support dbus, but there is another solution, mpDris, a mpd client exporting the mpris functionality via dbus.

mpris client

A really nice and powerful mpris command-line client is mpris-remote to access an mpris capable player. Here are some examples commands:
mris-remote pause # toggle pause 
mris-remote next # next 
mpris-remote random true 
mpris-remote random false 
it is really intuitiv, so just use ist.

So what is the benefit?

  • You only have one command to control them all, so you can just switch your music player and your scripts will work. So instead of binding player specific commands to, e.g. your multimedia keys on the keyboard, consider using mpris and it does not depend if you use mpd, amarok, audacious or any other client.
  • Additional features are possible, for example inhibit power-manager when playing music, so you can close the lid, unhibit when music stop so your pc can start sleep. And this works for multiple player out of the box.
  • You can can subscribe to signals from the music player, so you can just get the information and don't have to check the status regular
So, if you going to control a music player via commandline, look if the player support mpris and use this, instead of proprietary command line.

Posted by Ulrich Dangel | Permanent Link | Categories: Stuff

Sa 3. Jan 17:22:10 CET 2009

Mark build dependencys as automatical installed

The latest apt-get version in experimental has is a really nice feature, which allows to mark all packages installed with apt-get build-dep as an automatic install.
You can set the option on the commandline
apt-get -o "Apt::Get::Build-Dep-Automatic=True" build-dep gnome-power-manager

or set it in the config file
$ cat /etc/apt/apt.conf.d/99builddep 
APT::Get::Build-Dep-Automatic "True";

To remove the dependencies just use apt-get autoremove

Posted by Ulrich Dangel | Permanent Link | Categories: Just me, Stuff

Mo 29. Dez 23:52:10 CET 2008

Mehr als 800 Zuschauer innerhalb von 5 Minuten ....

beim diesjärigen Hacker Jeopardy beim 25C3.
Ich habe da u.a. ich beim Theora Streaming mitgemacht, und wir haben dazu von der FEM ihre MMS Streams transcoded und Theora Streams bereitgestellt. Kurz vor Start hatten wir ca. 400 Zuschauer, danach >1200 Zuschauer.
Stats theora streams
Das ganze auf 4 Servern (2 an der Uni Ulm, einer an der BA Lörrach und einer im BCC) verteilt. Sehr coole Aktion!

Posted by Ulrich Dangel | Permanent Link | Categories: Stuff, 25C3