A strategy for developing in Minix

In Operating System Design and Implementation (diso, as we say in Spanish, from here on) we have to work with the Minix kernel source code. The first practical assignment involves implementing a system call.

Of course we use some emulator to run this mini Unix. But how to work? How to modify the kernel and test it? From Minix with vi and the shell that doesn’t remember the commands we execute? It would be nice to work in GNU/Linux (or whatever system we use), move the changes somehow to the Minix partition, compile there and verify that everything works correctly.

We could create a raw partition from QEMU. Then we mount it in GNU/Linux, work there, then boot Minix with that partition to compile and test the changes. The problem with this solution is that it’s still inconvenient: we can’t have the same partition mounted on both sides (our system and Minix). I already tried it, and while it seems to work, it causes inconsistencies in the file system. Actually, this method doesn’t work if we don’t remount the partition.

The solution I found was to configure Minix for the network and use the ftp server. Below are the steps to follow to achieve this.

First, you have to compile Minix with Network support (worth noting we’re talking about Minix 2.0.2). However, it’s not that simple. The problems come with the network card that QEMU emulates. Although we can change the model (-net nic,model=model), the best supported card is NE2000, from what I’ve seen. We can emulate the ISA or PCI version. I didn’t investigate the first one. To give PCI support to Minix you have to patch (they’re three small changes) the file /usr/src/kernel/dp8390.c. This file corresponds to the DP8390 task, responsible for handling the NE2000 network card. From here you can download the patch. I don’t remember which page I got it from.

Once we finish compiling, we copy the image somewhere and close the system (shutdown) and exit QEMU. As root, we run the emulator again, as follows:

# qemu -hda minix202 -net nic -net tap

The “-net nic” option makes it emulate the network card (by default the ne2k_pci model), and “-net tap” creates a device in our Linux, /dev/net/tun, which we can configure as we want (for this reason we need to run the emulator as root). If you use Debian, you already have a script /etc/qemu-ifup, which takes care of configuring that device with IP address 172.20.0.1. Done, we’re now in contact with the guest system. We just need to configure Minix correctly.

When the Boot Monitor starts, press Ctrl-Alt-2, to go to the QEMU shell. We’re going to verify if the network card loaded correctly, and see what IRQ and what address it has.

(qemu) info network … ne2000 pci macaddr=… (qemu) info pci … Ethernet controller: PCI device… IRQ 11. BAR0: I/O at 0xc100…

To avoid extending too much on the Boot Monitor, I’m leaving you this image so you can see how I configured it. Obviously, change the options according to your system.

Boot Monitor

The image has a link to view it in original size, in case you can’t see it well on this page.

The next step is to configure RARP, to indicate the IP address of our Minix. Open the file /etc/ethers and put the MAC address of the emulated network card (information we obtained from the QEMU console), a tab, and the machine name (for example “minix”). More info with “man ethers”.

With this we only map the MAC address with a host name. To get the IP, we edit the file /etc/hosts, add our host name and its IP address (remember that the address set by QEMU in Linux is 172.20.0.1, with the first two octets representing the network, so use an IP compatible with that). It’s also good to already add an entry in this file for your Linux host.

With this, and if I didn’t forget to mention anything, we now have contact with the emulated world. Do a ping from your Linux or from your Minix to verify. Now it simply remains to configure the ftp server.

I use the root user directly. Whatever user you use to log in, give it a password (otherwise it doesn’t work). Done. Using Nautilus or Konqueror you connect, edit what you have to edit, save, compile, test, etc etc etc… no need to mount or unmount anything being careful not to damage the file system.

Licensed under CC BY-NC-SA 4.0
Last updated on Sep 23, 2006 21:52 UTC
comments powered by Disqus