the linux kernel

42
The Linux Kernel • About 6 million lines of code • Controls memory and process management.

Upload: stephanie-rokos

Post on 30-Dec-2015

126 views

Category:

Documents


3 download

DESCRIPTION

The Linux Kernel. About 6 million lines of code Controls memory and process management. The Linux Kernel. Linux & the Kernel. Kernel Version Numbering: 2.6.38.8. A.B.C.D A is the version B is the major revision C is the minor revision D are security and bug fixes - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: The Linux Kernel

The Linux Kernel

• About 6 million lines of code

• Controls memory and process management.

Page 2: The Linux Kernel

The Linux Kernel

Page 3: The Linux Kernel

Linux & the Kernel

Page 4: The Linux Kernel

Kernel Version Numbering: 2.6.38.8

A.B.C.D• A is the version• B is the major revision• C is the minor revision• D are security and bug fixes• 2.6.39 was the last minor revision before 3.0 is

released.

Page 5: The Linux Kernel

Linux Boot Sequence

• After the BIOS/UEFI instructions are given to start the OS,– A compressed version of the kernel is loaded

into the first megabyte of ram.– The complete kernel is expanded and loaded– The kernel starts

Page 6: The Linux Kernel

Kernel Startup

• Checks memory

• Probes for hardware

Page 7: The Linux Kernel

Kernel Hardware Probe

• Some drivers are compiled into the kernel other drivers are loaded when the kernel starts.

• Everything recognized by the os has a file node associated with it. The kernel will establish nodes for each required device.

Page 8: The Linux Kernel

Starting the kernel

• Find and set up swap (virtual memory)• A hardware probe is done to determine what

drivers should be initialized.• Read /etc/fstab to mount the root file system.• Mount other devices • Start a program called init.• Kernel passes control to init.

Page 9: The Linux Kernel

Kernel startup

• Create tables for memory management.

Page 10: The Linux Kernel

Kernel Startup

• Dummy processes are started. These processes do not have PIDs, and cannot be killed:– Swap– Paging virtual memory– IO activity– Other (example: managing threads)

Page 11: The Linux Kernel

Dummy processes

• Swapper

• vhand, kflushd, kpiod, mdrecoveryd

Page 12: The Linux Kernel

Kernel Startup

• Find and mount the other partitions starting with the swap partition space.– The /etc/fstab

Page 13: The Linux Kernel

/etc/fstab

• /dev/root

• /proc –A virtual file-system (in memory) used for managing processes. This allows loadable runtime modules to be inserted and removed as needed.

• /dev/pts – A VFS used for managing devices

Page 14: The Linux Kernel

init

• The first non-dummy process, PID = 1.

• First process to run and is always running.

• The kernel passes process management to init.

• Init reads its configuration file: /etc/inittab

• Directly or indirectly spawns all other processes until shutdown.

Page 15: The Linux Kernel

init: Processes

•  The basis of all Linux systems.

• Run perpetually in the background waiting for input. – Services– Daemons– Shells– utilities

Page 16: The Linux Kernel

init:Services & Daemons

• Examples:

• login prompt

• X-Window server

• keyboard input functionality

• firewall

• and all classic server programs; e-mail, DNS, FTP, telnet, ssh, etc.

Page 17: The Linux Kernel

init

the runlevel is determined by inittab:

0. Halt the system

1. Enter single-user mode (no networking)

2. Multiuser mode, without NFS.

3. Full multiuser mode

4. Unused

5. Same as runlevel 3 but with X-windows.

6. Reboot.

Page 18: The Linux Kernel

/etc/inittab

• Additional programs and services are started when init reads the contents of inittab.

Page 19: The Linux Kernel

inittab

• Each line has the same syntax: Id:runlevels:action:process• Id A unique sequence of 1-4 characters to

identify the line in the file (a macro).• Runlevels are any combination of numbers

from 0-6. If blank it implies all run levels.• Action- what should happen.• Process – the actual process to run.

Page 20: The Linux Kernel

Action

• Respawn – restart whenever it terminates.• Wait – don’t continue until it completes.• Once – will not wait for completion.• boot – run at boot time.• Bootwait – start at boot time and wait for

completion before continuing.• ondemand, initdefault, sysinit, powerwait,

powerfail, powerkwait, ctrlaltdel.

Page 21: The Linux Kernel

• Read /etc/fstab

• Read /etc/inittab

• Run /etc/rc.sysinit

• Run /etc/rc

• Run the K* and S* startup scripts.

