Operating System Kernel Compilation Sarah Diesburg CS 3430

advertisement

Operating System Kernel

Compilation

Sarah Diesburg

CS 3430

Operating Systems

1

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

2

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

3

Logging In

 Username: os

 Password: os

 Username: root

 Password: iamr00t

4

No GUI/Desktop?

 I disabled it by default (to run faster)

 If you really want it, issue (as root)

#> systemctl set-default multi-user.target

 If you want to turn it off again, issue (as root)

#> systemctl set-default graphical.target

5

Communicating with your fresh virtual machine

Use ssh

1.

Log into the terminal, and issue /sbin/ifconfig to get the second IP address

Type the IP address directly into PuTTY

2.

 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

6

SSH/WinSCP Demo…

7

If you created your own virtual machine….

Good for you!

 You will want to install these packages:

 gcc

 make

 ssh

 vim / emacs / (your choice of editor)

 sudo

 libncurses5-dev

8

Basic System Commands

 $> passwd

Change your password

 $> su

Become root directly. Use root’s password when prompted.

 $> sudo

Do something with root’s privileges without having to become root

9

Basic System Commands

 $> chown –R os:os <dir>

Changes ownership of dir to user/group os

 $> adduser <username>

Adds user specified by username

 $> userdel <username>

Deletes user specified by username

10

Kernel Compilation

11

Example of Kernel Compilation….

12

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.4.2 (bleeding edge stable version)

13

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.4.2.tar.xz

14

Compiling the Kernel

 Compiles based on configuration of .config file located in the kernel source directory

 How can I correctly configure my kernel?

1.

2.

Use the ‘make defconfig’ command

Use the ‘make menuconfig’ command

15

‘make defconfig’

 This new command makes the default configuration file for Linux.

It creates a smaller configuration file than previous methods, so the kernel is faster to compile

16

‘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

17

‘make menuconfig’

18

‘lspci’

19

General Linux Source Organization

 Memory Management

 Networking Layer

 Security

 Sound Processing

 Architecture-specific

Code

 Disk Drivers

 Devices

 File Systems

20

Config Example (Inside Source Dir)

$> cd /usr/src/linux-4.4.2

$> make defconfig

21

Compiling the Kernel

Issue ‘make’ inside the source directory

$> make

Grab some coffee….

22

Installing the Kernel

1.

Install the modules (drivers)

$> sudo make modules_install

2.

Install the actual kernel

$> sudo make install

What does ‘sudo’ do?

23

Final Step

 Create the ramfs image

 Why do we need an extra ramfs image?

24

Boot Driver Problem

 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

25

Boot Driver Solutions

 Hard : Figure out all drivers needed to read the root file system and compile into kernel

May take a few tries…

 Easy : Create a root file system image file that will load the right modules for you

 initramfs

26

initramfs

 Create the initramfs image

$> cd /boot

$> sudo mkinitramfs –o /boot/initrd.img-4.4.2 4.4.2

27

Configure the Boot Loader (Grub)

$> sudo update-grub

 Now you can issue a reboot and cross your fingers!

$> sudo reboot

28

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

29

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

30

Next Recitation

 More on Project 2

Loading a kernel module and playing with proc files

31

Download