In this course, lab assignments will frequently ask you to make modifications to the Linux kernel. Thus, you will need to setup:
This guide will walk you though both steps. Since they each need lots of storage space, you'll need to work in /local, which is the local hard disk of the machine you're using. Storing things on /local has two major implications that you need to account for:
At the start of each lab assignment, you'll need to build a kernel from scratch. It will take approximately 10 minutes to compile, depending on which machine you use. At the end, you'll get nice .deb packages that you can install.
mkdir /local/kernels-username # Fill in your username cd /local/kernels-username
apt-get source linux-image-4.4.0-109-generic
cd linux-4.4.0 wget https://www.cs.swarthmore.edu/~kwebb/cs45/s18/labs/.config
make menuconfigThen navigate to the General Setup -> local version setting. I would suggest naming it based on the current lab number you're working on.
chmod a+x debian/rules chmod a+x debian/scripts/* chmod a+x debian/scripts/misc/* fakeroot debian/rules clean
export CONCURRENCY_LEVEL=4 time fakeroot make-kpkg --revision=1.0 kernel_image kernel_headersYou can adjust the revision number however you'd like. When it's finished, you should have two new .deb files one directory up:
$ ls -l ../*.deb -rw-r--r-- 1 kwebb users 7815612 Jan 15 12:12 ../linux-headers-4.4.98-cs45-lab_1.0_amd64.deb -rw-r--r-- 1 kwebb users 14928660 Jan 15 12:11 ../linux-image-4.4.98-cs45-lab_1.0_amd64.debWe'll install those .debs once the VM is up and running.
For security and reliability reasons, you'll be testing your kernels on a virtual machine. That way, if your kernel fails, you can simply reboot the VM and there's no risk of damaging your CS files.
To get started, you'll need to import a copy of the starter VM image:
After you've completed these steps, you should see the your VM in the list of VMs available to start. Go ahead and turn it on. The username and password are both cs45.
Before going any further, you should use the passwd command to set a new password to protect your VM. Open a terminal and run passwd.
Because it's so slow, building the entire kernel from scratch every time you make a change would be maddening. It's a nice fallback in case something goes wrong, but otherwise you probably just want to rebuild the files that you've changed (plus anything that depends on those files). NOTE: If you make changes to a very important header file that gets included all over the place (e.g., sched.h), you'll likely end up rebuilding most of the kernel.
From the linux-4.4.0 directory, you can rebuild the kernel image with:
make -j4 bzImage
Note that if you change .h files and your userspace programs need to see those changes (rare), you'll need to copy them over to your VM. While you can copy them by hand, it is often easier to just rebuild the kernel_headers package, remove the old one, and install the new version.
First, you'll need to copy the .deb files to your VM. The easiest way to do this is to use scp, which works like cp for transferring files over a network. It uses encryption, so the 's' stands for 'secure'. From the VM:
# Replace username with your username and hostname with the name of the machine you used to build your kernel. scp username@hostname.cs.swarthmore.edu:/local/kernels-username/*.deb . #Don't miss the trailing dot.
You can now install the .deb packages using dpkg:
sudo dpkg -i package_name.deb
If you've already an earlier version of .deb packages with the same name, you'll need to uninstall the old ones first:
sudo dpkg -r package_name
Reboot the VM to use the new kernel.
You'll need to copy two files from the kernel build directory to your VM. From the VM:
# Replace username with your username and hostname with the name of the machine you used to build your kernel. scp username@hostname.cs.swarthmore.edu:/local/kernels-username/linux-4.4.0/arch/x86_64/boot/bzImage . #Don't miss the trailing dot. scp username@hostname.cs.swarthmore.edu:/local/kernels-username/linux-4.4.0/System.map . #Don't miss the trailing dot.
Now that the files are on the VM, you need to put them in /boot. You should overwrite the existing kernel that was created when you did the .deb file installation:
# Replace whatever with the name you gave to your kernel. sudo mv -i bzImage /boot/vmlinuz-4.4.98-whatever sudo mv -i System.map /boot/System.map-4.4.98-whatever sudo update-grub
Reboot the VM to use the new kernel.
When your VM starts, it will present you with options for 10 seconds. Choose the "Advanced options for Ubuntu" to select which kernel you'd like to boot. I would suggest leaving the original kernel there as a fallback, just in case one of yours crashes on startup.