Introduction
This article is for those who want to learn a little more about Linux, but either hesitated to ask, or have not thought about it yet. We start with the biggest disappointment - there is no Linux operating system.
Linux OS is not
First, let's understand the terminology and how the computer works. We have a program. Their work is provided by the operating system (OS). The operating system is provided by the OS kernel. Here is a matryoshka: Kernel -> OS -> Programs.
By and large, the fact that “I will install Linux myself” is a big terminological confusion. True to say, for example, “I will install Debian GNU / Linux myself”.
The fact is that Linux is the universal core of the OS. It can work with any OS compatible with it. In short, Linux is just the kernel.
The operating system to which we are all accustomed and which stands on our servers and desktops is called GNU. GNU is compatible with the Linux kernel and it is this OS that is paired with this kernel in most distributions.
And what is a distribution kit? The distribution is a ready-made set of “Kernel + OS + Programs”. Each distribution kit is just a well-assembled and debugged puzzle from the Linux + kernel of the GNU + OS suite of programs. For example Debian GNU / Linux.
By the way, the same Debian is in the version with a different kernel, the assembly has the keyword kfreebsd - this is Debian GNU with the kernel from FreeBSD.
In general, there is no Linux OS, there is a kernel, a cool, beautiful and universal one. On this core, OS is made for mainframes (1 in the world), for servers (1 in the world), desktops (3 in the world) and network equipment (for example, for home routers).
')
How does it all start?
In addition to the fact that we have already installed Debian GNU / Linux, it should somehow run. Rather, someone should run it. Together with Debian comes the universal OS loader - GRUB. Grub can run not only Linux, but any operating system that supports the multiboot protocol - freebsd, netbsd, openbsd, any Linux + GNU, or without GNU. In addition, Grub can run MacOS and Windows without multiboot.
So how does our Linux computer start?
First, the motherboard and its firmware start up. They organize the processor access to the BIOS code and start the processor (CPU). The CPU starts executing the BIOS code.
The only task for the BIOS in this case is to find and start the bootloader. He finds a bootloader on one of the disks. This is what the BIOS found - this is not GRUB itself, this is a bootloader of 512 bytes in size. It is called stage1. This small 512 byte bootloader, the only thing that does is download GRUB from the same disk.
Well, GRUB has booted up and we have a greeting on the screen with the choice of the OS boot option and a countdown to the boot in the “default” mode. We are waiting for these three seconds ...
Next, GRUB does the following.
It loads the Linux kernel and the so-called initramfs into memory. initramfs is the minimum GNU system image required to boot the system itself. This image contains drivers for working with hardware and there are settings needed to start the OS.
The kernel and initramfs are loaded and GRUB transfers control to the entry point in the kernel. The kernel is being initialized. Runs modules, finds and registers hardware, file systems, network interfaces, and more. When the kernel completes its prelude, it launches / sbin / init from initramfs. This program does one task - preparing to start the OS - building a RAID, LVM, mounting file systems.
When / sbin / init has done its job, a magic operation occurs - Change Root. The kernel kills the initramfs image loaded into memory and mounts the root file system of our OS.
After that, control is transferred to / sbin / init already from our “real” system. It also performs only one task - it launches programs from the launch list.
Programs are launched, the network is configured, a graphical shell is launched.
Well, our OS is loaded.
In short, about all the GNU / Linux boot steps:
- BIOS - boot boot loader
- boot-loader 512 bytes - loads grub
- GRUB - loads the kernel and initramfs
- The kernel is looking for and starting equipment
- initramfs (/ sbin / init) prepares everything to start the OS
- Change Root to a real system
- / sbin / init present system runs programs
- We see a login greeting (one of the programs launched in step 7, for example gdm)
Why is everything so difficult?
Well no! Everything just seems difficult - every single part is simple and performs its own small task, each part is as simple as a cork. Do not believe?
A BIOS that finds the disk and loads 512 bytes into memory is simple. If I knew the specification for my motherboard, I would write it in a few hours.
The boot-loader that loads GRUB is simply impossible — it even weighs only 512 bytes. I wrote it several times - believe 40 minutes is enough for this "for the eyes." He is very simple.
GRUB is the only thing that can - boot the OS. By the way, the GRUB inside is broken into small and simple pieces.
The kernel is the only thing that can do - work with hardware and file systems. By the way, it is also inside broken into small pieces - modules. Each module - performs only its task.
Initramfs is simple to ugliness - there are only files with kernel modules needed for working with hardware and file systems. And a small / sbin / init, which is written in bash and simply collects RAID as it is written in the config file, which is also simple to disgrace.
Change Root - an operation that is written in the code of the Linux kernel, looks magical, but believe me - it is simple to disgrace - bang several pages of memory and use already running modules to mount the root FS.
/ sbin / init from real system? Yes, this is just a for loop, which will go through the files from the /etc/rc*.d directories in the right order and run each file.
OS is not complicated. Complex programs in it. GNU / Linux itself is simple and transparent. The kernel is as separated as possible from the system, the bootloader is separated from the rest. Everyone does their own small business and the result is a flexible and versatile system. This is an example of a correct and beautiful OS architecture.
Kernel and modules
The Linux kernel is not a monolith. It would be too complicated, and no one loves it (m. Except the Hindus from “some companies”). It is divided into modules. Each module can work with something one - with some kind of one piece of hardware or file system or something else.
I have written kernel modules more than once, and this is really simple, because most of them have already been done for you and you just need to do “your part”.
And how will I install all this for myself? I can not!
And nothing to be able and not necessary. The installation program of the same Debian GNU / Linux itself will find your disks and offer to configure FS. In general, setting up FS is the only thing you have to configure when installing Linux. It will install GRUB and boot-loader on this FS and your disks, install the OS and the kernel itself, create the initramfs image itself.
At the end, it will offer you to install ready-made sets of programs at once, for example for Desktop. Feel free to install and you will have a ready and customized computer for work.
How to manage it then?
This is also not difficult. An ordinary user from the system management needs only two commands:
apt-get install program
apt-get remove program
Debian GNU / Linux is so easy to use that you don’t even have to search for the necessary software - everything has already been found for you, given the name and put into the repository.
You just say the OS - “put me chromium“ (apt-get install chromium) and in a few seconds you will have your favorite browser downloaded and installed.
I want to write Linux too!
Linux is like a kernel, GNU is like an OS, Debian is like a distribution, it is completely open source software. Anyone can write something of their own, debug “on themselves” or “on cats” and send a patch (or nowadays trendy pull-request) to meinteiners. They will look at your code and idea, and if this is a really necessary thing for people, they will include it in the kernel, in the OS or in the distribution kit (depending on what you wrote there).
Where the stories about tambourines and "sex with Linux"
There are lots of such stories and they express their indignation. And the reason for resentment is simple - I want to customize (I'm an admin!), But I don't want to read the documentation. In general, everything is standardized and described in Linux and GNU. If you, excuse me, a pervert and want to run Linux on some strange file system - read - does GRUB know how to do it? You will understand whether GRUB will be able to start your OS (read the file with the kernel and initramfs). In the same documentation read, it is possible that in GRUB you will need to add a special module for your “strange” FS.
The second reason for tambourines is also not read the documentation, only to the gland. There is a mass of iron on the market now. Not all hardware is supported by all operating systems. Do not believe? Does windows work everywhere? Put Windows 7 on IBM System-Z, and I laugh. This is the misfortune of some iron manufacturers - the lack of open documentation and, as a result, the lack of drivers. Now Linux can be run on any hardware. Oddities arise with non-standard (or very rare equipment), usually purchased additionally from a computer. Such things as webcams or graphics tablets have long been no problem for Linux - almost all manufacturers of such equipment either wrote the drivers themselves or opened the documentation and the Linux developers did. But still, before you buy a piece of iron - make sure that Linux is familiar with it.
Everything is perfect? But there are difficulties
There are difficulties - the only difficulty that I still have to circumvent is the formats of office documents. Unfortunately, MS, as a monopolist of the office software market, chose not to disclose these formats. But I get out of the situation easily - Google Docs, it is even more convenient than MS Office.
Afterword
The GNU system, the Linux kernel, and numerous distributions are simple. In this article I was able to quickly and briefly tell about one of the main tasks of the system - its loading. And you understand! This suggests that everything is not so difficult and do not need to be afraid of it.
Good luck to you, a beginner Linuxoid (and maybe the future developer of this beautiful kernel and the GNU OS).