CS Project 4: Kernel Programming: Using VMWare

Last updated 03-23-12


GETTING STARTED

Lab and background information: The Systems Lab (SB337) has over 20, 64-bit dual core machines running Ubuntu 10.04 and Vmware Player for use for lab project 4. In a nutshell, you will be running a 32-bit version of Ubuntu (10.04), running on a VMware Player virtual machine.

Ubuntu Desktop was chosen specifically for this lab because of its ease of use, small size, and abundant documentation/examples.

Each machine being used for CS232 are also being used for IS333. This may cause problems when trying to logon to one of these systems. While one group is mixing and matching components and software in an ever expanding symphony of educational chaos the other group relies on a strict order of layered, unchanging, protocols and environments, quivering on the very edge of the abyss should the smallest wrong change be made.

What technical maven could be found that could balance these very different sides of the scales, harness the apparent opposites of law vs freedom!?... The CS department couldn't find anyone like that so they got me. Some possible fixes to the problems that inevitably arise are:

  1. Reattach the green nic cable (w/ yellow numbered label) and reboot.

  2. Find another machine and try that.

  3. Go find Gary Draving and let him know that those industrious IS333 students have messed with the cables again (or something to that effect)

You should logon to these machines using the same userid that you use in the Unix Lab (SB354). Your password will be the exact same as your userid, in which case you should change your password using the yppasswd command the first time you login.

After you login to any of the CS232 designated Ubuntu machines, you can start your VMWare session by going to:

   Applications > System Tools > Vmware Player

There is an image already setup for you named Ubuntu.

Most of you can just select Ubuntu but if Ubuntu is not listed under “Home” select “File”,”Open a Virtual Machine”. Ubuntu should be listed as an option. Select Ubuntu and then select Ubuntu.vmx. You should now be ready to select play to boot your Ubuntu operating system.

After you power on the Ubuntu 32 bit image you can login using account id mradmin, password bluestone. The root account is also set to password bluestone. You are free to make any changes you want to your Ubuntu image, but you will be responsible for remembering your account details. Password recovery on virtual images is not part of my skill set at this time.

The following packages needed for kernel development have already been installed on the Ubuntu image:

update
build-essential
linux-source-2.6.28
kernel-package
gcc
libncurses5
libncurses5-dev
libqt3-mt-dev

Additional packages can easily be added at your own disgression (discretion) with the aptitude, apt-get and dpkg commands.

Basic instructions for working with your kernel are as follows:

Regardless, use the same password as mradmin.

Different Linux distributions handle kernel recompilation differenty; here are some steps you will need to do the project using Ubuntu and the 2.6.* kernel...

To perform these steps correctly, you will need to be root.

1. Unpack the kernel source:

  cd /usr/src
  tar --bzip2 -xvf linux-source-2.6.28.tar.bz2
  ln -s /usr/src/linux-source-2.6.28 /usr/src/linux
  cd /usr/src/linux

2. Compile your new kernel

When you are done making and saving changes to your kernel:

  1. In /usr/src/linux run "make menuconfig" to create a ".config" This is a general kernel configuration file the compiler needs. All the default settings in menuconfig should work for now.

  2. Remove the directry /usr/src/linux/debian/stamp, (if it exists) which constains build-stamps from previous builds; and

  3. Compile your customized kernel as follows:

       make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

    This will compile each of the kernel source files, creating corresponding .o files, and will create new kernel image and header files with names like kernel_image-2.6.8-custom....deb and kernel_headers-2.6.8-custom...deb respectively, which we will use in our next step.

The first time you do a full kernel compile, you'll have to wait 45 minutes to 3 hours for the compilation to finish, so plan accordingly: study for your OS test, go eat, etc. Avoid using the computer, as anything you do during the compilation competes for the CPU and slows the compilation. If you leave, put a sign on your computer to let other students know that the it is in use.

When the compilation succeeds, make-kpkg will use whatever name you specified as an argument to the --appeend-to-version switch to create an entry in /usr/src/linux/control naming your new kernel image.

