Sunday, October 11, 2015

Pulling up oneself by one's own bootstraps!!!

This has been explained by many on their respective blog posts around the world...so eh...why not another one!!

I went through some Wikipedia entries as well to understand how the world wide community explains this stuff...and i got some pretty new buzz words to write here...the Hen and the egg problem for example...explains initramfs quite straight forward manner.

So lets start and push your power button.

This probably causes the x86 microprocessor to reset, and hence loads it's program counter (PC)
with a fixed address near the top of the one-megabyte address space assignable in real mode.

Did I write real mode...Yes!! to all those undergraduates who have read that there are two or modes supported by the x86 processors Real, protected, etc....the only code that actually uses Real Mode 16 bit addressing scheme (No paging) etc...is the Boot-loader. Yes!! the boot-loader is the place in today's era that uses 16 bit addressable memory and instructions ( o_O again!!)...this is kept for backward compatibility.

A full power-on self-test (POST) is run (although you can stop POST from running evertime you boot -cold boot by pressing the 3 finger salute ctrl+alt+del,This saves the time otherwise used to detect and test all memory. ).  The POST checks, identifies, and initializes system devices such as the CPU, RAM, interrupt and DMA controllers and other parts of the chipset, video display card, keyboard, hard disk drive, optical disc drive and other basic hardware.

On a more detailed Note:

The BIOS does several things. This is its usual sequence:
Check the CMOS Setup for custom settings
Load the interrupt handlers and device drivers
Initialize registers and power management
Perform the power-on self-test (POST)
Display system settings
Determine which devices are bootable

Initiate the bootstrap sequence

Interrupt handlers are small pieces of software that act as translators between the hardware components and the operating system. For example, when you press a key on your keyboard, the signal is sent to the keyboard interrupt handler, which tells the CPU what it is and passes it on to the operating system. The device drivers are other pieces of software that identify the base hardware components such as keyboard, mouse, hard drive and floppy drive. Since the BIOS is constantly intercepting signals to and from the hardware, it is usually copied, or shadowed, into RAM to run faster.

Now the BIOS is just going to look at a bootlable device in the list of drives attached, be it Floppy or HD or CD or USB. Then jumps to the first partition at that drive and loads just 1 sector (512 bytes) at again a predetermined location. The 1st sector contains MBR (Master Boot Record ).

The MBR contains assembly code ( Not C code) since at that so very nascent stage of machine, the C run time environment it self is not set. Now the job of the MBR is to load the Bootloader (GRUB in Linux), bootmgr ( In windows).

The boot loader then loads the Kernel and initramfs. After the kernel is loaded, it unpacks the initramfs (initial RAM filesystem), which becomes the initial root filesystem. The kernel then executes /init as the first process. The early userspace starts.

The purpose of the initramfs is to bootstrap the system to the point where it can access the root filesystem (see FHS for details). This means that any modules that are required for devices like IDE, SCSI, SATA, USB/FW (if booting from an external drive) must be loadable from the initramfs if not built into the kernel; once the proper modules are loaded (either explicitly via a program or script, or implicitly via udev), the boot process continues. For this reason, the initramfs only needs to contain the modules necessary to access the root filesystem; it does not need to contain every module one would ever want to use. The majority of modules will be loaded later on by udev, during the init process.

At the final stage of early userspace, the real root is mounted, and then replaces the initial root filesystem. /sbin/init is executed, replacing the /init process. Arch uses systemd as the default init.

After the Display manager comes up then the Login screen pops up and you can then LOGIN!!!

No comments:

Post a Comment