ANU College of Engineering and Computer Science
Research School of Computer Science
This laboratory should take you less than 2 hours to complete. Make sure you ask your tutor for help if you get stuck. You are expected to print out and read through these instructions and to complete about 1 hour of preparation.
Also as the laboratory proceeds you are expected to take notes of your findings/results. This will be shown to the tutor once you have completed the lab.
Familiarize yourself with the software environment to enable you to:
Step 0 - logging in
For the Operating Systems course, we will be using N112,N113, and N114 for the labs (these are the ones we have set up with the ability to reboot from the hard disk and for you to have root access).
Reboot your workstation at the start of each lab and after about 30 seconds or so, it will prompt you to boot from the "net" (normal) or the "disk" (Operating Systems only) kernels. You have about 5 seconds to respond before the system starts booting from the default network image.
To start off reboot into using "net". Make and install your kernel and then you can reboot using "disk" so you can see your running kernel.
Once booted, you can log in as normal with your standard username and password. From a terminal you can uses "sudo" to execute commands as "root" (superuser).
The Linux kernel is quite a large body of code, and compiling it utilises a lot of disk, both space and I/Os.
Your normal home directory is stored on a file-server which can be servicing up to 120 or so simultaneous uses, and has limited space per user (currently set to 1GB per user).
To make kernel compilation a less painful experience for all involved, we will be doing it on each lab machines local hard disk in the /scratch directory. The advantages of using this directory are:
The disadvantages of using /scratch are:
IMPORTANT: backup any files etc. that you create/modify to your home directory so that:
Also, in line with the ANU's Academic Misconduct policies, make sure you delete any files in /scratch that may be part of submittable assessment items. In cases of Academic Misconduct, it is not sufficient to claim that someone else may have obtained your submittable work by reading them from the /scratch, /tmp, or other sharable directories.
Back to the lab...
Create in /scratch a directory which holds the linux kernel source code. In the commands below I am using "u1234" as the uniID, please replace this with your own.
$ mkdir /scratch/u1234 $ cd /scratch/u1234 $ tar xjf /usr/src/linux-source-2.6.32.tar.bz2 $ cd /scratch/u1234/linux-source-2.6.32
Also, this kernel source tree is not the "standard" Linux 2.6.32 tree, but one that includes a number of Debian/Ubuntu patches and that has some of the files and directories associated with (re-)building Debian/Ubuntu kernel packages. These files/directories can be safely ignored.
Step 1 - kernel source code
Look at the kernel source code in /scratch/u1234/linux-source-2.6.32 (note that it is normally stored in /usr/src/linux). What is contained in the following directories/files?
If you have a computer at home then I would encourage you to get a copy for home. You don't need to install Linux (although this is a good thing to do), but, you will find it handy having the source code available.
Step 2 - navigating the source code
To find something in the source code you may either use "grep" or the "tags" program.
Read the grep man page and workout how to use the grep command to search files over a number of directories.
Try to find the point in the source code that writes out the contents of /proc/cpuinfo when you ask for it. (Note the location.)
Look at the man page for ctags (if you use vi) or etags (if you use emacs). Run a tags program on the kernel sources. Hint:
cd /scratch/u1234/linux-source-2.6.32 ctags -R
Use this in your editor to find the definition of the function sys_unlink(). Note that the "sys_unlink" method is defined using a macro, called "SYSCALL_DEFINE1" and has "unlink" as the first parameter. What does this function do? Report your findings.
During the Lab
Step 1 - Installing LinuxYou should reboot using the normal "net" mode. Note this leaves "/scratch" but rsyncs all the other directories: /boot, /usr, /etc, ...
Step 2 - Compiling/installing the kernelBuild the kernel with any changes and get it running. This involves:
$ cd /scratch/u1234/linux-source-2.6.32 $ cp /dept/dcs/comp3300/public/lab1.config .config $ make -j2 $ sudo make install $ sudo make modules_install $ sudo grub-install /dev/sda $ sudo update-grub Reboot using the "disk" option. You may wish to start thinking about Step 3 while waiting for the compile to finish. Now you are running on your newly made kernel!!!Modify the kernel sources to add your name to the contents of /proc/cpuinfo. Then build the kernel using the command "make", along with the "sudo make install" commands. The rest should not need redoing.
Did your modification work?
Step 3 - dont_deleteModify the kernel source code so that it is impossible to delete a file called "dont_delete". Compile your kernel (that should be fast this time as most of it hasn't changed) and see if your change worked. Make sure that you test it thoroughly - eg. can you delete the file if you use "rm ./dont_delete" or other extended forms of the file name?
You only need to add one line of code to the source code. However, working out at what point to place it is the trick!
Step 4 - scpUse scp or rsync/ssh to transfer the files you modified in the kernel sources to your student account. Or add them to a USB stick.
Step 5 - A "hello world" kernel moduleDownload the hello world kernel module and compile it then install it in your kernel using the insmod command. Also try lsmod and rmmod. (you may need the -f option.)
Have a look at the source code to the module and try to work out what the module does. How do you get it to print "hello world" ?
Virtual BoxThis lab can also be done in VirtualBox. See Eric's Wiki which has some basic instructions on how to do this. There is also some ideas about how to do it from scratch, see How to set up Kernel Development in Virtual Box.
Optional ExtraModify the hello world module such that it returns a different message each time it is output. These messages could be part of a fixed set of messages. (eg "Hi!", "Howdy", "G'day", "Greetings", "Grrr", etc)