3. Add your new kernel to the boot loader (Grub)

After the compilation finishes, enter the following to install your new kernel:

   cd /usr/src
   ls
   sudo dpkg -i linux-image-2.6.32.52+drm33.21-custom_2.6.32.52+drm33.21-custom-10.00.Custom_i386.deb

(your name maybe different)

   sudo dpkg -i linux-headers-2.6.32.52+drm33.21-custom_2.6.32.52+drm33.21-custom-10.00.Custom_i386.deb

(again your name will be different).



Next you need to prepare the new image for booting with “update-initramfs”.

“update-initramfs -c -k 2.6.32.52+drm33.21-custom”

your version name my look different and can be found in /lib/modules

root@ubuntu:~# ls -al /lib/modules/

total 28

drwxr-xr-x 5 root root 4096 2012-03-23 09:54 .

drwxr-xr-x 20 root root 12288 2012-01-25 19:19 ..

drwxr-xr-x 4 root root 4096 2012-01-25 14:51 2.6.32-21-generic

drwxr-xr-x 4 root root 4096 2012-01-25 18:53 2.6.32-38-generic

drwxr-xr-x 3 root root 4096 2012-03-23 09:55 2.6.32.52+drm33.21-custom

The final step to make your kernel active is to simple update grub (the boot loader). Edit /etc/defaults/grub and make sure “GRUB HIDDEN_TIMEOUT=0” is commented out as so:

GRUB_DEFAULT=0

# GRUB_HIDDEN_TIMEOUT=0

GRUB_HIDDEN_TIMEOUT_QUIET=true

GRUB_TIMEOUT=10

This is so we can see and choose which kernel to boot during startup. Next run “update-grub”

Your new kernel should now be one of grub's menu choices when you reboot your virtual machine.

4. Reompiling your new kernel

After you have compiled the kernel once, subsequent rebuilds should not take as long, since just the code you have modified has to be recompiled and then relinked.

Once you have modifed your kernel, you should:

These steps can probably be scripted, though I have not tried that. Feel free to give it a try and report to the group.

When you re-run make-kpkg, be sure to use the same string for --append-to-version or your new image name will be different from the name in /usr/src/linux/control and you will get errors.

If you need to remove all of the .o files, the command:

   make-kpkg clean

will do this, and your first compile will (again) take a long time.

5. Shutting down, rebooting, etc.

You can reboot or shut down your virtual machine using the usual Ubuntu mechanisms. If you need to "manully" powerdown your virtual machine (i.e., your OS has escaped your control), you can do so using VMWare's Power Off button.

Some final considerations:

  1. The above instructions were basically taken from the following links. I would encourage you to read these articles, since they were written by people that know a whole lot more about working with the linux kernel than I do.

  2. You and/or your group are free to make your own linux image. If you do that, bear in mind that it is best to start out with an image at least 20-30 gig. Do not use much more than this since it may use up too many resources and I will have to delete it. Theoretically it is possible to start out with an image much smaller than this and VMware can be set to grow as needed. In practice this feature of VMWare does not seem to work when compiling a new linux kernel. The amount of file content in your image can more than triple when doing a full kernel compile and VMWare does not not necessarily expand your disk image quickly enough, causing errors in your new kernel files.

  3. If you mess up your image and just want to start over with a new image, you can copy the image at /home/guest1/vmware. There are also Ubuntu ISOs here that can make it very easy to make your own Ubuntu VMWare image.

  4. As mentioned earlier Ubuntu also lets you make changes to the kernel using a menu system called menuconfig:

      make menuconfig

    This mechanism seems to be more for managing the kernel's modules than hacking its source code so its use may have limited value to you except for creating that initial .config file.

  5. This document is a work in progress. I will be eager to hear from you and add any helpful tips you might discover. Especially any tips on making the kernel compilation go faster. Future generations will praise you for it!.

- Gary.