Wednesday, August 7, 2024

How the Linux System Boots

I come form a scientific background where standards and uniformity should rule but in the current world it does not happen even in the Linux World. Sometimes, I think Ubuntu is a pain in the but in Linux environment. 

I do not use Ubuntu.

Linux comes from the framework of Unix but with a difference. System, processes not events rule the Linux world. Ubuntu comes and puts words like Events, Compositors and the like and muddy the waters. Whereas, I come from the tiniest of the Linux World, i.e; Puppy Linux and it is the only distribution when there is kernel panic it leaves behind a set of textural information from which one can recover.

That is why, I  have over 20 Puppy Linux derivative (only a few are 64 bits) including Games Puppy in my download folder. 

I wish Puppy Linux guys work hard and get all of them 64 bit compatible. Puppy does not have lot of overheads and it can be done but I am, too old, to invest my time on a such an adventure except write few blog pieces.

How the Linux System Boots 

1. System V Init

System V (SysV) is a mature and popular init scheme on Unix like operating systems, it is the parent of all processes on a Unix/Linux system. SysV is the first commercial Unix operating system designed. Almost all Linux distributions first used the SysV init scheme except Gentoo which has a custom init and Slackware which uses the BSD style init scheme.

As years have passed by, due to some imperfections, several SysV init replacements have been developed in the quest to create more efficient and perfect init systems for Linux.

Although these alternatives seek to improve SysV and probably offer new features, they are still compatible with original SysV init scripts.SystemV is very old boot loader that comes from Unix Multi Frame Architecture dating back to 1983. If I remember right, Suse Linux used, it in the past and it has 6 level of interaction. It is a server based system and Level 1 is the single user level.One looks at the /etc/inittab file to decide the Linux run level.

Following are the available run levels

0 – Halt

1 – Single user mode

2 – Multiuser, without NFS

3 – Full multiuser mode

4 – unused

5 – X11

6 – Reboot

Init identifies the default init level from /etc/inittab and uses that to load appropriate program. Typically, the default run level is either 3 or 5.

2.System D

SystemD is a relatively new init scheme on the Linux platform. Introduced in Fedora 15, it is an assortment of tools for easy system management.       The main purpose is to initialize, manage, and keep track of all system processes in the boot process and while the system is running. Systemd init is comprehensively distinct from other traditional Unix init systems, in the way, it practically approaches system and services management. It is also compatible with SysV and LBS init scripts.

It has some of the following eminent features:

Clean, straightforward, and efficient design

Concurrent and parallel processing at bootup

Better API

Enables removal of optional processes

Supports event logging using journald

Supports job scheduling using systemd calendar timers

Storage of logs in binary files

Preservation of systemd state for future reference

Better integration with GNOME desktop.

SystemD boot is a UEFI boot loader developed as part of the SystemD system and service manager, which was designed to load EFI executable images, such as Linux kernels, initramfs images and other operating systems, such as Windows.

SystemD boot is a relatively new boot loader, but it has become popular due to its simplicity and performance. It is also the default boot loader for many modern Linux distributions.

3. Upstart

Upstart is an event based init system developed by the makers of Ubuntu as a replacement for the SysV init system. It starts different system tasks and processes, inspects them while the system is running, and stops them during system shutdown. It is a hybrid init system that uses both SysV startup scripts and SystemD scripts, some of the notable features of the Upstart init system include:

Originally developed for Ubuntu Linux but can run on all other distributions

Event based starting and stopping of tasks and services

Events are generated during the starting and stopping of tasks and services

Events can be sent by other system processes

Communication with the init process through D-Bus

Users can start and stop their processes

Re-spawning of services that die abruptly and many more.This was the init on Ubuntu installations. However, Ubuntu has  migrated to SystemD.

4. OpenRC

OpenRC is a dependency based init scheme for Unix like operating systems, it is compatible with SysV init. As much as it brings some improvements to Sys V, you must keep in mind that OpenRC is not an absolute replacement for the /sbin/init file.

