The Linux boot process January 31, 2011Posted by Tournas Dimitrios in Linux.
This article will outline the main steps that are essential for booting a Linux box . These steps must be well understood , as they will be the foundation to do maintenance tasks or to troubleshoot a non-booting Linux machine . From the time that the power is switched on , until users are able to log in to a fully functioning machine , the system passes through four distinct stages of initialization :
- BIOS : The minimal operating system which is located in the ROM of the system’s motherboard
- Bootloader : This minimal application (GRUB) which is located on the disk’s MBR , used to load and pass control to the Linux kernel .
- Kernel : Firstly it initializes device drivers , starts the first process (init) and lastly during the operation of the computer act’s as the control center of the computer .
- /sbin/init : This process performs most of the hard work to initialize the machine .
See the picture below to get a 20000 meters high view of the process .
First step : The BIOS performs an integrity check of the system , ensuring that all core components (CPU ,Hard discs , Basic Input / Output System etc…) are ” in-place ” and ready to get started . The next step is to locate the appropriate boot device . Usually it searches in a ” sequential order ” , first looking for a bootable floppy , and if not present “flips ” to the next device (ie a bootable CD-ROM) and finally looking for a bootable hard disk . The order of the sequential search is usually configurable through the BIOS menu .Finaly the BIOS loads the first part of the boot loader and pass the control to this application .
Second step : The bootloaders on Linux have three responsibilities :
- Acting as an command line interface to pass arguments to the kernel at booting .
- Loading an appropriate initial ram disk (initrd)
- Loading and passing control to the appropriate Linux kernel
Bootloaders are usually designed in two stages , with the first stage small enough to reside in a Master Boot Record (464 Bytes ) , and the second part on the hard disk .
The Kernel on Linux is usually created as a modular component and drivers are loaded as module – elements when needed . This choice naturally leads to a problem . From where does the kernel load its kernel modules . if they are needed in the boot process before the filesystem is created ? (mounted) . The answer is an initial ramdisk , which is a filesystem image which contains the necessary modules . The boot loader loads the ramdisk image into memory for the kernel , from where the kernel can trivially mount the filesystem and load any necessary modules .
Third step : At this point the kernel with its modules (initrd) are loaded in RAM . Essentially a system administrator can view the kernel as performing these three steps :
- Replace all BIOS device drivers with Linux device drivers
- Mount the root partiton read – only .
- Start the first process (init ) .
And that’s it . The kernel does remarkably little to initialize the system , relying on the first process (init ) to do all of the hard work .
Fourth step : /sbin/init process receives a system that has only mounted the root partition read – only and delivers all hard disk’s checked for errors , mounted r/w and full featured ready for operation . These are the key points that are executed in the exact order :
- /sbin/init reads the /etc/inittab configuration file to decide what runlevel it should start .
- /sbin/init runs the bash script /etc/rc.sysinit (softlink of /etc/rc.d/rc.sysinit)
- sysinit reads /etc/fstab to decide which partitions must be mounted
- sysinit receive a root filesystem mounted r/o and delivers a all partitions checked – mounted r/w .
- depending on configuration of the inittab file , the scripts in a specific directory will be executed .
vs for runlevel 3 –> /etc/rc.d/rc3 ,
for runlevel 5 –>/etc/rc.d/rc5 etc…..
- As init is the mother of all processes it is now ready to act accordingly . It delivers a log – in to the user .