280 likes | 384 Views
Dive into the challenging yet fun world of kernel compilation for operating systems. Learn how to compile the newest kernel version and communicate with your virtual machine effectively. Follow step-by-step instructions and customize your kernel using various tools. Ensure successful booting and system operation.
E N D
Operating System Kernel Compilation Sarah Diesburg CS 3430 Operating Systems
Kernel Coding • The next project involves compiling a new kernel! • Fun but challenging…. • Each person/team will get their own virtual machine(s) • See website instructions for how to install/use the virtual machine
Booting with the Bootloader (grub2) • The newest version of the kernel will boot by default • Look in the submenu (or further down the list) for any older version
Logging In • Username: user • Password: user • Username: root • Password: iamr00t
Communicating with your fresh virtual machine • Use the GUI • Select the terminal program from the bottom of the left shortcuts bar
Communicating with your fresh virtual machine (other ways) • Use ssh • Log into the terminal, and issue /sbin/ifconfig to get the second IP address • Type the IP address directly into PuTTY • Transfer files • Must use Winscp or Filezilla with the IP address found above • Basically, communicate with it the same way you communicated with the student.cs.uni.edu machine
SSH/WinSCP Demo… • Issue this command inside VM to get its IP address ip address
If you created your own virtual machine…. • Good for you! • You will want to install these packages: • gcc / flex / bison • make • ssh • vim / emacs / (your choice of editor) • libssl-dev • libncurses5-dev • others (heh heh)
Choosing a Kernel • The next project will involve kernel development • We all need to be in the same boat… • The class version will be 4.20.10 (bleeding edge stable version)
Kernel Repository • http://kernel.org – place to download latest and greatest Linux kernels! • Traditional place for kernel is in /usr/src/ • It is already in there for you • …That is, unless you created your own virtual machine. Then download it from kernel.org, and extract it with the command • $> tar xv linux-4.20.10.tar.xz
Compiling the Kernel • Compiles based on configuration of .config file located in the kernel source directory • How can I correctly configure my kernel? • Use the ‘make oldconfig’ command • Use the ‘make menuconfig’ command
‘make oldconfig’ • This command makes the default configuration file for Linux. • It creates a new configuration file based on the old configuration, so the kernel has the right mix of drivers
‘make menuconfig’ • Only do this if you are trying to make the kernel smaller • Manually select and deselect drivers and options for your kernel • * -- compiled directly into kernel • M – compiled into a module (driver) that can be dynamically added • Can be tough to figure out what you need and don’t need • Command ‘lspci’ shows hardware on computer
General Linux Source Organization • Memory Management • Networking Layer • Security • Sound Processing • Architecture-specific Code • Disk Drivers • Devices • File Systems
Config Example (Inside Source Dir) $> cd /usr/src/linux-4.20.10 $> make oldconfig $> make menuconfig
Compiling the Kernel • Issue ‘make’ inside the source directory $> make • Grab some coffee….
Installing the Kernel • Install the modules (drivers) • $> make modules_install • Install the actual kernel • $> make install
Historical final steps • Now the ‘make install’ command does all the following for you • Create a ramfs image • Update grub
Boot Driver Problem • Why ramfs? • Suppose you compiled the disk drivers and root file system drivers as modules • Boot process loads the kernel image • Kernel image does not contain disk drivers
Configure the Boot Loader (Grub) • Update bootloader (no longer necessary with ‘make install’) $> sudo update-grub • Now you can issue a reboot and cross your fingers! $> sudo reboot
Telling Which Kernel You are In • Select the new kernel from the grub menu! • Watch your virtual machine • If something goes wrong, reboot and go back into your original kernel to try again • The following command will tell you which kernel you are in: $> uname -r
Uh oh…. • If it doesn’t boot, go back into the original kernel • Always important to have one working kernel! • Make sure you didn’t skip a step… • You may have taken too much out of the kernel… • Start with bloated kernel, take things out one by one
Project 2 Spec • Let’s take a look at it