Press the power button on your system unit, and after a few seconds you will see the login window.
I dare to assume that everyone was interested at least in what was going on behind a curtain of splash screens and loading screens from the moment the computer was turned on to the moment when it was suggested to enter the system.
I suggest you get acquainted with the following typical Linux boot levels:
1. BIOS
The BIOS is responsible for basic data input / output from devices to devices.
Does some device integrity checks. In addition, POST (Power-on self-test, also “self-adequacy test”, performed as a pre-boot stage), which is controlled by the BIOS, is responsible for testing the performance of electronics.
Searches, loads and executes the OS loader
Takes bootloader from floppy, sidyuka or hard drive. During the BIOS boot, you can click on the button (usually F12 or F2 or Del, depending on the platform), if you need to make some changes regarding the hardware settings.
Once the boot loader has been detected and loaded into memory, the BIOS transfers control to it.
In short, the BIOS loads and executes a boot record (MBR).
2. MBR
MBR is the master boot record stored on the hard disk.
It is located in the 1st sector of the boot disk, for example / dev / hda or / dev / sda
MBR takes less than 512 bytes. It consists of three components: 1) the main boot information, "living" in the first 446 bytes; 2) partition table information is in the next 64 bytes; 3) and the last 2 bytes are needed to verify mbr.
It contains information about GRUB (or LILO).
In simple terms - the MBR loads and executes the GRUB bootloader.
3. GRUB
GRUB - Grand Unified Bootloader.
If you have more than one kernel installed on your system, you can choose which one should be executed.
GRUB displays a beautiful animation of the plymouth screensaver, and after waiting a few seconds for the user to interact interactively, if he did not press any keys, he loads the default kernel in the grub configuration file.
GRUB understands what a file system is (ancient Linux loaders, for example, LILO do not understand this).
The Grub configuration file is usually located along the path /boot/grub/grub.conf (also /etc/grub.conf can be a symbolic link to it). Here is an example of a configuration file for CentOS:
As a note to the information above, the configuration file contains the path to the kernel and the initrd image
In short, GRUB simply loads and executes kernel and initrd images.
4. Kernel or Kernel
The kernel mounts the file system according to the “root =” setting in the grub.conf file
Runs the program / sbin / init
Since init is the first process started by the Linux kernel, it therefore has process ID (PID) # 1. You can run “ps -ef | grep init "and see this.
initrd - this is the Initial RAM Disk, it is also a temporary disk in RAM
The initrd is used by the kernel itself as a temporary root file system until kernel boots into the real mounted file system. This temporary disk also contains the necessary drivers to download, allowing you to access disk partitions and other equipment.
5. Init
Looks at the / etc / inittab file to determine the run level.
There are the following performance levels:
0 - abort execution
1 - Single user mode, the so-called “Single user mode”, or in other words, recovery console
2 - Multi-user mode without NFS support
3 - Full multi-user mode
4 - not used
5 - X11
6 - reboot
Init determines the default run level based on / etc / inittab and uses it to load all necessary programs.
Run “grep initdefault / etc / inittab” on your system, and you will find out which default level you are using
If you can't live in peace, you can set the standard level to 0 or 6. :)
In most cases, level 3 or 5 will be enough for you.
6. Level of execution of programs (Runlevel)
When Linux performs its boot, you can watch the download of various services. For example, it can be messages like “starting Postfix ... OK” (Postfix starts). These services are called execution-level programs executed from a directory that corresponds to the desired level of execution.
Based on the default settings, the system will execute the files in the following directories.
Level 0 execution - /etc/rc.d/rc0.d/
Tier 1 execution - /etc/rc.d/rc1.d/
Level 2 execution - /etc/rc.d/rc2.d/
Level 3 execution - /etc/rc.d/rc3.d/
Level 4 execution - /etc/rc.d/rc4.d/
Level 5 execution - /etc/rc.d/rc5.d/
Run level 6 - /etc/rc.d/rc6.d/
But keep in mind that there may also be symbolic links in the / etc directory. For example, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
In the /etc/rc.d/rc*.d/ directories you can see a list of programs that begin with the letters S and K.
Programs beginning with S are used to run. S, because s tartup.
Programs that start with the letter K are used - correctly - to complete the work. K, because k ill.
There are also numbers next to the letters S and K in the program names. These numbers are used to determine the order in which these programs are run.
For example, S12syslog is designed to start the syslog daemon, its sequence number is 12. S80sendmail - to start the sendmail daemon, which has a sequence number of 80. Thus, the syslog program will be launched before sendmail.
')
That's all. Perhaps, for some of you, this is not new and there was not much interest in reading the article, since it is more focused on the initial-middle level of acquaintance with Linux.
In this case, I can only say that “repetition is the mother of learning” (c).
artemlight:: “Well, let's face it - not all distros are loaded this way.” Most agreed with him, noting bsd-style init, u-boot, and even though the initrd is omitted in the article, it’s worth noting that the kernel doesn’t need it in all distributions. It is also noted that in slackware, rc.d support is provided only as compatibility, and embedded systems are loaded differently. On dekstopah sometimes EFI, and in addition Linux is popular in the embedded world and there are still a lot of different platforms. Linux on the phone is generally loaded differently.
soomrack , referring to Wikipedia: I also want to make a comment about the MBR, the first sector, etc. Everything has become somewhat more complicated in recent years. Now it is more appropriate to talk about EFI.
“GUID Partition Table (GPT) is the standard layout for partitioning tables on a physical hard disk. It is part of the Extensible Firmware Interface (EFI) (Extensible Firmware Interface) - a standard proposed by Intel to replace the outdated BIOS, one of the latest relics of the original IBM PC. EFI uses GPT where the BIOS uses the Master Boot Record (MBR) .... "
Xpeh adds that “the BIOS (and the (U) EFI not mentioned here) is primarily concerned with the initialization of devices (including the loading of its own bios of PCI devices), nothing is written about it. Although this role is gradually diminishing, as more and more hardware initializes itself and / or supports hotplugging and therefore the OS is still initialized, but, for example, it always initializes the RAM. „
- directories /etc/rc?.d/ real directories, not links;
- in these directories are stored references to scripts in the /etc/init.d/ directory
Manually it is better not to edit anything in /etc/rc?.d/, but use the update-rc.d command, which allows you to create links, delete them, prohibit (actually rename from S * to K *) and allow (c K * to S *) launch.