2
2
3. homework
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.
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.
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).
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
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.
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