CS 160 - Homework One
An Introduction to Minix

Drake University
Spring, 2006



Due date: 1/25




Outline of the homework objectives

This assigment is intended to be a fairly straightforward introduction to the following:

The skills gained here will be essential to the later programming projects. You need to go through each part carefully to become comfortable in the Minix environment.



Details about the assignment


  1. The Minix computer has been set up with two copies of Minix in two different hard disk partitions (hd1 and hd2). Most of the time, you will be booting and using the copy on the second partition, which is refered to as hd2. However, when you cold boot the computer, it will automatically boot the version on the first partition, which of course is caleed hd1. We do not want to alter the version of Minix on this partition, in order to ensure that we can always boot some version of Minix. After cold booting, log into Minix as "root" (no password required). Then issue the command halt, or press CTRL-ALT-DEL, to shutdown Minix. You will then be presented with a different prompt. At this point, you are no longer communicating with Minix, but rather with the "boot monitor." From here you can reboot Minix either using hd1 or hd2. You simply give the command "boot hd1" or "boot hd2".

    Why do I want you to be able to boot two different copies of Minix? The answer is that while working on projects, you will make alterations to the Minix kernel, the one on hd2. As with all software development, you are likely to get it wrong at first. But if you mess up the Minix kernel, you won't be able to boot that copy of Minix anymore. Or, as in the case of the last exercise in this homework, you could render the kernel awkward to use. I've arranged for a simple and quick fix. All you need to do is to boot the other (still working) copy of Minix (on hd1), log in, and then execute the command "fix_other", which will copy to good kernel over to replace the bad kernel. We'll practice this at the end of this homework assignment. If you somehow blow up both copies of the kernel, then please let me know ASAP, so I can reinstall Minix.

    When working in Sheppard, please do not leave your own work on the hard-drive.
    You will learn how to format Minix disks, and you should use these to transfer work in and out of the lab. I will supply you with floppies for this. Work left on the hard-drive will be erased and I might start getting cranky about the issue. You do not need to submit anything for this exercise. It is sufficient that you understand how to perform the above operations to get around in the system.

  2. The next step in our initiation into Minix is to discover how to transfer files to and from diskettes. While you're at it, you'll compile and run a fun little C program I found on the internet. The projects will involve C programming, recognizing that some students might be confortable with Java, but not C. You will be introduced to the needed C constructs as we go along. Now, log back into Minix, and use the command

    cd /usr/mqr

    followed by the command

    ls

    to move into the directory containing the program and to see what else is in this directory. You can then give the command

    more life.c

    to examine the program. Use the space key to advance a page at a time or the enter key to advance a line at a time. Then compile the program by giving the command

    cc life.c -lcurses -o life

    Then give the command

    ./life

    to execute it. You will need to use CTRL-ALT-DEL to kill the program, but this will also terminate Minix. So reboot Minix again. You don't need to submit anything concerning this exercise, but be sure you understand what is going on (except that you don't need to understand how the life program behaves).

  3. You will need to get some exposure to at least one of the available text editors on the Minix computer. There are three text editors available to you: an emacs-like editor called elle, a vi-like editor called elvis, and a friendlier text editor called mined. You can read the man page for each. For example, type "man mined" to learn about the mined text editor. You can also find more info on these editors by doing a Google search on the name of editor combined with "Minix". Figure out what you like and use it. Experiment with the life.c file. Try altering it a bit to get the hang of the text editor you opted to use, but please restore it to its original form. The safest way to do this is to execute the command "cp life.c life.c.old" before altering life.c, and later, after playing with it, executing "cp life.c.old life.c" . Again, you don't need to submit anything concerning this exercise.

  4. Minix has its own file system structure. It is possible to structure the files on a diskette using this system, and to mount (attach) this to Minix's overall file system. (Many of you have no doubt had experience with a similar situation in Linux.) To get exposure to doing this in Minix, do the following:

    • format a diskette using     format /dev/fd0 1200
    • add a Minix file system to it using     mkfs /dev/fd0
    • mount this to the overall file system using     mount /dev/fd0 /mnt
    • copy a file to the diskette using     cp life.c /mnt
    • view this using     more /mnt/life.c
    • unmount the diskette using     umount /dev/fd0

    You don't need to submit anything concerning this.

  5. The next exercise is to examine some of the system commands available to you in Minix. Change directory using cd /usr/bin and then view the (executable) files there using ls | more . Some of these should look familiar to you from Linux. Spend a little time exploring the manual pages for some of the commands. For example, to learn about the command ls give the command "man ls". Not everything there will make sense to you, but some of it should. Then explain carefully what each of the following commands does:

    • man man
    • whatis whatis
    • whereis whereis
    • which which
    • size size
    • du du
    • du
    • ls -ls ls
    • ls -alsFR
    • grep grep *
    • pwd

    Your answers to these questions should be submitted and can be handwritten.


  6. The final exercise involves making small changes to the Minix kernel, rebuilding it, and rebooting Minix to see the effect. You will also learn how to recover from any catastophic changes made to the kernel. Proceed as follows:

    • Boot up Minix on hd2, and log in.
    • Move into the directory /usr/src/kernel.
    • Copy the file proc.c to proc.c.old , for a backup.
    • Carefully edit proc.c as follows:
      • Locate the definition code for the function sys_call.
      • Locate the line in this that says "case NOTIFY:".
      • Just before the break; statement that ends this case (which is line 07575 in the source code listing in Appendix B of the textbook) insert the following statement: kprintf(".");
      • Now save and exit the text editor.
    • Give the command rebuild and watch it rebuild the Minix kernel, and then reboot Minix on hd2. If you made a mistake, it won't be able to reboot. In this case, you will need to boot Minix on hd1, log in, give the command fix_other, halt, reboot Minix on hd2, correct your mistake, and try again.
    • Once you have successfully altered the kernel, notice the effect your change to proc.c has on the system behavior. Play around in here for a bit, and you'll see something funny happening.
    • Now to undo what you have done, give the halt command, boot Minix on hd1, log in, give the command fix_other, halt again, boot Minix on hd2, log in change directory to get into /usr/src/kernel, and then give the command "cp proc.c.old proc.c" and then use rebuild again.

    Submit a brief account of what you experienced and learned from this exercise.


    Please turn off the computer and video monitor after logging out.
    Please remember to do likewise in the future.