Posted 12-18-2014

(This page is from the front page posting of the same name)

My regular programming site has been off-line for awhile. This WP page should work for a couple posts, at least. One of the things I’ve been doing lately is that I’ve been looking at the kernels of operating systems developed by small groups of people, or OS projects that might be described as hobby projects. These are wonderful things for a guy who’s spent most of his life doing user-land programming. Even a user-land programmer gets to brush up against the kernel occasionally, when using traditional systems. We may be involved with writing the drivers, living at the periphery of the kernel, if we have some hardware knowledge. Most of us don’t even do that.

Yet – we never really gain a comfort level, and we live with a feeling that there’s “stuff going on down there,” in the big blackbox that underlies all. We’re never necessarily one hundred percent sure about what is going on “down there”. Most people like me have a latent desire to know more about all that which lies below their own code, inside the system kernel, and makes their own code possible. Few ever do anything about it. Kernel developers have few peers, and live in the rarefied airs of programmingdom.

For the inquisitive, wanting to dabble, a better place to start playing in kernel-land is to study one of the small kernel projects. This approach compacts the learning curve, and filters the extraneous, because small kernel developers have no time for extraneous. I’d rather study these little kernels than the bigger ones in operating systems such as Linux or FreeBSD. I’m using the former, mostly (Debian Linux) – to facilitate the expansion of my coding knowledge in this realm. I’ve chosen a kernel to use in the experiment, and it comes from a nice little system that goes by the name of Visopsys, and is primarily the work of one man (not me). While it’s a work-in-progress, it’s an excellent choice for our kernel debugging experiment. The site for the project is:

http://www.visopsys.org

An assortment of installation media can be found on that site, as well as all of the source (It is GNU/GPL2 copyrighted by its talented author – J. Andrew McLaughlin).

So, how do we go about setting things up? Are you inquisitive enough to have read this far?

Inside of twenty minutes, you could be kernel debugging your kernel of choice (well, slight exaggeration) in a session such as this one:

On Debian Wheezy, there are a few packages we need to set up before we can begin debugging kernels. A standard desktop installation of Debian Wheezy is a good place to start. I installed the full gnome package as well.

Development packages can be installed with aptitude:

aptitude install gcc build-essential nasm gettext zip wodim genisoimage gdb qemu emacs

We’ll need the source for the kernel. The source is available on http://www.visopsys.org. As the download link supplies us with a zip file, unzip the source to a convenient location. We’ll need an image of the system we can boot. The installation ISO image available on the same site provides us with that.

Finally, we’ll need a hard disk image (virtual disk) that QEMU can use. We’ll create that with a QEMU tool:

qemu-img create -f raw ./vistest.img 1G

The qemu-img command will supply us with a 1G “virtual drive” (in a file) that qemu will see as a hard disk. The raw format is the oldest format. To compile the kernel, go into the source directory (top level) and type “make”. In my case, I added the -g option to the kernel Makefile, so that I could debug the kernel. You can make the entire build a debug build if you want. If all goes well, the newly compiled kernel is put into the {top-of-source-tree}/build directory. Take a look in there, type “date” and compare to see that the kernel file-date matches the system date.

Now type this command:

gdb ./visopsys

The debugger should tell you that it found debug info in the kernel when you do this. So, we’ve gathered most of the pieces and parts for our debugging session. The first launch of our target OS with qemu will be without frills. Later, we’ll launch it with networking enabled. As a regular user, type this line to start the simple session in a stopped state:

qemu -hda ./vistest.img -cdrom ./visopsys-2014-12-13.iso -boot d -s -serial stdio -S

Go to next section of article