Basic Theory of Linux - Day 0

Everyone knows what linux is: An open source operating system kernel which has been widely accepted in the entire world to create, deploy computer programs. So, I’ll rather not waste your time on a fancy definition of linux. For now, the definition that Linux is an opensource operating system kernel works fine
Linux Philosophy
Linux was inspired heavily by UNIX. At that time when linux was built, UNIX was not for rookies like you and me. It was built for computers which were much more powerful than ours PCs and were very expensive (IDK about you but I am broke af so I couldn’t buy it)
Linux stores files in a hierarchical file system with the top node being /root or /. In linux, everything including devices, processes, network sockets are treated like a file. Files are not just .txt or .pdf, everything acts as a file (but are not actual files)
Why?
Cuz it makes life easier
How?
Let’s say you want to read something from your keyboard. It’s easy to read it directly from a file named /dev/keyboard
Let’s say you want to send something to your printer. It’s easy to write something to a file named /dev/printer
So, you see reading data and writing data in files is very simple. That’s why everything is treated like a file. If you have a linux distro like ubuntu, arch or anything, just open your terminal and type cat /proc/cpuinfo. You’ll be able to see information about your cpu in it
So everything is treated like a file as doing operations like read, write, rename, copy and others are easy in a file that’s why smart bros at linux adopted this philosoply
Fancy Terminologies
These are some terms you should know about Linux that will impress your non-tech friends (or techie friends with low knowledge bandwidth)
Kernel: I gave a definition previously which is an oddly simple definition
Boot loader: As the name suggests, it is the program that boots up the operating system
Services: Programs that run as background processes
fs (filesystem): The way by which files are organized and managed. e.g: ntfs, ext3, FAT
X window system: The X window system provides the standard toolkit and protocol for building gui on nearly all linux systems
Desktop Environment: The GUI built on top of operating system
Command Line Interface (CLI): The interface used for typing commands
Shell: The CLI that interprets the command line input and instructs OS to perform necessary tasks based on the user input
Distributions: A full Linux distribution consists of the kernel plus a number of other software tools for file-related operations, user management, and software package management.
The Boot Process
The boot process is the process by which your system gets initialized. It consists of different processes from powering on your computer to the user interface that you see
But why is it important? It might help you troubleshoot your problems while using your linux based OS

This is the diagram of the internal processes which helps to see your GUI after you power on your pc. Now, I’ll try to explain each part of it
Power On - The Step 0
You already know it
BIOS
When the computer is powered on, the Basic Input/Output System (BIOS) initializes all the hardware components including screen, keyboard in your pc and tests the main memory. This process is called Power on Self Test (POST)
The BIOS software is then stored on your ROM chip in the motherboard. Then the remaining of the boot process is handled by your OS
Boot Loader, MBR, EFI
Well, in the diagram MBR and EFI was before boot loader but its better to study all these together cuz it will ultimately get interliked
After The POST process, the system control is passed to the boot loader. The boot loader is stored on the persistent storage like your slow HDD or fast SSD in either the boot sector (for MBR partition systems) or the EFI partition sector. Then the information on date, time and other settings are being loaded from the CMOS.
Stages
The boot loader has 2 distinct stages:
In BIOS/MBR systems, the boot loader is stored in the first 512 bytes of the hard drive, called the Master Boot Record (MBR). It checks the partition table, finds a bootable partition, and loads a second-stage boot loader like GRUB into RAM.
In UEFI systems, the UEFI firmware reads its Boot Manager to find and launch a UEFI application like GRUB from the EFI partition. This process is a bit more complex but more flexible than MBR.
The second-stage boot loader (stored in /boot) shows a menu to pick an operating system or kernel. Once selected, it loads the kernel into RAM
2 lines to summarize boot loader
The boot loader is responsible for loading the kernal into the RAM so that the computer system can start
It loads the kernel into RAM because RAM is much faster than storage devices, and the CPU can only run programs directly from RAM, not from the hard drive or SSD
Initial Ram Disk

The initramfs is the filesystem image that consists of programs and binary files that contains instructions about mounting proper root fs, kernel functionality, locating devices and driver and then load them. Then it checks for errors in the root filesystem
After the mount program instructs the OS that the filesystem is error free and ready to use, the initialization program (sbin/init) is run after the initramfs gets cleared from the RAM.
Command Shell Using getty
After the init command is executed, the terminal loads up for you to login to your linux OS.
getty is the program that opens the terminal, displays the login prompt, and then hands over control to the login process once you enter your username.
Kernel, init and Services
The Linux Kernel

The boot loader initializes the kernel and the initial RAM file system (initramfs). After the kernel instructions are loaded to the RAM, it immediately initializes and configures the computer memory and all the hardware attached to the PC
/sbin/init and Services
After the kernel sets up the necessary hardware components and mounts the file system, the init process is executed. It is the initial process that gets other systems running. Besides starting the system, the init process is also responsible for starting the PC and shutting it down correctly.
Startup Services
When your system starts, there are scripts that are responsible to start your system. Old Linux boot systems (SysVinit) started things one by one, slowly and step-by-step, which didn’t use modern multi-core processors well.
Back in those days, boot time was not considered as a very vital thing, but then it become a major deciding factor among users. No one wanted a slow ass system which would take long time to boot. To fix this, newer systems were developed:
Upstart (by Ubuntu, around 2006) — used for a while but later dropped.
systemd (adopted widely from 2011) — now used by almost all Linux systems.
systemd
Systems with systemd starts up a service much faster than the other init methods. This is mainly because it replaced linear sequential steps to parallel steps. One systemd command (systemctl) can be used to start or stop any services in your pc
Small Exercise using systemctl command
Let’s do a worthless experiment to check the systemctl command:
In your pc, there is a service named Apache Web Service
I am using ubuntu so to install Apache Web Service, I’ll run these commands
sudo apt update sudo apt install apache2
Now, to stop this service run
sudo systemctl stop apache2To start this service run
sudo sysemctl start apache2To check its status run
sudo systemctl status apache2
Linux Filesystems
Intro
Different types of filesystems supported by Linux:
Conventional disk filesystems: ext3, ext4, XFS, Btrfs, JFS, NTFS, vfat, exfat, etc.
Flash storage filesystems: ubifs, jffs2, yaffs, etc.
Database filesystems
Special purpose filesystems: procfs, sysfs, tmpfs, squashfs, debugfs, fuse, etc.
Let’s learn about these now
Partitions and Filesystems
Partition is basically a part of your entire physical storage device that acts as a whole storage volume
A filesystem is a method of storing and accessing files inside a partition
Filesystem Hierarchy
As mentioned earlier, linux uses a filesystem hierarchy to store different files. If you want to know more about this hierarchy, you can read a 50 page pdf written by our smart bros at linux: File System Hierarchy
Some important info:
All Linux filesystem names are case-sensitive, so /boot, /Boot, and /BOOT represent three different directories (or folders). Many distributions distinguish between core utilities needed for proper system operation and other programs, and place the latter in directories under /usr (think user). To get a sense for how the other programs are organized, find the /usr directory in the diagram from the previous page and compare the subdirectories with those that exist directly under the system root directory (/).
Conclusion
Let’s leave this much for today, I hope I was able to add some knowledge to your knowledge stack. One like would really help to keep me motivated. Anyways, thanks for reading




