0% found this document useful (0 votes)
12 views4 pages

2

Uploaded by

wlghho01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

2

Uploaded by

wlghho01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lecture 2: Installing/Reading Linux Kernel

1. What's in the linux kernel

init: start up code


main.c : beginning of linux

kernel: cpu-indendent code for basic system management


fork.c, exit.c, sched.c : process creation, exit, scheduling

arch : cpu-dependent code for basic system management


arch/x86 : cpu-dependent code for intel x86 cpu
arch/x86/boot : boot-related code
arch/x86/kernel: low-level intel cpu code for initialization, interrupt handling, etc
entry_32.S : code for interrupt entry point
head_32.S : code for system initialization
i8259_32.c : code for interrupt controller
irq_32.c : code for IRQ
process_32.c : code for process control
time_32.c : code for timer
traps_32.c : code for exception handling
signal_32.c : code for signal handling

fs: file system code


open.c, read_write.c, file.c, ... : fs system call handling
inode.c : inode handling
fs/ext2 : ext2 file system code
fs/ntfs : windows NT file system code

mm : memory management code


net: network handling code
drivers: device handling code
include : include files
inclde/asm-x86 : include files for intel cpu specific code
ipc: code for inter-process communication

2. Linux starting location: init/main.c: start_kernel()

3. homework

1) Install Gentoo Linux on virtual machine.

1.0) Download Virtualbox from Internet and install. Install vmware if you have trouble with
VirtualBox. If you are mac m1 user, skip 1.1) and 1.2) and install UTM as explained in Section 4:
“Installing gentoo on macOS”.

1.1) Download Gentoo virtualbox files (gentoo.zip) from the I-class and un-compress it.
1.2) Run VirtualBox, and click File>Import and go to the gentoo directory. Select Gentoo2.ovf.
Uncheck USB controller. Select Import. This will install Gentoo Linux on your virtual box. If you
are mac m1 user, follow the steps in Section 4.

1.3) Run Gentoo. If you have an error, run VirutalBox as administrator and try again. For USB
error, simply disable usb controller in "Setting" tab. For Hyper-V error (Raw-mode is
unavailable), turn off Hyper-V feature in control panel>program and feature>window feature.
Select My Linux. Login as root and hit Enter for the password prompt. If VirtualBox still cannot
open the session, you need to look at the log file (right click on Gentoo VM and select “log file”)
and see what is the error and fix it.

1.4) Make a simple program, ex1.c, with vi which displays "hello world". Compile and run it.

2) Go to linux-2.6.25.10 directory and find all the files referred in Section 1 such as main.c,
fork.c, entry_32.S, etc. You should find ALL .c or .S files referred. How many files are in kernel
directory? How many c files in the kernel directory? How many files in arch/x86/kernel directory?
How many c files in arch/x86/kernel directory? Use “ls | wc” command or “ls *.c | wc” (for c
files) to count them.

3) Find the location of start_kernel().

To find a string "start_kernel", go to the linux top directory (linux-2.6.25.10) and do


$ grep -nr "start_kernel" * | more
Use "space" to move down the screen, "q" to exit. Since there are many files that contain
“start_kernel”, you need to guess intelligently which file contains the function definition of
“start_kernel”.

Once you found the file that has "start_kernel" function, use "vi" to read the file.
In vi, type "/start_kernel" to search for the first instance of "start_kernel".
For the next string, simply type "/". Repeat "/" until you find the start_kernel() function.

Use "j" to mode down the cursor, "k" to move up, "^f" to move one screen down, "^b" to move
one screen up.

3-1) Another way to find “start_kernel” function in Linux is using “elixir.bootlin.com” web site.
Go there, select version 2.6.25.10 (the Linux version used in this class) and type “start_kernel”
in the search box. Since you are looking at “start_kernel” function definition in x86 cpu, ignore
“Defined in 4 files as a prototype” or “Referenced in 47 files”. Also ignore files in arch/alpha
directory because our CPU is not alpha. Now the relevant file should be “init/main.c”. Click
“init/main.c” and you will see the function.

3-2) Find the definition of “printk” by clicking “printk” in “printk(KERN_NOTICE)” in


“start_kernel” function shown in 3-1). Also find the definition of “KERN_NOTICE” by clicking it.
What is the value of “KERN_NOTICE”?

4) start_kernel() is the first C function run by Linux. Predict what will be the first message
appearing on the screen by analyzing start_kernel(). Note that "printk()" (not "printf") is the
function to print something in the kernel. Therefore “printk(linux_banner)” will print the first
message during the boot time. Note “printk(KERN_NOTICE)” is just setting the log level, not
printing some actual message. You need to check the value of “linux_banner” to predict what will
the first message. Confirm your prediction with "dmesg > x" and "vi x". The kernel remembers
the booting message in the system buffer and dmesg command displays the content of this buffer
to the screen. "dmesg > x" will send the booting message to file x. With "vi x" you can look at
the file x.

5) Find the definition of the following functions called in start_kernel() and briefly explain your
guessing about what each function is doing (but do not copy the whole code). Remember our
Gentoo is using 32bit x86 cpu. So if the function is cpu-dependent, you should look for them in
arch/x86 directory with 32 bit notation (e.g. arch/x86/kernel/traps_32.c).

trap_init(), init_IRQ(), sched_init(), time_init(), console_init(), mem_init(),


rest_init()

6) Why can't we use "printf" instead of "printk" in Linux kernel?

4. Installing gentoo on macOS (with m1 cpu)

1) Install homebrew
Do following 4 steps in mac terminal.

/bin/bash –c “$(curl -
fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

echo '# Set PATH, MANPATH, etc., for Homebrew.' >> /Users/yourID/.zprofile

echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/yourID/.zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"

brew --version

In above "yourID" is what comes after /Users when you type pwd command.

2) install qemu
You need qemu to convert gentoo.vmdk to gentoo.qcow2 which is disk image in UTM, the virtual
machine you are using in mac m1.

brew install qemu

3) convert gentoo.vmdk to gentoo.qcow2

qemu-img convert -O qcow2 Gentoo.vmdk Gentoo.qcow2

4) Install gentoo in UTM


4.1) Install UTM
4.2) Run UTM and do following steps

0. Create New Virtual Machine


1. Emulate
2. Custom
3. Skip ISO boot
4. The rest of configs as your needs or default (continue, continue, etc... save):
5. choose i386(x86), 8GB hard disk
6. Continue & Save
At this point something that looks like a virtual machine was created in the left panel.

Right click on the just-created VM, select edit, click system, and activate "Force Multicore"
option for performance.

1. Drives: In the popup Settings window at the bottom left is Drives - Delete that Drive
(Mine is called IDE Drive)
2. Drives: Click in New...
3. Import
4. Select the qcow2
5. Go to QEMU Tab
6. Unselect "UEFI Boot"
7. Save
8. Run

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy