{"id":19723,"date":"2023-07-11T04:53:21","date_gmt":"2023-07-11T04:53:21","guid":{"rendered":"https:\/\/linuxways.net\/?p=19723"},"modified":"2023-11-13T06:13:54","modified_gmt":"2023-11-13T06:13:54","slug":"linux-boot-process","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/linux-boot-process\/","title":{"rendered":"Linux Boot Process"},"content":{"rendered":"<p>When a user presses the system&#8217;s power button or restart button, the login screen appears on their monitor. After logging in, the machine begins to function. There are several steps that are involved from pressing the power button to getting the login screen; this process is called the boot process.<\/p>\n<p>Here, we will discuss and understand about the Linux boot process in details. We can divide the boot process into six steps:<\/p>\n<ol>\n<li><a href=\"#1\">The BIOS<\/a><\/li>\n<li><a href=\"#2\">MBR<\/a><\/li>\n<li><a href=\"#3\">GRUB<\/a><\/li>\n<li><a href=\"#4\">Kernel<\/a><\/li>\n<li><a href=\"#5\">Init<\/a><\/li>\n<li><a href=\"#6\">Runlevels<\/a><\/li>\n<\/ol>\n<p>Here is one simple diagram to understand the whole Linux process.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-341721\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2023\/06\/word-image-341699-1.png\" \/><\/p>\n<h2 id=\"1\"><strong>The BIOS (Basic Input Output System): Starting Point of the Booting Process<\/strong><\/h2>\n<p>The BIOS is where the hardware and software first interact. When the system powers up, the power supply begins to distribute the current to the different parts of the computer so they can operate. When the CPU receives the current from the power supply, it searches for a special programme that helps load the operating system into the computer&#8217;s memory. This programme is called BIOS. The BIOS is a special programme which is hardwired into the motherboard itself.<\/p>\n<p>BIOS first performs an integrity check which is called a \u201cPower On Self Test (POST)\u201d. The POST process verifies whether all of the computer&#8217;s hardware like RAM, hard drive, CD-ROM drive, keyboard, etc., are working fine or not. If no error occurs, the boot process will continue. But if any error is encountered, it generates a beep sound, and the computer will not boot up.<\/p>\n<p>After the POST, the BIOS selects the first boot device and gives back the control to the CPU. If it does not find the first boot device, it checks for the second device, and so on. If it has not found any boot devices, it shows the &#8220;No Boot Device Found&#8221; error.<\/p>\n<h2 id=\"2\"><strong>MBR (Master Boot Record)<\/strong><\/h2>\n<p>After the BIOS, the control is back to the CPU. Now, the CPU loads the MBR to the memory.<\/p>\n<p>The first sector of a hard drive contains the MBR that indicates the system about the hard drive details and loads the steps for the operating system.<\/p>\n<p>MBR is a location on the disk with the following details:<\/p>\n<ul>\n<li>The primary boot loader information is stored in the first 446 bytes.<\/li>\n<li>The next 64 bytes store the Partition table information.<\/li>\n<li>The last 2 bytes store the magic number.<\/li>\n<\/ul>\n<p>From given information, we can get the MBR as 512 bytes in size.<\/p>\n<p>The primary boot loader information is the location of the actual boot loader. Using this location, the CPU loads the actual boot loader (GRUB).<\/p>\n<p>MBR contains 64 bytes Partition table which stores the following data:<\/p>\n<ul>\n<li>First and last address of each partition.<\/li>\n<li>What is the size of partition?<\/li>\n<li>What is the type of partition?<\/li>\n<\/ul>\n<p>The last 2 bytes of the MBR store the magic number. Here, the magic number is 0xAA55 which is used for validation check of the MBR.<\/p>\n<p>So, the primary boot loader\u2019s task is to find and load the secondary boot loader.<\/p>\n<h2 id=\"3\"><strong>GRUB (GRand Unified Bootloader)<\/strong><\/h2>\n<p>The GRUB is a boot loader which is responsible to load the kernel.<\/p>\n<p>This loader displays the GRUB menu from which we can choose the required operating system. If the user has not chosen any one from the menu with an optional timeout after the waiting time, the default one is loaded to the memory.<\/p>\n<p>After loading the kernel, it gives control to the kernel.<\/p>\n<h2 id=\"4\"><strong>Kernel<\/strong><\/h2>\n<p>Here are the sequences that are followed in kernel:<\/p>\n<ol>\n<li>The Linux kernel is first read into the memory.<\/li>\n<li>After loading the kernel into memory, the following things happen:<\/li>\n<\/ol>\n<p>The kernels are located in the \/boot directory in compressed format.<\/p>\n<p>After loading inside memory, it unzips itself from the zipped version. At the beginning of the kernel image, there is a routine which is responsible to extract from the compressed version.<\/p>\n<p>After self-extracting, the chosen kernel mounts the root file system which is specified in the \u201cgrub.conf\u201d file.<\/p>\n<p>Here is one sample \u201cgrub.conf\u201d file content:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co0\">#boot=\/dev\/sda<\/span><br \/>\n<br \/>\n<span class=\"re2\">default<\/span>=<span class=\"nu0\">0<\/span><br \/>\n<br \/>\n<span class=\"re2\">timeout<\/span>=<span class=\"nu0\">5<\/span><br \/>\n<br \/>\n<span class=\"re2\">splashimage<\/span>=<span class=\"br0\">&#40;<\/span>hd0,<span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">\/<\/span>boot<span class=\"sy0\">\/<\/span>grub<span class=\"sy0\">\/<\/span>splash.xpm.gz<br \/>\n<br \/>\nhiddenmenu<br \/>\n<br \/>\ntitle CentOS <span class=\"br0\">&#40;<\/span>7.2.18-<span class=\"nu0\">324<\/span>.el5PAE<span class=\"br0\">&#41;<\/span><br \/>\n<br \/>\nroot <span class=\"br0\">&#40;<\/span>hd0,<span class=\"nu0\">0<\/span><span class=\"br0\">&#41;<\/span><br \/>\n<br \/>\nkernel <span class=\"sy0\">\/<\/span>boot<span class=\"sy0\">\/<\/span>vmlinuz-7.2.18-<span class=\"nu0\">324<\/span>.el5PAE ro <span class=\"re2\">root<\/span>=<span class=\"re2\">LABEL<\/span>=<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\ninitrd <span class=\"sy0\">\/<\/span>boot<span class=\"sy0\">\/<\/span>initrd-7.2.18-<span class=\"nu0\">324<\/span>.el5PAE.img<\/div><\/div>\n<p>From the previous file, we can see the entry of the kernel and the initrd image.<\/p>\n<p>Then, it starts the \/sbin\/init programme. Init is the first program which is executed by the kernel. So, the PID of init is 1. To get the init\u2019s PID, the following command can be used:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">ps<\/span> <span class=\"re5\">-ef<\/span> <span class=\"sy0\">|<\/span> <span class=\"kw2\">grep<\/span> init<\/div><\/div>\n<p>It initialises and sets up all of the system&#8217;s hardware after being loaded into the memory.<\/p>\n<p>Then, it searches for the compressed initramfs image(s) in a specific area of memory, decompresses them directly to \/sysroot\/, and loads all the required drivers.<\/p>\n<p>It finishes the initramfs operations and releases all the memory that the disc image previously used by initializing the virtual devices that are connected to the file system.<\/p>\n<p>The root device is then created by the kernel, along with the root partition which is mounted as read-only and any unused RAM are released.<\/p>\n<p>The kernel is now active and loaded into the memory. There aren&#8217;t any user apps that allow the system to receive a significant input, so not much can be done with it. The kernel runs the \/sbin\/init programme to configure the user environment.<\/p>\n<h2 id=\"5\"><strong>Init<\/strong><\/h2>\n<p>The \/etc\/inittab contains a script that is read by init. The initial configuration script, which essentially takes care of everything a system has to do when it is initializing, is read by init. This includes the following:<\/p>\n<ul>\n<li>setting the clock<\/li>\n<li>initializing the serial port<\/li>\n<li>other tasks<\/li>\n<\/ul>\n<p>Init decides how the system should be configured for each runlevel by reading this file, and it also establishes the default run level.<\/p>\n<p>Init starts all background processes which are necessary to keep the system running after deciding on the system&#8217;s default runlevel. The kill scripts, whose file names begin with a K, are first executed with the stop option. To start all services and apps, it then executes all start scripts whose file names begin with S.<\/p>\n<h2 id=\"6\"><strong>Runlevels<\/strong><\/h2>\n<p>A runlevel is a Linux system software setting that only allows a predetermined set of processes to exist. Runlevels decide about the programmers which are allowed to run after the OS is running.<\/p>\n<p>There are seven runlevels which are numbered from 0 to 6.<\/p>\n<p>The following table describes the function of each runlevel:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Runlevel<\/strong><\/td>\n<td><strong>Function<\/strong><\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>It shuts down the system.<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>It operates in single user mode.<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>It operates in multiuser mode without networking.<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>It operates in multiuser mode with networking.<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>It is defined by the user.<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>A multiuser with networking and X windows.<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>It reboots or restarts the system.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The runlevel 0 \u201cshuts down the system\u201d.<\/p>\n<p>Runlevel 1 is a single-user mode in which the non-root logins are not permitted, the networking is not available, but the configuration files and passwords can be changed.<\/p>\n<p>There are no networking daemons at runlevel 2, and multiple users are not supported.<\/p>\n<p>Runlevel 3 allows networking and command line interface.<\/p>\n<p>We are able to construct the new runlevels as of run level 4.<\/p>\n<p>The runlevel 5 is used in maximum Linux systems.<\/p>\n<p>The runlevel 6 \u201creboots or restarts the system\u201d.<\/p>\n<p>The runlevel program can be executed from the following directories:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">Runlevel <span class=\"nu0\">0<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc0.d<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nRunlevel <span class=\"nu0\">1<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc1.d<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nRunlevel <span class=\"nu0\">2<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc2.d<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nRunlevel <span class=\"nu0\">3<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc3.d<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nRunlevel <span class=\"nu0\">4<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc4.d<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nRunlevel <span class=\"nu0\">5<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc5.d<span class=\"sy0\">\/<\/span><br \/>\n<br \/>\nRunlevel <span class=\"nu0\">6<\/span> \u2013 <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>rc.d<span class=\"sy0\">\/<\/span>rc6.d<span class=\"sy0\">\/<\/span><\/div><\/div>\n<p>We can check all programs under \/etc\/rc.d\/rc*.d\/ folder. For example, if we want to see the runlevel in four files, we can check the \u201cls \/etc\/rc4.d\/\u201d directory.<\/p>\n<p>If the program name starts with \u201cS\u201d, it is used at the start time. If the program name starts with \u201cK\u201d, it is used at the time of shutdown.<\/p>\n<p>Here are the ways to change the runlevel:<\/p>\n<p>&#8211; init command<\/p>\n<p>&#8211; telinit command<\/p>\n<p>The default runlevel in the \/etc\/inittab file can be modified by the user. Here is the command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"re1\">$init<\/span> <span class=\"sy0\">&lt;<\/span>runlevel_value<span class=\"sy0\">&gt;<\/span><br \/>\n<br \/>\n$ telinit <span class=\"sy0\">&lt;<\/span>runlevel_value<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>To interact with\u00a0init, the \/dev\/initctl\u00a0control channel should be used rather than\u00a0SIGPWR\u00a0and\u00a0\/etc\/powerstatus.<\/p>\n<p>The <strong>\/<\/strong>sbin\/telinit\u00a0is linked up with\u00a0\/sbin\/init.\u00a0Telinit takes up an argument and send signals to \u00a0init\u00a0to do the required action.<\/p>\n<p>Here is the table:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Argument<\/strong><\/td>\n<td><strong>Function<\/strong><\/td>\n<\/tr>\n<tr>\n<td>0,1,2,3,4,5,6<\/td>\n<td>Switch to specified runlevel<\/td>\n<\/tr>\n<tr>\n<td>a, b, c<\/td>\n<td>Processes only the file entries from\u00a0<strong>\/<\/strong>etc\/inittab\u00a0having runlevel a,b, c<\/td>\n<\/tr>\n<tr>\n<td>q or q<\/td>\n<td>Re-examines the <strong>\/<\/strong>etc\/inittab file<\/td>\n<\/tr>\n<tr>\n<td>s or s<\/td>\n<td>Switches to a single user mode<\/td>\n<\/tr>\n<tr>\n<td>u or u<\/td>\n<td>Init re-executes itself<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>If we want to find out our current system runlevel, we can use the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">who<\/span> <span class=\"re5\">-r<\/span><\/div><\/div>\n<p>To see all help related to Linux \u201crunlevel\u201d command, use the following commands:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\">$ runlevel \u2013h<br \/>\n<br \/>\nOr<br \/>\n<br \/>\n$ runlevel \u2013<span class=\"kw3\">help<\/span><br \/>\n<br \/>\nOr<br \/>\n<br \/>\n$ <span class=\"kw2\">man<\/span> runlevel<\/div><\/div>\n<p>These are the six processes which happen in background when the user presses the power button of the system.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>We learned the Linux boot process in details. We also learned the booting component and run levels which are very important for system administrator, developer, and also for the users of the Linux operating system. There are many detailed steps in each area, but we tried to cover the overall process in this short article.<\/p>","protected":false},"excerpt":{"rendered":"<p>Practical guide on the Linux boot process and the booting component and run levels for system administrator, developer, and users of the Linux operating system.<\/p>","protected":false},"author":111,"featured_media":19725,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-19723","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=19723"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/19723\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/19725"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=19723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=19723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=19723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}