StepInside

Creativity and Inspiration

September archive

Starting with UML

I have been using Linux for a long time but mostly for developing high level applications in java and python and as home operating system (multimedia, Internet surfing and so on). From everyday usage I’ve gained understanding of how different parts of Linux system work together, how to configure and use various applications, how to find what’s going wrong and many other things. So my experience was mostly “in user-mode” and I have little understanding (except some common principles that are applicable to all modern operating systems) how kernel of Linux works. Recently I became very interested in it for several reasons:

  • I’ve bought laptop and there is plenty of hardware that is currently not supported by Linux, including built-in web cam, microphone and IR-receiver.
  • Linux crashed several times on my laptop and I have no idea why and even how to find out the reason.
  • Some nice features like suspend-to-ram and hibernate don’t work and again I can’t figure why.
  • It’s just interesting and about having fun :)

Unfortunately it is hard to start with kernel development especially taking into account that my knowledge of C language is limited to university courses that I took several years ago. Linux kernel is very large piece of code and it is easily possible to get lost in it.

To have something to start with I’ve decided to play with UML . In particular I’ve thought about creating my own filesystem image for running UML and running UML process in debugger. So exploring source code for UM architecture I can learn about system
programming for Linux (such things like signals, threads, etc) and at the same time learn about kernel by exploring rest of kernel sources.

In this post I am going to describe how to create very simple basic filesystem image and run UML with it.

At first you need to create empty file with ext2 filesystem inside:

dd if=/dev/zero of=minimal-1.ext2 count=10k bs=1024
/sbin/mke2fs minimal-1.ext2

To mount this file as real file system run following command as root:

mount minimal-1.ext2 minimal-1/ -t ext2 -o loop=/dev/loop1

Statically linked busybox can serve as minimal Linux distribution. Installation is pretty straightforward:

make menuconfig
make
make install

Make sure that at least following busybox applets are enabled:

  • init* (CONFIG_INIT)
  • ash (or any other shell, make it default shell, CONFIG_ASH, CONFIG_FEATURE_SH_IS_ASH)
  • mount/umount (CONFIG_MOUNT, CONFIG_UMOUNT)

and it is configured for static build (CONFIG_STATIC). It is also very convenient to configure mounted at the previous step directory as installation prefix (PREFIX).

Now it is time to make some missing directories in just created filesystem:

mkdir minimal-1/proc
mkdir minimal-1/dev
mkdir minimal-1/tmp
mkdir minimal-1/etc

and devices for consoles, terminals and virtual hard drive (run following commands as root):

cd minimal-1/dev
mknod console c 5 1
mknod tty0 c 4 0
mknod tty1 c 4 1
mknod tty2 c 4 2
mknod tty3 c 4 3
mknod tty4 c 4 4
mknod tty5 c 4 5
mknod ubda b 98 0

Only 2 things are left: /etc/fstab:

/dev/ubda /boot ext2 defaults 1 2
none /proc proc defaults 0 0

and startup script (called by init) /etc/init.d/rcS:

#!/bin/sh
# mount proc
/bin/mount /proc
# remount root file system in rw mode
/bin/mount -o remount /
echo "Started!"

Thats all! Now you can unmount created file system or run sync several times to make sure that all changes are written to the file and use it as root image for UML:

./linux ubda=minimal-1.ext2

In the next posts I am going to describe my further experiments with UML.

Posted by ksh on September 5, 2006 | 2 comments | linux

Calendar

August 2008
MoTuWeThFrSaSu
0000123
45678910
11121314151617
18192021222324
25262728293031

Tags

Archives

RSS feeds