{"id":13782,"date":"2019-04-06T03:26:42","date_gmt":"2019-04-06T03:26:42","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13782"},"modified":"2019-04-06T03:26:42","modified_gmt":"2019-04-06T03:26:42","slug":"a-basic-guide-to-linux-boot-process","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/a-basic-guide-to-linux-boot-process\/","title":{"rendered":"A Basic Guide to Linux Boot Process"},"content":{"rendered":"<p>As promised in our earlier post, in this post we are going to review boot process in Linux Operating System. How Operating system passes through different stage of booting states. This article is written for those readers who has just steps in Linux world. Understanding how Linux boots up is very important in terms of effectively troubleshooting in case of system failure. When a system switched on and after few moment we get a login prompt. Have we try to find out what all stage of booting sequence has crossed and what happened behind the scene during system boots up.<\/p>\n<div id=\"attachment_4429\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/03\/Linux-Boot-Process.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4429\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/03\/Linux-Boot-Process.png\" alt=\"Linux Boot Process\" width=\"435\" height=\"321\" aria-describedby=\"caption-attachment-4429\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-4429\" class=\"wp-caption-text\">Linux Boot Loader Process<\/p>\n<\/div>\n<h3>Power on<\/h3>\n<ol>\n<li><strong>BIOS<\/strong>\u00a0(<strong>Basic Input Output System<\/strong>) is a software program comes pre-built in a motherboard chipset.<\/li>\n<li><strong>BIOS<\/strong>\u00a0loads and scans for devices such as\u00a0<strong>Hard Disk<\/strong>,\u00a0<strong>CD-ROM<\/strong>,\u00a0<strong>RAM<\/strong>, etc.<\/li>\n<li><strong>BIOS<\/strong>\u00a0searches for\u00a0<strong>MBR<\/strong>\u00a0(<strong>Master Boot Record<\/strong>: 1st sector) of the primary hard drive, it scans for 1st stage loader (In our case boot loader is (<strong>GRUB LILO<\/strong>) and hands over the responsibility to\u00a0<strong>MBR<\/strong>.<\/li>\n<li>Boot\u00a0<strong>PROM<\/strong>\/<strong>FLASH<\/strong>\/<strong>BIOS<\/strong>\u00a0is proficient of loading the\u00a0<strong>MBR<\/strong>\u00a0into\u00a0<strong>RAM<\/strong>\u00a0and executing it.<\/li>\n<\/ol>\n<h3>MBR (Master Boot Record)<\/h3>\n<ul>\n<li><strong>512<\/strong>\u00a0bytes of space \u2013&gt;\u00a0<strong>MBR<\/strong><\/li>\n<li><strong>MBR<\/strong>\u00a0contains the information of loader of most operating system e.g\u00a0<strong>UNIX<\/strong>,\u00a0<strong>Linux<\/strong>\u00a0and\u00a0<strong>WINDOWS<\/strong><\/li>\n<li><strong>MBR<\/strong>\u00a0holds the small binary information of 1st stage of loader<\/li>\n<li>MBR consist physical sector of the first disk drive (i.e\u00a0<strong>512 bytes<\/strong>) and it\u2019s not part of any partition.<\/li>\n<li>Placed on the prime disk drive, in the prime sector of the first cylinder of track is 0 and head is 0 (this whole path is generally booked for boot programs)<\/li>\n<li>MBR involve a mini executable programs and a table specify the primary partitions.<\/li>\n<\/ul>\n<pre>Boot Code (GRUB) 446 bytes\r\npartition 1: 16 bytes\r\npartition 2: 16 bytes\r\npartition 3: 16 bytes\r\npartition 4: 16 bytes\r\nmagic Number: 2 bytes<\/pre>\n<ol>\n<li>MBR also document which primary partition is\u00a0<strong>ACTIVE<\/strong>.<\/li>\n<li>The\u00a0<strong>BIOS<\/strong>\u00a0surrender rights to the first stage boot loader, which then scans partition table and finds second stage boot loader on the partition configured as bootable.<\/li>\n<\/ol>\n<h3>Boot Loader<\/h3>\n<ol>\n<li>The boot loader termed from 1st stage loader and loads itself into\u00a0<strong>RAM<\/strong>. All this go on in milliseconds.<\/li>\n<li>The default stage 2 boot loader is a\u00a0<strong>GRUB<\/strong>\u00a0(<strong>Grand Unified Boot Loader<\/strong>) or\u00a0<strong>LILO<\/strong>\u00a0(Linux Loader)<\/li>\n<li>Once\u00a0<strong>GRUB<\/strong>\u00a0is loaded into\u00a0<strong>RAM<\/strong>, then it\u2019s search for the location of\u00a0<strong>Kernel<\/strong>.<\/li>\n<li><strong>GRUB<\/strong>\u00a0will scrutinize the map file to find the kernel image, that is located under (<strong>\/boot<\/strong>) and load it.<\/li>\n<li>GRUB loads the kernel (<strong>vmlinuz-version<\/strong>) from\u00a0<strong>\/boot<\/strong>\u00a0partition<\/li>\n<\/ol>\n<h4>Trivia 1<\/h4>\n<p>GRUB organize\u00a0<strong>RAMDISK<\/strong>\u00a0for initrd \u2014&gt; (<strong>RAMDISK<\/strong>\u00a0is reserved space from\u00a0<strong>RAM<\/strong>). In addition, it drives\u00a0<strong>initrd<\/strong>\u00a0into\u00a0<strong>RAM<\/strong>\u00a0to ready the kernel for loading itself into memory and depended modules so that it can leave the system to \u201c<strong>init<\/strong>\u201d process<\/p>\n<p>In, Linux most of the drivers are pre-built as modules, these would be initial ram drive (<strong>initrd.img<\/strong>) where it can keep all the information of additional modules. So, when the kernel boots, it creates\u00a0<strong>ramdrive<\/strong>, loads the\u00a0<strong>initrd.img<\/strong>\u00a0and its depended modules.<\/p>\n<p><strong>GRUB<\/strong>\u00a0reads\u00a0<strong>\/boot\/grub\/grub.conf<\/strong>\u00a0&amp; shows us a clean interface for selecting Operating System<\/p>\n<p>Once Kernel loads its depended modules and then it hand over to \u201c<strong>init<\/strong>\u201d process. The kernel image has a small, unpacked program that un-compresses kernel and runs it.<\/p>\n<h4>Trivia 2<\/h4>\n<p><strong>LILO<\/strong>\u00a0needed to indicate\u00a0<strong>MBR<\/strong>\u00a0in order to locate operating systems on the hard drive. Any modifications done to\u00a0<strong>\/etc\/lilo.conf<\/strong>, that must be updated in\u00a0<strong>MBR<\/strong>, but in\u00a0<strong>GRUB<\/strong>\u2018s case no need to update, it reads directly from the file\u00a0<strong>\/boot\/grub\/grub.conf<\/strong>.<\/p>\n<p>After making changes in\u00a0<strong>\/etc\/lilo.conf<\/strong>, we\u2019ll have to update the\u00a0<strong>MBR<\/strong>\u00a0manually<\/p>\n<pre># \/sbin\/lilo -v<\/pre>\n<h4>Trivia 3<\/h4>\n<p>The\u00a0<strong>GRUB<\/strong>\u00a0second stage loader resides within the\u00a0<strong>MBR<\/strong>\u00a0and within\u00a0<strong>\/boot<\/strong>\u00a0partition. Once\u00a0<strong>GRUB<\/strong>\u00a0is loaded into memory it becomes 2nd stage loader.<\/p>\n<h4>Trivia 4<\/h4>\n<p>The\u00a0<strong>\/initrd<\/strong>\u00a0directory should not be removed it is a temporary place holder for kernel to have quick access to the modules that it needs to start the system modules include device drivers.<\/p>\n<h3>Kernel initialization highlights include:<\/h3>\n<ol>\n<li>initialize\u00a0<strong>CPU<\/strong>\u00a0components, eg,\u00a0<strong>MMU<\/strong><\/li>\n<li>initialize the scheduler (<strong>PID<\/strong>\u00a00)<\/li>\n<li>mount the root filesystem in rw mode<\/li>\n<li>fork off the init process (<strong>PID<\/strong>\u00a01)<\/li>\n<\/ol>\n<p>In essence, kernel initialization does two things:<\/p>\n<ol>\n<li>Start the core system of shared resource managers (<strong>RAM<\/strong>, processor and mass storage).<\/li>\n<li>Starts a single process,\u00a0<strong>\/sbin\/init<\/strong>.<\/li>\n<\/ol>\n<p>Init process\u00a0<strong>(sbin\/init<\/strong>) is the very fist process which loads all the various daemons and mounts all the partitions which are listed under\u00a0<strong>\/etc\/fstab.<\/strong><\/p>\n<h3>About \/etc\/fstab<\/h3>\n<ol>\n<li>The\u00a0<strong>\/sbin\/init<\/strong>\u00a0reads\u00a0<strong>\/etc\/inittab<\/strong>\u00a0file<\/li>\n<li>Set default runlevel ( the\u00a0<strong>telinit<\/strong>\u00a0command allows administrators to tell the\u00a0<strong>init<\/strong>\u00a0process to change its current runlevel)<\/li>\n<li>Calls\u00a0<strong>\/etc\/rc.d\/rc.sysinit<\/strong>\u00a0and\u00a0<strong>\/etc\/rc.d\/rc x<\/strong>\u00a0(where\u00a0<strong>\u2018x<\/strong>\u2018 is a runlevel)<\/li>\n<li>In\u00a0<strong>\/etc\/rc.d\/rc5.d<\/strong>\u00a0directory files starting with letter\u00a0<strong>K<\/strong>\u00a0\u2013&gt; kill scripts and files starting with letter\u00a0<strong>S<\/strong>\u00a0\u2013&gt; Startup scripts.<\/li>\n<li>Start up the\u00a0<strong>tty<\/strong>\u00a0processes and\u00a0<strong>xdm<\/strong>\u00a0(\u00a0<strong>X<\/strong>\u00a0display manager)<\/li>\n<li>Starts User\u2019s\u00a0<strong>login screen<\/strong><\/li>\n<\/ol>\n<p><a href=\"https:\/\/www.tecmint.com\/linux-boot-process\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised in our earlier post, in this post we are going to review boot process in Linux Operating System. How Operating system passes through different stage of booting states. This article is written for those readers who has just steps in Linux world. Understanding how Linux boots up is very important in terms of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/a-basic-guide-to-linux-boot-process\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;A Basic Guide to Linux Boot Process&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13782","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13782"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13782\/revisions"}],"predecessor-version":[{"id":13783,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13782\/revisions\/13783"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}