Page 22: The Linux Kernel

inittab and sysinit

• The file rc.sysinit is a script run once at boot time to set up services specific to the computer system:– Hostname– Networking– Etc.

Page 23: The Linux Kernel

rc Scripts

• They keep track of the large number of services to be managed.

• The main rc script is /etc/rc.d/rc

Page 24: The Linux Kernel

/etc/rc.d/rc

• Responsible for calling the appropriate scripts in the correct order for each run level.

Page 25: The Linux Kernel

/etc/rc.d/rc[0-6].d

• There is an additional directory for each different runlevel: 0-6.

• Each directory has the scripts needed to run the specified boot level.

• The files in these subdirectories have two classifications: kill and start.

Page 26: The Linux Kernel

Kill and Start Services.

• The letter K is the prefix to all services to be killed.

• The letter S is the prefix to all the services to be Started.

• The K & S prefixed names are links to the actual service scripts located in /etc/rc.d/init.d

Page 27: The Linux Kernel

Order of services

• A number follows the S or K prefix.

• The number determines the order of execution.

• The rc file accesses the correct run-level directory and executes the files in numerical order.

• K files are first, then S files.

Page 28: The Linux Kernel

K and S scripts

• Every script in the /etc/rc.d/init.d directory is run with one of two options:– stop if the prefix is K– start if the prefix is S

/etc/rc.d/init.d/xfs start

/etc/rc/d/init.d/sound stop

Page 29: The Linux Kernel

Adding services

• If a service need be installed at boot time, you can edit the /etc/rc.d/rc.local file.

• Or add functionality by adding a script to the /etc/rc.d/init.d directory.

Page 30: The Linux Kernel

Contents of Custom RC script

• A description of the scripts purpose.

• Verify the program really exists before attempting to start it.

• Parse for start and stop command line options.

• Put your script in the /etc/rc.d/init.d directory.

Page 31: The Linux Kernel

Link the New RC script

• Add new service script to the /etc/rc.d/init.d directory.

• cd to the correct run level directories,

cd /etc/rc.d/rc5.d

• Add the linkln –s ../init.d/mynewservice S98mynewservice

Page 32: The Linux Kernel

/etc/rc.d/rc.local

• You can also add a service by modifying the /etc/rc.d/rc.local file.

• /etc/rc.d/rc[0-6].d/[K,S]99local

Page 33: The Linux Kernel

Core Services

• init – process id 1.

• inetd – Traditional Unix service.

• xinetd – Linux version of inetd. Used to manage some services: xinetd.org/faq.html

• syslogd – logs system messages to /var

• cron – used to start utilities at a pre-described time.

Page 34: The Linux Kernel

Review: init

• The parent process of all processes.

• Started by the kernel at boot time.

• If a process dies before all of its children complete, then the children inherit init as the parent (PPID = 1).

• Controls the run level with /etc/inittab.

Page 35: The Linux Kernel

inetd & xinetd

• Daemons – independent background processes that poll for events.

• Events sent to the daemons determine how the daemon behaves at any given time.

Page 36: The Linux Kernel

inetd

• Pre-Linux tool.

• The supervisor of network server-related processes.

• Rather than running many daemons taking up memory, initd polls for daemon requests. When a particular daemon gets an event, initd will activate the appropriate daemon.

Page 37: The Linux Kernel

xinetd

• Linux implementation of inetd.

• A list of the services currently offered by xinetd are in /etc/xinetd.d directory.

Page 38: The Linux Kernel

syslogd daemon

• With programs/services disconnected from a terminal, where does their standard output go?

• Syslogd routes the output of services to text files.

• Most log files are in /var/log

• Works in a heterogeneous environment.

Page 39: The Linux Kernel

syslogd

• /sbin/syslogd

• /etc/syslogd.conf

• man syslogd

Page 40: The Linux Kernel

/etc/syslog.conf

• Syntax of file involves– Facility: mail, kern, daemon, lpr, other services– Priority: emerg, alert, warning, err, notice, etc.– Log file

*.emerg @loghost,childrja,root

Emergency messages are sent to machine loghost and to the console session of childrja and root.

Page 41: The Linux Kernel

cron

• Used to schedule programs to run.

• Cron wakes up once every minute and checks all the crontab files on the system.

• If an entry in one of the crontab files matches the date and time, then the designated process is run.

Page 42: The Linux Kernel

crontab

• /etc/cron.allow

• /etc/cron.deny

• Crontab file syntax:

• Min Hr Day Month DayofWk command