430 likes | 802 Views
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
E N D
The Linux Kernel • About 6 million lines of code • Controls memory and process management.
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.
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
Kernel Startup • Checks memory • Probes for hardware
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.
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.
Kernel startup • Create tables for memory management.
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)
Dummy processes • Swapper • vhand, kflushd, kpiod, mdrecoveryd
Kernel Startup • Find and mount the other partitions starting with the swap partition space. • The /etc/fstab
/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
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.
init: Processes • The basis of all Linux systems. • Run perpetually in the background waiting for input. • Services • Daemons • Shells • utilities
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.
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.
/etc/inittab • Additional programs and services are started when init reads the contents of inittab.
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.
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.
Read /etc/fstab • Read /etc/inittab • Run /etc/rc.sysinit • Run /etc/rc • Run the K* and S* startup scripts.
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.
rc Scripts • They keep track of the large number of services to be managed. • The main rc script is /etc/rc.d/rc
/etc/rc.d/rc • Responsible for calling the appropriate scripts in the correct order for each run level.
/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.
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
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.
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
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.
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.
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
/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
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.
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.
inetd & xinetd • Daemons – independent background processes that poll for events. • Events sent to the daemons determine how the daemon behaves at any given time.
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.
xinetd • Linux implementation of inetd. • A list of the services currently offered by xinetd are in /etc/xinetd.d directory.
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.
syslogd • /sbin/syslogd • /etc/syslogd.conf • man syslogd
/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.
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.
crontab • /etc/cron.allow • /etc/cron.deny • Crontab file syntax: • Min Hr Day Month DayofWk command