walking around linux kernel

22

Click here to load reader

Upload: dharshana-warusavitharana

Post on 06-May-2015

1.234 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Walking around linux kernel

Your NameYour Title

Your Organization (Line #1)Your Organization (Line #2)

Walking around Linux Kernel

Dharshana Kasun Warusavitharana.Software Engineer,Test AutomationWSO2 Inc.

Page 2: Walking around linux kernel

How Story Begins

Birth of Linux

1984 Richard M Stallman found GNU (GNU is Not Unix).

Andy Tannenbaum Wrote Minux.

1991 Linus Torvalds wrote Linux

Page 3: Walking around linux kernel

Why Operating System

Process managementInterruptsMemory managementFile systemDevice driversNetworking (TCP/IP, UDP)Security (Process/Memory protection)I/O

Page 4: Walking around linux kernel

What is a Kernel

The kernel is a bridge between applications and the actual data processing done at the hardware level. The kernel's responsibilities include

Managing the system's resourcesThe communication between hardware and software

componentsThe kernel's primary function is to manage the

computer's resources and allow other programs to run and use these resources.Typically, the resources consist of:

The Central Processing Unit. The computer's memory.Any Input/Output (I/O) Key aspects necessary in resource management.

Page 5: Walking around linux kernel

Kernel basic facilities

Process managementSupport to hardware abstractions (Hal Daemon). Setting up an address space for the application, loads the file containing the application's code into memory Multi-tasking kernels are able to give the user the illusion that the number of processes being run simultaneously on the computer.The kernel generally also provides these processes a way to communicate; this is known as inter-process communication (IPC) and the main approaches are shared memory, message passing and remote procedure calls (see concurrent computing).

Page 6: Walking around linux kernel

Kernel basic facilities (Contd.....)

Memory managementAllows processes to safely access this memory .Virtual addressing, usually achieved by paging and/or segmentation. Virtual addressing allows the operating system to use other data stores

Virtual addressing also allows creation of virtual partitions of memory in two disjointed areas.

Page 7: Walking around linux kernel

Kernel basic facilities (Contd.....)

Device management 1. On the hardware side:Interfacing directly.Using a high level interface (Video BIOS).Using a lower-level device driver (file drivers using disk drivers).Simulating work with hardware, while doing something entirely different.

2. On the software side:Allowing the operating system direct access to hardware resources.Implementing only primitives.Implementing an interface for non-driver software (Example: TWAIN).Implementing a language, sometimes high-level (Example Postscript).

Page 8: Walking around linux kernel

Kernel basic facilities (Contd.....)

System callsUsing a software-simulated interrupt.Using a call gate. A call gate is a special address stored by the kernel in a list in kernel memory at a location known to the processor.Using a special system call instruction. Using a memory-based queue.

Page 9: Walking around linux kernel

Kernel-wide design approaches

Page 10: Walking around linux kernel

Monolithic kernels

In a monolithic kernel, all OS services run along with the main kernel thread.Monolithic kernels, which have traditionally been used by Unix-like operating systems.Since there is less software involved it is faster.As it is one single piece of software it should be smaller both in source and compiled forms.Less code generally means fewer bugs which can translate to fewer security problems.Most work in the monolithic kernel is done via system calls.These types of kernels consist of the core functions of the operating system and the device drivers with the ability to load modules at runtime.

Page 11: Walking around linux kernel

Cons

Coding in kernel space is hard, since you cannot use common libraries (like a full-featured libc), debugging is harder.Bugs in one part of the kernel have strong side effects.Kernels often become very huge, and difficult to maintain.Even if the modules servicing these operations are separate from the whole, the code integration is tight and difficult to do correctly.Since the modules run in the same address space, a bug can bring down the entire system.The disadvantage cited for monolithic kernels is that they are not portable; that is, they must be rewritten for each new architecture that the operating system is to be used on.

Page 12: Walking around linux kernel

●Microkernel

A microkernel that is designed for a specific platform or device is only ever going to have what it needs to operate. The microkernel approach consists of defining a simple abstraction over the hardware,Maintenance is generally easier.Patches can be tested in a separate instance, and then swapped in to take over a production instance.Rapid development time and new software can be tested without having to reboot the kernel.More persistence in general, if one instance goes hay-wire, it is often possible to substitute it with an operational mirror.Most micro kernels use a message passing system of some sort to handle requests from one server to another. A microkernel allows the implementation of the remaining part of the operating system as a normal application program written in a high-level language.

Page 13: Walking around linux kernel

Cons

Disadvantages in the microkernel exist however. Some are:Larger running memory footprint.More software for interfacing is required, there is a potential for performance loss.Messaging bugs can be harder to fix due to the longer trip they have to take versus the one off copy in a monolithic kernel.Process management in general can be very complicated.Extremely context based. As an example, they work well for small single purpose (and critical) systems because if not many processes need to run, then the complications of process management are effectively mitigated.

Page 14: Walking around linux kernel

●Hybrid kernels

Hybrid kernels are part of the operating systems such as Microsoft Windows NT, 2000 and XP. Dragonfly BSD etc. They are similar to micro kernels, except they include some additional code in kernel-spaceMany traditionally monolithic kernels are now at least adding (if not actively exploiting) the module capability. On demand capability versus spending time recompiling a whole kernel for things like new drivers or subsystems.Faster integration of third party technology (related to development but pertinent unto itself nonetheless). Disadvantages of the modular approach are:With more interfaces to pass through, the possibility of increased bugs exists (which implies more security holes).Maintaining modules can be confusing for some administrators when dealing with problems like symbol differences.

Page 15: Walking around linux kernel

Linux Kernel

Page 16: Walking around linux kernel
Page 17: Walking around linux kernel

Lets Hack :)

Because a driver is not working as well as itshould, or is not working at all.Because we have a school or work project.Because the kernel is crashing, and we don’tknow why.Because we want to learn how the kernel works.Because it’s fun! Real men hack kernels ;-

Page 18: Walking around linux kernel

You need to install the kernel development packages•e.g.: gcc, make, binutils, ncurses, qt• Extract the kernel source in /usr/src• Optionally create a symlink• Quick configuration using an old configuration•linux:# tar jxvf /tmp/linux-2.6.16.8.tar.gzlinux:# ln -s /usr/src/linux-2.6.16.8 /usr/src/linuxlinux:# cp /boot/config-2.6.14 .configlinux:# make oldconfigCompiling the kernellinux:# make && make install && make modules_install

Page 19: Walking around linux kernel

But WHAT if you make a MESS and wantto CLEAN UP?

Just use Mr. Proper# make mrproper This will clear all pre-compiled binaries as well as remove the .config file# make clean Just clean all pre-compiled binaries

Page 20: Walking around linux kernel

Know your Hardware

To see whats plugged into your motherboard, or USB ports.linux:# lspci -vlinux:# lsusbTo check your processor and memorylinux:# cat /proc/cpuinfolinux:# cat /proc/meminfo• To see your hard drive partitions.• To see your kernel loglinux:# fdisk -llinux:# dmesg

Page 21: Walking around linux kernel

Add Modules

To list modules that are currently loaded you can issue• To list available modules (compiled) for the current kernel• To get a small description about a module ...• To load a kernel module driver manually•#lsmod#modprobe -l#modinfo radeon#modprobe radeonTo load a kernel drive automatically as the machine boots consider adding it to /etc/modules.conf (2.4) or /etc/modprobe.conf (2.6)

Page 22: Walking around linux kernel

Thank You&

Happy compiling ...