Setting up

The following steps will help you compile your own versions of the kernel, read the class notes, and search in the kernel source.

1. A personal copy of the kernel, running as UML

These notes assume that you are using the MultiLab, where you have access to my copy of the Linux source. If not, you need to modify the instructions appropriately.

You will create a User-Mode Linux (UML) kernel, which is a full-featured Linux kernel that runs as an ordinary process within a Linux installation.

  1. Make your own private copy of the kernel source to compile, modify and search. You must compile it using a recent gcc (such as 5.4.0, which is installed in the MultiLab). To tell what version of gcc you have, run
    	gcc --version
    You only want to make links to, not real copies of, the Linux source files we have downloaded from the web:
    	mkdir MYLINUX
    	cd MYLINUX
    	lndir /u/joa-d1/SCRATCH/linux/linux-4.4.108
    To compile the kernel:
    	make defconfig ARCH=um
    	make menuconfig ARCH=um (You can just save the original configuration.)
    	make ARCH=um (You can accept the default values for UML)
  2. To make any changes to the source code (to complete projects), you need your own copy of the relevant file instead of a link to our read-only copy. You can use ~raphael/bin/ FILE ... to replace links with real copies.
  3. To run your UML:
    	cd MYLINUX
    	./linux rootfstype=hostfs rw mem=128M init=/bin/bash (or /bin/tcsh or other shell)
    You are now running the shell in your UML, and the current directory is / on the host operating system. All files you write are written with your permissions and ownership, and you can only read files that your permissions permit, even though UML thinks the shell is running as root.
  4. Enable the /proc filesystem in the UML:
    	mount -t proc proc /proc
  5. Become yourself in the UML (optional):
  6. To stop your UML, exit your shell. You might get an abort from UML, generating a core dump. You can prevent getting massive core dumps by:
    	limit coredumpsize 0 (csh, tcsh)
    	ulimit -c 0          (bash, dash)
You can read extensive documentation on UML at

2. Tags file

I recommend you use the Vim text editor for reading class notes, although you may certainly choose some other tool. Vim can use a tags file to quickly jump to the file and line that defines a given identifier.

The following code runs find to list all the files in the Linux source, ctags to create a set of tags from those files, and grep to remove tags that you really aren't interested in, primarily platform-dependent tags for other platforms, as well as device-driver files. The tags file will be about 60MB. Better yet, just grab and gunzip the tags file from (9 MB).

cat > badtags << BADEND
find MYLINUX -not \( -type d \) \
	\( -name '*.c' -o -name '*.S' -o -name '*.h' \) -print | \
/bin/grep -v -F -f badtags | \
/usr/bin/ctags \
	--regex-Asm='/.* LIST_HEAD\((.*)\)/\1/l/' \
	--regex-Asm='/ENTRY\((.*)\)/\1/l/' \
	-w -L - -f tags

3. Vim

To get fancy syntax coloration in Vim for my class notes, put the file in directory ~/.vim/syntax/linux.vim.

Place the following command in your startup file (~/.vimrc is a good place):

	:syntax on
To jump via a tag, move the cursor to the tag, then type <control>]. To jump to another location with the same tag, type :tn<enter>. To pop the stack of tags, type <control>T.

4. Emacs

Here are the emacs commands to use tags (thanks to Amit Sehgal for this list). You need to build the tags file with etags, not ctags. In the list below, C stands for <control>; M stands for <meta>.
M-x visit-tags-table prompts for the tag file to be loaded. The default filename used by etags is TAGS.
M-. prompts for the tag to be searched and finds the first occurrence.
C-u M-. goes to the next occurrence of the tag.
M-* goes to the previous occurrence of the tag.
C-x 4 . prompts for the tag to be searched and displays the first occurrence of the tag in another window.
M-x tags-apropos searches for all tags that match a regular expression in the tag table.
M-x tags-search searches for text "other than tags" across all files in the current tag table.
M-, repeats the last tags-search command.
M-x tags-query-replace prompts for a search string (not a regular expression) and a replacement string and then calls the query-replace function on all files in the current tag table.
M-x list-tags prompts for a filename and then displays all the tags defined within the file in another window.