Thursday, May 6, 2010

Adding a new server to the MINIX 3.1.6 kernel.

For a class project I was required to add a new service to the MINIX kernel.  In MINIX, all the essential parts of the operating system are implemented as services.  For example, the file system is a service, the process manager is a service and so forth.

To my dismay, no documentation on adding a service exists (or is hard to find), except in my project's description.  Unfortunately, that too was outdated.  After much experimentation, here's what I discovered needs to be done to add a service:

(1)  Copy an existing service to create foundations.  Most services need the same basic structure: a dispatch loop that checks for messages and executes system calls.  The services have source code in /usr/src/services.  Simple servers to copy include ds (data store server) and is (information server).  For example:

$cp -r /usr/src/servers/ds /usr/src/servers/foo

Here, "foo" is the abreviated name for the new service.

  • You should modify the Makefile in your /usr/src/servers/foo folder to update the name of the binary.  You should only have to change the first or second line.
  • It would be a good idea to appropriately modify the Makefile in /usr/src/servers at this point as well.
  • Once you get everything working, you should remove all the code from the other service that's not relevant to you.  When I created my server from the ds server I ended up deleting store.c, store.h and removed calls from main.c to functions in those files.

(2)  Add "foo" to the boot image.  Since MINIX uses a microkernel architecture there are several places where boot image information needs to be updated.  In general, the order that services are listed in tables are important as it determines the order they startup.

  • /usr/src/tools/Makefile contains the Makefile that compiles to boot image.  You must add the path to your binary in the 'programs' variable.
  • /usr/src/include/minix/com.h lists constants for all of the boot image processes.  You'll see entries like "#define DS_PROC_NR ..." for each process.  You'll need to create your own constant for your process and update the constants on the other ones so the order is consistent.
  • /usr/src/kernel/table.c has a table of the boot image processes that the kernel uses.  This needs to be updated and is fairly self explanatory.  You will want to copy values from another process for the fields.  You could change the values if you know what you're doing, but you don't really need to.
  • /usr/src/servers/rs/table.c has THREE tables that you'll need to fill out.  Again, I would recommend copying entries from other processes.
  • /usr/src/servers/rs/manager.c has a list of if statements around line 1645 that needs to be updated with information for your process.
(3) That should be it!  You should recompile the kernel using 'make fresh install' from the /usr/src/tools directory.  It should be possible to compile it using a command like 'make install' or 'make hdboot' instead, but it's sometimes hard to know.  You should reboot to make sure your service starts up, and then you can start hacking!

6 comments:

  1. Oh there's a side note here, you can't put your new service ANYWHERE in the list of services. Putting it right after "ds" works fine.

    Check this post for more information: http://groups.google.com/group/minix3/browse_thread/thread/abfd159848367036/ae90a90b02ef026c?lnk=gst&q=add+service#ae90a90b02ef026c

    ReplyDelete
  2. I lied, you must put your new service between VM and INIT. Also you MUST update the Makefile in /usr/src/tools so that your process is in the same order it is listed in all the other files. The makefile dictates the startup order of the processes.

    ReplyDelete
  3. but I put my new server at 11, and it works fine. Just remember to change NT_BOOT_PROCS to cover the last process.

    BTW, for rs/table.c, one had better to understand what it means. rs/const.h and kernel/priv.h will help.

    ReplyDelete
  4. hello sir,
    Actually i am trying to mount pendrive in minix 3 but it is not happening so please tell me what should i do.I have added a usbcontroller and usb is also coming in vmplayer under removable disks
    please help me out i'll be thankful to you for this consideration............

    ReplyDelete
  5. Please help. I am a newbie to Minix. I am adding a new server by copying ds in minix3. I did everything mentioned above.
    Only difference being in /usr/src/servers/rs/table.c I could find only one table to replace for the new DS. Also in /usr/src/servers/rs/manager.c I could not find any statements to update.

    After running make hdboot and rebooting I am getting error "kernel panic expecting 12 boot processes found 13". I have increased the #define LAST PROCESS by 1 to 11. So cant fiugre out why its not working

    ReplyDelete
  6. Unfortunately, everyone is a newbie to Minix, and I really have no expertise here. I wrote this about four years ago (and never looked back), and since then I'm sure things have changed.

    Based on the error it sounds like something is counting the number of services and getting a different number than expected, so you probably forgot to update some table/#define somewhere.

    Double check table.c and manager.c. I remember that those two files in particular were crucial for everything to work. Make sure that there is really nothing that specifically lists services.

    The only thing I can add is this: I found places where I needed to list the new service by grep/find. You can search for keywords that you see in the tables for new places to modify tables.

    Also, if you've lost track of your changes, it can be a good idea to start over.

    ReplyDelete