More on Kernel
The kernel code contains both machine dependent as well as machine independent code. This is because the same kernel will be used on a variety of devices which uses different processor architecture.
The following section describes what the machine dependent and machine in-dependent code deals with
Machine dependent code
- Low level system startup function
- Traps and fault handling
- Low level manipulation of runtime context of a process i.e., context switching
- Configuration and initialization of hardware devices
- Runtime support for I/O devices
Machine independent code
- System call handling
- The file system: files, directories, pathname translation, file locking and I/O buffer management
- Terminal handling support: the terminal-interface driver and terminal line disciplines.
- IPC facilities
- Network communication support
Terminal Line Discipline
(Source)
Terminal line disciplines refer to the terminal type (TTY) that is to be used - RawTTY & CookedTTY
- Cooked Terminal Type
- This is also called canonical mode.
- The terminal driver is, by default a line-based system i.e., characters are buffered internally until a carriage return (
Enter or Return) is passed to the program - this is called cooked i.e., the terminal driver "cooks" the characters before serving them up.
- This allows certain characters to be processed, such as
Ctrl+D, Ctrl+S, Ctrl+U, Backspace);
- Raw Terminal Type
- This is also called non-canonical mode.
- The terminal can be placed into raw mode where the characters are not processed by the terminal driver i.e., special characters are not processed, but are sent straight through.
<aside>
💡 The architecture dependent code can be accessed at /usr/src/<linux-kernel>/arch.
</aside>
Booting Procedure
(Source 1) (Source 2)
The booting procedure involves the following steps -
-
Power On - BIOS
- BIOS (Basic Input Output System) is a software program comes pre-built in a motherboard chipset.
- BIOS loads and scans for devices such as Hard Disk, CD-ROM, RAM, etc.
- BIOS searches for MBR of the primary hard drive, it scans for 1st stage loader and hands over the responsibility to MBR.
-
Master Boot Record (MBR)
- MBR contains the information of loader of most operating system.
- MBR involve a mini executable programs and a table specify the primary partitions.
- The BIOS surrender rights to the first stage boot loader, which then scans partition table and finds second stage boot loader on the partition configured as bootable.
-
Boot Loader
- The 1st stage loader a.k.a boot loader loads itself into RAM.
- The default stage 2 boot loader is a GRUB (Grand Unified Boot Loader) or LILO (Linux Loader)
- Once GRUB is loaded into RAM, then it’s search for the location of Kernel i.e., it searches for
vmlinuz bootable file under /boot directory and loads its.
(A brief video explanation about the Boot Loader on Youtube)
-
Initializing the Kernel
- All of the kernels are in a self-extracting, compressed format to save space. The kernels are located in the
/boot directory, along with an initial RAM disk image, and device maps of the hard drives.
- After the selected kernel is loaded into memory and begins executing, it first extracts itself from the compressed version of the file.
- Once the kernel has extracted itself, it loads
systemd process and turns control over to it.
systemd is a replacement to the old init (a.k.a SysV init).
-
The systemd process
systemd is the mother of all processes and it is responsible for bringing the Linux host up to a state in which productive work can be done.
- Some of its functions are mounting filesystems, starting and managing system services required to have a productive Linux host.
- The
systemd process boots the system into the run level as specified in /etc/inittab
-
Run Level
- A runlevel is one of the modes that a Unix-based OS will run on.
- Each runlevel has a certain number of services stopped or started, giving the user control over the behavior of the machine. Conventionally, seven runlevels exist, numbered from zero to six.
Runlevels