Project 3: GIMIX - MINIX Setup
Assignment Day | September 26, 2016 (Monday) |
Due Date Check PT1 | October 06, 2016 (Thursday) Setup and Patch (part 1 and part 2) |
Due Date Check PT2 | October 10, 2016 (Monday). Demo System Call (part 2 and part 3) on Tue Oct 11, 2016 |
Collaboration Policy - Read Carefully
You must work on this project individually, but you may discuss this assignment with other students in the class and ask and provide help in useful ways, preferable over our email list (piazza) so we can all benefit from your great ideas. You may consult (but not copy) any outside resources you including books, papers, web sites and people (but no penguins or sea urchins).
If you use resources other than the class materials, indicate what you used along with your answer.
You have probably guessed it by now - every project will have a similar paragraph to the one above but with slight variations, or not.
Objective:
The main objectives for this assignment are:
- Part 1: Set up your virtual machine emulator on your system, if you don't have one.
- Part 2: Download, install and setup Minix on the emulator/virtual machine you set up in the previous step.
- Understand MINIX and software structure.
- Modify and 'rebuild' a MINIX Kernel.
- Learn about patching.
- Submit patch on nike (check point 1)
- Part 3: Write a simple System Call, using a tutorial (Challenge : this tutorial is for an earlier version of MINIX but you need to use a later version so there may be different names of variables, and files in your Minix version. Minix is a well documented kernel, and previous classes that used a similar version of the kernel successfully implemented this task.
A variation of this tutorial/project is drawn from Darrel Long's class and is used by permission.
Lessons from other students taking this course in the past:
1) Participate on the google Minix group, this is a fantastic resource (see here). Follow the group protocol if you post questions (e.g., search and see if your question has already been answered).
2) Use google - you won't get penalized - it is a win-win tool
3) Use the class list, but to get a reply - be courteuous and outline what resources you have tried before posting, e.g., I tried searching on google for "add a sysstem call to MINIX", and I posted on the google Minix group, but I did not get a reply
4) backup frequently - your kernel will crash - and it will crash often, and
5) have fun! you can if you want to, you are all in the same boat (:
Tutorial / References
MINIX resources programming/tutorials:There are several MINIX resources that I found useful. http://en.wikipedia.org/wiki/MINIX_3 (see great links at bottom). MINIX Wiki Installation Guide (outlines the process nicely, be sure to follow the links). MINIX Wike Installation Guide detailed (newer and above, but the first listed is still useful). Minix Setup (insights on running MINIX on WMware you can get 30 days for free, you can use other free Virtual Machines, people from this class have used Virtual Box successfully). http://www.minix3.org/manpages/index.html (Minix man pages) How to implement a system call:http://www.phien.org/ucdavis/ta/ecs150-f03/syscall.html VMWare resources programming/tutorials:http://www.vmware.com/products/player/ (free VMware player) |
If you find other resources please post links on the mailing list for the class. |
Background:
The Minix operating system comes with a complete set of tools, including C compiler and linker as well as debugger (this is not true of latest version of Minix - which you will not be using). If you want the less wordy description skip to the bottom of this page and just do each bullet point.
Install VMware:
- Download VMware for free (30 days trial for people with a mac platform).
- Win/Linux=VMware player. (free version);
- Mac=VMwareFusion. (select "Get Free Trial" for now - 30 days)
- Install VMware (easy)
Before you install Minix you need to install a platform where Minix runs. Minix runs (and have been tested) on both actual hardware and machine emulators (or virtual machines as we called them in class). Maintaining a uniform machine for a large class is close to impossible we will use an emulator for the class.
Hardware emulators that I have tried (that also runs on a mac) include Bochs, QEMU (Q for mac), Virtual Box, VMware, Virtual Box and Parallels. We recommend, VMware for this project for the following reasons - we had the least problem with VMware, it has a nice interface, it performs well, and it has a large user base, including MINIX developers (and MINIX users). It is free if it runs on top of Window, it costs $79.99 on top of OS X (mac OS).
For the obsessed shopper of emulators - here is a nice comparison chart from Wikipedia.
Install Minix:
After you installed your 'platform', you need to download and Install Minix. Minix is distributed as a [compressed] CD image file (.iso file) - which are easily installed on VMware. An 'image file' is simple an archive of an optical disk, a single file containg lots of smaller files.
It is '.iso' because the archive file format is a standard defined by the International Organization of Standards. ISO actually have a double meaning: the acronym (ISO) and isos which in Greek means equal - It was a deliberate double meanin and itsignifies the aim of the organization which is to equalize and standardize across different cultures.
You may have heard of other ISO standards from the organization, for example the ISO standard for speed of photographic film (ISO 5800), but in addition to file ISO and CD image file ISO, there are 17,500 other standards including the grading standard of Saffron (the world's most expensive spice) and the size of paper (A4 - european paper size). The CD image file is ISO 9660.
Back to business (if you use windows - a button may be in a slightly different location (bottom vs. top)) in getting started with Minix. Note there is lots of available documentation online (in addition to the one in the red box on how to install Minix. For installs on physical machines, take a look at the Minix install docs here. For installation on Qemu, there is a nice set of instructions here. Note : You can chose your platform (virtual machine) because your implementation of projects will graded according to how you perform you demo in class, and by inspecting your code. So, be sure it works on your laptop that you will bring to class when demo your project (and future projects). Having it work on your workstation at home (only) will give you a 0.
Installing Minix is fairly straightforward, and involves several key steps:
1. Download Minix (minix_R3.2.1-972156d.iso.bz2), and decompress it.
2. Configure your Virtual Machine to boot from the downloaded CD (ISO).
3. Run the setup script (pgin)
4. Reboot from the installed Minix on disk (and not the ISO image).
- Download Minix 3.2.1 from here, do not use the latest version since 1) it does not contain source, and 2) the C compiler does not work on Minix 3.3.+
- Decompress is (from iso.bz2 to simply an .iso).
- Check the Minix Wiki (here - I took notes (see here)- so follow along or skip).
- Select the OS to be 'other', not the 64 bit).
- Choose a virtual disk option - Create a new Virtual Disk
- Customize settings (simply call it MINIX3.2.1) and then save.
- Set the Network Adapter - Bridge Auto Detect
- Set Disk Size - 4G then hit Apply button
- Set Memory Size - 512MG
- Set the Startup Disk so it boots from the ISO Image: Click on CD/DVD Icon - Hit Add - Choose DIsk or Disk Image Then Select the dowloaded ISO from you directory.
- The goal now is to boot from the ISO then install the image (Operating system) on to a virtual disk, and then run setup, once you ran the setup you need to boot from this new virtual disk that you created).
- Boot from ISO: Select CD/DVD Icon, then select it to be the starup disk (this instructions may be different on a Window Machine).
- Once you enabled you virtual machine to start up from the MINIX ISO you run the setupscript called "setup" so just type setup when you get to the # prompt.
- log in as root (Yay!)
- no password (just hit return)
- You will now have access to several vitual terminals of your Minix OS, use (Mac=fn+option+F1/F2/F3) or (Win/Linux=Alt+F1/F2/F3) to see them.
- start setup script to install MINIX 3 on 'hard disk'
- just type:
- 'setup'
- Steps 1-7 just pick the defaults
- Step 8 again pick the defaults: AMD Lance and DHCP
- Select it so the network adaptor is shard with your platform
- just type:
- When done setting up your virtual machine: Shutdown, Shutdown your Virtual Machine, Now reset your virtual machine so that it starts up using your virtual disk instead of the ISO image.
- so essentally you will neet to change your startup disk to be the hard disk.
- Next go to post intallation ( here ).
- Change password of root
- passwd root
- you will need this later so you can change to super user mode su when you ssh into your Virtual Machine that runs MINIX.
- follow the instruction at post installation - link above
- Add a new user (example user 'ingrid' - but you should select a name for you login), and add the user to the group, set the initial password for the user
- user add -m -g users ingrid
- passwd ingrid
- type:
- pkgin update
- Install the binary packages (see here).
- Make sure to include ssh
- pkgin install openssh
- You may need to set the .profile of the user so it sets the TERM variable to vt100
- export TERM=vt100 or you can do it by hand once you ssh into your MINIX machine.
- After install type shutdown -r to reboot the system. On boot up you should see messages about an ssh keypair being generated and the sshd service running.
Use sftp to easily transfer files to/from Minix and your host OS:
- Start from Minix:
- Logged in as root, you can now add a user (see above
- Check the manpages on MINIX, man user.
- Example:
- user add -m -g users ingrid
- Example:
- Still logged in as root, set up telnet and ftp to run in the background on Minix so you can connect to it.
- See here:
- http://wiki.minix3.org/en/NetworkingConfiguration
- See here:
- Exit minix as root; 'exit'
- Login as your new user.
- You should be at your new user's home directory: 'pwd'
- Make a directory for your work: 'mkdir cs4730'; 'cd cs4730; 'mkdir project2;
- Create a sample file in there called 'test_on_minix.txt', using some text editor ('vi' or 'mined' (use ctrl+x to exit mined))
- Get Minix's IP address: 'ifconfig', this will be your current minix_ip_address
- Make sure you are connected to the outside world: 'ping nike.cs.uga.edu'
- Problems?
- Try: Setting VMware to use NAT rather than bridged, and restart Minix (see instructions above for shutdown). (Mac=VirtualMachine->NetworkAdapter->NAT; Win/Linux= Devices->NetworkAdapter->NAT) This seems to solve most problems.
- Try: Setting your home router to use DHCP, and restart Minix (see instructions above for shutdown).
- Try enabling the services using the following command:
# intr -d tcpd telnet in.telnetd &
# intr -d tcpd ftp in.ftpd &
- Now, from your host machine
- Open a terminal window and cd to your class work directory.
- Create a sample file in there called 'test_on_host.txt', using some text editor.
- Connect to Minix via sftp: 'sftp minix_ip_address'
- Login as the user and password you just created.
- Check your location, you should be at the user's home dir. In your ftp window, type 'pwd'. Now cd to your work dir: 'cd csX730/project2'.
- Use sftp to move your files around. Use the commands 'get' and 'put' (or 'mget' mput' for multiple files) to push and pull your files. Try it:
- 'get test_on_minix.txt'
- 'put test_on_host.txt'
- Check both places and verify the files have been transferred.
- Type 'quit' to exit ftp and disconnect from Minix.
Using Putty (see here - similar project look for sub heading).
MINIX Familiarization
Once the network is active, you might want to install a few other applications to make your life easier (unless, of-course, you used the install all option above). For example, you might want an editor (such as vim), openssh (to exchange files between Minix and the outside world using scp), a new shell (such as bash), or a version control system (such as svn). Also, check out the source code of Minix that is located in /usr/src and get a feeling for which parts of the OS are located under which directories.
Once you have played around a little bit and have become more familiar with Minix, answer the following questions (you may use the Minix Wiki to answer these)
- Provide a brief description of your installation, including whether you installed MINIX on a simulator (and if so, which one) or on what hardware, and if on actual hardware, whether you have a dedicated machine or a machine that multi-boots Minix and other operating systems. Also (whether on real hardware or on a simulator), the size of your disk and the amount of memory available to the OS.
- What is the name of the application (utility) that you used to install new software in Minix?
- What is the command that you need to issue to rebuild the kernel and install it?
- What is the kernel source file that holds the Minix banner string (i.e., "MINIX 3.2.1 ...") that is shown when Minix boots up?
- What is the name of the Minix system call with the number 33 (decimal), and how did you determine this information?
- Why does a new installation of Minix come with an existing user called "ast"?
The answers to these questions have to be written in a plain ASCII file called discussion.txt, which you will need to submit as part of this project (see below for instructions).
Part 2: Simple Kernel Hack & Create a Patch
At this point, it is time to rebuild the kernel.
Check the page for hints on rebuilding the kernel:
http://wiki.minix3.org/doku.php?id=developersguide:rebuildingsystem
Go to (this may be different from later kernels this is for (3.1.x) so double check the above page, essentially;
/usr/src/tools and invoke make.
Check the options to see how a kernel can be rebuilt and installed. Make sure you select the third option "Start custom kernel" in the start screen so you run your new and freshly built and improved kernel.
When you are able to build a new kernel, it is finally time to make a small OS modification (and enter the realm of kernel hacking). First, however, you have to make a clean copy of the kernel source tree.
This is necessary for two reasons. First, when you later make changes that do not work and you want to have a reference that you can look at, the source is already there. Second, and more importantly, you need such a clean reference to create patches (see below).
So, just issue a cp -r /usr/src /usr/src.clean, and you are good to continue. Of course, you can additionally store (backup) your modified and clean source trees on a remote machine (using rsync or scp, for example) or using version control system. At this point, you should not be modifying any code directly on Minix. Run the following on your developement machine:
rsync -rptOv minix:/usr/src/ minix_src_cleanNote that rsync may fail occasionally. If that happens, just continue to re-run rsync until you receive no errors.
For the kernel modification itself, you need to print out the name of every file that is being executed by the OS.
You should locate the kernel source file that implements the exec system call. Then, at the right point, you should insert a printf statement that outputs the string "executing ... " followed by the name of the file that is being executed. That is, when you type "ls" in the shell, you should see the string "executing ... " being printed to the console. More precisly, if a process executes /bin/ls, your code should print to the console "executing /bin/ls".
This should actually require only a single line to be added, but it provides you with some (very basic) debugging facilities. Once you have done your modification, rebuilt the kernel, install it, and reboot the system. When you were successful, you should now see a series of output statements that show you which programs the operating systems launches.
Your last task of part 2 is to submit your changes to us. When dealing with large software systems (e.g., operating systems such as Linux), it does not make sense to send around the complete source code tree for every small change. For this, people invented patches. A patch captures the changes between two different files (oldfile and newfile). Given the oldfile and the patch, one can use the patch program to create the newfile. This is exactly what we want. So, when you have finished your kernel modification (including recompiling, installing, and testing everything), you switch to the /usr directory and produce a patch for each file that you have changed. For this, you invoke
diff -ruNp (path/to/oldfile) (path/to/newfile) and store the output in a file named mypatch (so redirect standard output to a file).
For example, when making a patch of the file /usr/src/servers/inet/clock.c, you would first change into the /usr directory (containting both src.clean and src) and then do
diff -ruNp src.clean/servers/inet/clock.c src/servers/inet/clock.c. > mypatch
You can test whether your patch has worked by creating another copy of the source tree (e.g., /usr/test), change to /usr/test and run patch -p1 < mypatch. This should modify the clock.c file in the /usr/test tree accordingly. Also, note that this is how we test your patches, and we expect that they can be applied cleanly (without any warnings or errors).
Part 3: A Simple System Call
You are to write a system call, numberprocs(), that returns the number of processes currently running in the system. Use the below tutorial for this.
https://github.com/rhiguita/lab-minix/blob/master/eng_us/Seen2-Creating_a_System_Call-English.txt (your kernel)
http://www.phien.org/ucdavis/ta/ecs150-f03/syscall.html (older MINIX kernel but may contain useful instructions).
Submitting:
Submitting:
|
Optional:
Install your shell that you created in project 1 in the proper place and test it out and debug if needed for 5 pt extra credit.