It offers some illustrious features including:

It can run on other many Linux distributions including Gentoo and also on BSD

Supports hardware initiated init scripts

Supports a single configuration file

No per-service configurations supported

Runs as a daemon

Parallel services startup and many more

5. runit

runit is also a cross platform init system that can run on GNU/Linux, Solaris, BSD, and Mac OS X and it is an alternative to SysV init, which offers service supervision. It comes with some benefits and remarkable components not found in SysV init and possibly other init systems in Linux and these include:

Service supervision, where each service is associated with a service directory

A clean process state guarantees each process a clean state

It has a reliable logging facility

Fast system boot-up and shutdown

It is also portable

Packaging friendly

Small code size and many more

6. s6

This is the latest version of Linux based init system.

s6 offers a compact set of tools for UNIX, tailored for process supervision, similar to daemon tools and runit. It facilitates operations on processes and daemons. Designed as a low level service administration toolkit, s6 provides diverse tools that can function independently or within its framework. These tools, when combined, deliver robust functionality with minimal code.

As I had earlier mentioned, the init system starts and manages all other processes on a Linux system. Additionally, SysV is the primary init scheme on Linux operating systems but due to some performance weaknesses, system programmers have developed several replacements for it.

Syslinux

          This is Windows stuff, please do not confuse with Linux booting methods. While Linux can coexist with any file system and any operating system Apple and Windows try to carve their own capitalistic domains. Fortunately, I did not become a victim or a  prey.

Syslinux is a Linux's variant for FAT file systems. This is the oldest type of Syslinux boot loader. It supports FAT16, and FAT32 file systems. Syslinux is an assortment of lightweight boot loaders that enable booting from CD ROM, from the network, and from hard disks. It supports file systems such as FAT for MS DOS and ext2, ext3, and ext4 for Linux. It also supports uncompressed single device Btrfs.

Syslinux only accesses files in its own partition, therefore, it does not offer multi file system boot capabilities. It is rarely used in current systems and could be categorised as a Legacy Boot System.

Other Varieties

There are various other versions of init as well, especially on embedded platforms. For example, Android has its own init. The BSDs also have their version of init, but one is unlikely to see them on a modern Linux machine. However, some distributions have modified the System V init configuration to look like BSD style.

Identifying init

If one needs to determine theversion of the initsystem, one should look at the configuration files.

If you are not sure, check your system configuration filesas follows:

If your system has /usr/lib/systemd and /etc/systemd directories, you have systemd.

If you have an /etc/init directory that contains several .conf files, you’re probably running Upstart unless you’re running Debian 7, in which case you probably have System V init.

If neither of the above is true, but you have /etc/inittab file, you’re probably running System V init.

If your system has manual pages installed, viewing the init ( ) manual page should help to identify your version of init.

In summary, in Unix based computer operating systems, initialization (init) is the first process that starts during system booting. Init is a daemon process that continues running and until the system is shut down. It is the direct or indirect ancestor of all other processes and automatically adopts all orphaned processes. Init is started by kernel during the booting process and a kernel panic ensues, if the kernel is unable to start it, or it dies for any reason.

Init is typically assigned process identifier 1.

In Unix systems such as System V, the design of init has diverged from the functionality provided by the init in Research Unix and its BSD derivatives. Up until the early 2010s, most Linux distributions employed,      a traditional init that was somewhat compatible with System V, while some distributions such as Slackware use BSD style startup scripts, and others such as Gentoo have their own customized versions.

Since then, several additional init implementations have been created, attempting to address design limitations in the traditional versions. These include launchd, the Service Management Facility, systemd, Runit and OpenRC.

Over the years, many init systems have emerged in major Linux distributions and it is bit confusing to the ordinary user but one should not worry unless system panic does occur during the boot up process.     In my experience, Puppy Linux, probably the only distribution that gives running commentary, of course in  textural form, in a black terminal, if kernel panic is the end result.

No comments:

Post a Comment