Programming lesson
Building Your First Kernel Module: A COP4600 Guide to Adding Boot Messages in Reptilian
Learn how to modify the Reptilian kernel to print a custom boot message with your name and UFID, create a patch, and test your changes—just like the COP4600 assignment.
Introduction to Kernel Module Development
Kernel programming is a rite of passage for systems students. In COP4600, the first project asks you to modify the Reptilian kernel to print a personalized boot message. This tutorial walks through the core concepts and steps—without giving away the full solution—so you can complete the assignment with confidence. Think of it as learning to customize your operating system's startup, much like how gamers tweak their PC's BIOS for performance or how developers configure a cloud server's boot sequence.
Understanding the Assignment
The goal is simple: add a line like ##### FirstName LastName (UFID: 0000-0000) My Personal Message ##### to the kernel boot log, just before the message "Detecting Reptilian system partition". This appears during default boot (not debug mode). You'll also create a patch, take screenshots, and record a short video.
This mirrors real-world kernel development where engineers add diagnostic prints to track system initialization. For example, when debugging a new driver for an AI accelerator, you might insert log messages at key points.
Key Concepts: Kernel Log Levels
The Linux kernel uses eight log levels, from KERN_EMERG (0) to KERN_DEBUG (7). Messages at KERN_ERR (3) or higher appear on console by default. For your message to show without verbose mode, use pr_info or printk(KERN_INFO ...). Note: KERN_INFO (6) is below the default console log level, so it won't appear unless you adjust the log level. The assignment likely expects you to use pr_emerg or pr_alert to ensure visibility. Check the Reptilian kernel configuration.
Where to Add the Code
The assignment hints at adding code near rcu_end_inkernel_boot(). This function signals the end of kernel boot and start of system initialization. In the source tree, look for the file that calls this function, often init/main.c. Insert your printk just before that call. For example:
pr_emerg("##### John Doe (UFID: 1234-5678) My Personal Message #####\n");Add a newline before and after. Test by rebuilding the kernel and booting in default mode.
Creating a Unified Patch
Patches are essential for sharing kernel changes. After modifying the source, stage your changes:
cd /usr/rep/src/reptilian-kernel
git add -u
git add '*.c' '*.h' '*Makefile*' '*.tbl'
git diff remotes/origin/os-latest > p0.diffThis creates a patch file that can be applied with git apply p0.diff. Always test your patch on a clean VM!
Testing Your Changes
Rebuild the kernel: make && sudo make install && sudo make modules_install. Reboot and watch for your message. If it doesn't appear, check the log level. You can also use dmesg after boot to see all messages. For extra credit, modify GRUB menu entries by editing /etc/default/grub and updating GRUB_DISTRIBUTOR or manually editing /boot/grub/grub.cfg (but not with grub-mkconfig).
Common Pitfalls
- Log level too low: Use
KERN_EMERGorKERN_ALERTfor guaranteed visibility. - Missing newlines: Ensure leading and trailing newlines in your message.
- Patch not applying: Verify you're in the correct directory and the patch is clean.
Trend Connection: Boot Customization in Modern Tech
Custom boot messages aren't just for assignments. In the world of cloud-native computing, customizing startup logs helps DevOps teams identify builds. Even in gaming, enthusiasts tweak boot screens for aesthetic PCs. This skill ties directly to low-level system programming used in IoT devices and autonomous vehicle software.
Final Tips
Document your changes in the report (max 500 words). Include a link to an unlisted screencast. Practice applying the patch to a fresh environment. Good luck!