CS161 In-Class Exercise 1/29/15

After completing this exercise, you should be able to:

Configuring and Compiling OS/161

If you happened to not check the web site, then you probably have not installed the CS161 tools on your own VM. To make things a bit easier, we prepared a VM image with the CS161 tools installed. You can download it from here. Once you've done that, please prepare a clone of the os161 code base, following the instructions here. Then continue on to the next steps.

At this point you've created the working copy of the os161 repository and it's time to configure and build your own operating system. We will do this in two parts. First we will configure and build user level utilties, and then we'll configure and build the actual kernel (operating system).

Fire up your virtual machine and cd into the top level of the os161 directory:

% cd cs161/os161
The configure script in this directory indicates where to place the things it builds. By default, the configure script will put the kernel and its support files in $HOME/cs161/root. Run ./configure --help to see the options available. Next, run configure with an option that tells you where to place your root directory:

% ./configure --ostree=$HOME/cs161/root

Now let's build and install the user level utilities. Note that we are not yet building the kernel; these are user-level programs that will run in our operating system. Also note that we are using BSD make (bmake) and not the usual Linux GNU make. Complicated build systems like OS/161's are easier to write in BSD make.

% bmake
% bmake install
Let's make sure this wasn't all black magic. Traditionally operating systems place the files and utilities they need directly on file systems that the operating system itself provides. As might be apparent, there is a bit of a startup problem there. While you will not be undertaking any file system development until assignment 4, OS/161 comes with an emulated filesystem that passes requests from OS/161 to the file system on the computer on which we're running our simulated hardware (System/161) and our operating system (OS/161). In this case, OS/161 can retrieve files that reside on your virtual machine. Thus, files in your installation root (again, $HOME/cs161/root by default) will be available in this manner from inside OS/161. After you've built and installed your user level utilities, look in $HOME/cs161/root and see what's there.

Now that you have some utilities built, let's build a kernel! The first thing you will need to do is configure the kernel. Kernel configuration files live in kern/conf, (from now on all path names will be relative to your os161 directory, which should be ~/cs161/os161). If you look in that directory, you will see one configuration file per assignment. These configuration files describe which device drivers to include and various other sundry options. When the config script is run on them, a corresponding directory under kern/compile is created. So for now, do:

% cd ~/cs161/os161/kern/conf
% ./config ASST0

This will create and populate the directory kern/compile/ASST0 in which you will be able to compile your kernel as configured by the ASST0 configuration file from kern/conf. Note that you should specify the complete pathname ./config when you configure OS/161. If you omit the ./, you may end up running the configuration command for the system on which you are building OS/161, and that is almost guaranteed to produce rather strange results!

So, last but not least: compile the kernel!

% cd ../compile/ASST0
% bmake depend
% bmake
% bmake install
You have now built your first OS/161 kernel and put it in the right place. Congratulations!

So, when you want to build a kernel, you have to do four things:

  1. Configure the kernel you want to build by running config on a config file in kern/conf. This creates a kernel build directory in ../compile with the name of the config file you used.
  2. Create dependencies for the kernel you wish to build (by running bmake depend in your kernel build dirctory.
  3. Build your kernel using bmake.
  4. Install your kernel using bmake install.


The astute observer might be wondering where, exactly, the computer is that you're supposed to be running this new operating system on. That is, after all, the point of an operating system, right?

The answer is that the computer is simulated. You will run your operating system on a virtual machine known as System/161, which simulates a MIPS-like hardware architecture. System/161 reads in a binary operating system kernel image and then takes responsibility for simulating what would happen if real hardware with a real processor were to try to run it.

Ultimately, you do not need to understand the details of System/161's design or operation; you need only understand how to use it. You can view the full guide to its use here.

Before you can run System/161, however, you need to provide it with a configuration file. A sample can be found in ~/cs161/sys161/sys161-2.0.2/sys161.conf.sample. Copy this to your OS/161 installation root:

% cp ~/cs161/sys161/sys161-2.0.2/sys161.conf.sample ~/cs161/root/sys161.conf

To run your compiled kernel in System/161, type:

% cd ~/cs161/root
% sys161 kernel

You can play around with the current kernel, check out what commands it supports and simply experiment. You can't do anything bad, so just play with it for a minute!

Code Reading

Pull up Assignment 0 from the Web site. The last part of the assignment is a walk through of the OS/161 source tree accompanied by a set of questions. You should begin to work through those questions now. You may discuss them with your table-mates and help each other find things. We also encourage you to discuss what's really happening in the code. We cannot emphasize this enough, but the more familiar you are with the code NOW, the more ready you will be to begin assignments. We suggest that you spend class time on questions labeled Discuss Me!.