1 / 42

The Linux Kernel

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

Download Presentation

The Linux Kernel

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. The Linux Kernel

  3. Linux & the Kernel

  4. 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.

  5. 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

  6. Kernel Startup • Checks memory • Probes for hardware

  7. 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.

  8. 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.

  9. Kernel startup • Create tables for memory management.

  10. 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)

  11. Dummy processes • Swapper • vhand, kflushd, kpiod, mdrecoveryd

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

  13. /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

  14. 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.

  15. init: Processes •  The basis of all Linux systems. • Run perpetually in the background waiting for input. • Services • Daemons • Shells • utilities

  16. 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.

  17. 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.

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

  19. 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.

  20. 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.

  21. Read /etc/fstab • Read /etc/inittab • Run /etc/rc.sysinit • Run /etc/rc • Run the K* and S* startup scripts.

  22. 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.

  23. rc Scripts • They keep track of the large number of services to be managed. • The main rc script is /etc/rc.d/rc

  24. /etc/rc.d/rc • Responsible for calling the appropriate scripts in the correct order for each run level.

  25. /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.

  26. 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

  27. 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.

  28. 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

  29. 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.

  30. 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.

  31. 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 link ln –s ../init.d/mynewservice S98mynewservice

  32. /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

  33. 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.

  34. 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.

  35. inetd & xinetd • Daemons – independent background processes that poll for events. • Events sent to the daemons determine how the daemon behaves at any given time.

  36. 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.

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

  38. 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.

  39. syslogd • /sbin/syslogd • /etc/syslogd.conf • man syslogd

  40. /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.

  41. 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.

  42. crontab • /etc/cron.allow • /etc/cron.deny • Crontab file syntax: • Min Hr Day Month DayofWk command

More Related