Selasa, 27 Agustus 2013

Xathrya Sabertooth

Xathrya Sabertooth


Linux Boot Process – Init

Posted: 26 Aug 2013 04:24 AM PDT

In Unix-based OS, init (short for initialization) is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shutdown. It performs many things and also served as the ‘mother’ of processes.

Once init starts, “swapper” part on kernel goes into the sleep state, into an idle loop and rest of the bootup process is taken up by init process. The old init systems such as SysV-style and BSD-style is based on a single process which load the application serially using script. A newer system such as system and upstart can init system in parallel to speed up the process.

SysV-style

System V init is one of init system used by major Linux distribution. SysV init examines the /etc/inittab file for an :initdefault: entry, which defines any default runlevel. If there is no default runlevel, then init dumps the user to a system console for manual entry of a runlevel.

Runlevels

States in which system is running at. It describe certain states of a machine, characterized by the processes run. There are generally eight runlevels, three of which are standard:

  • Runlevel 0 : Halt
  • Runlevel 1 : Single user mode (aka. S or s)
  • Runlevel 6 : Reboot

Aside from these, every Unix and Unix-like system treats runlevels a little differently. The commond denominator, the /etc/inittab file, defines what each runlevel does in a given system. For example, there are runlevels such as:

  • multiuser mode
  • multiuser mode with networking support
  • GUI mode

BSD-Style

BSD init runs the initialization shell script located in /etc/rc, then launches getty on text-based terminals or a windowing system such as X on graphical terminals under the control of /etc/ttys. There are no runlevels; the /etc/rc file determines what programs are run by init. The advantage of this system is that it is simple and easy to edit manually. However, new software added to the system may require changes to existing files that risk producing an unbootable system. To mitigate against this, BSD variants have long supported a site-specific /etc/rc.local file that is run in a sub-shell near the end of the boot sequence.

Unlike System V’s script ordering, which is derived from the filename of each script, this system uses explicit dependency tags placed within each script. The order in which scripts are executed is determined by the rcorder script based on the requirements stated in these tags.

Slackware use this.

systemd

System management daemon designed exclusively for the Linux kernel. Like init, systemd is a daemon that manages other daemons.

Upstart

Event-based replacement for traditional init daemon.

Other

These are alternatives used to replace Sys-V and BSD-style init:

  1. BootScripts
  2. busybox-init
  3. DEMONS
  4. eINIT
  5. Initng
  6. launchd
  7. Mudur
  8. runit
  9. s6
  10. Service Management Facility
  11. SystemStarter

Linux Boot Process – Kernel

Posted: 26 Aug 2013 03:57 AM PDT

In order for a computer to successfully boot into device we know, a computer should pass some process which we refer as boot process. The BIOS, operating system, and harware components must all be working properly. Failure of any of these three elemens will likely result in a failed boot sequence.

After a boot loader does it jobs (load the kernel) it will terminate itself and the control will be passed to the kernel.

When a Linux kernel is loaded and ran, it is actually running two process for completely load kernel to memory. First one is bootstrapping, and second one is the process in the kernel itself.

In earlier phase kernel will use a bootstrap which is assembly code added to the image. When bzImge is loaded , the code of bootstrap starts executing. The tasks of bootstrap are,

  1. Forcing cpu to go into protected mode. In protected mode we have 4 GB of virtual address space or virtual addressing enabled.
  2. Enabling the MMU (Memory Management Unit) . MMU has got address translation ability , mapping between virtual addresses and physical addresses. CPU contains MMU instruction set.
  3. Decompressing the linux kernel. You can see "Decompressing Linux…." Messages on console at this point.
  4. Calling "start_kernel" function after that. start_kernel is similar to main function. kernel image starts running and initializes all the devices , schedulers, console etc. . You can see lot of text flying on the screen related to this. kernel boots up from here.

When bootstrapping done, the kernel take the process. Kernel does:

  1. Kernel initialize CPU and performs the "Bogo MIPS" calculation. Though BIOS has already intialized CPU but kernel does not depend upon BIOS initialization. It will re-initialize the CPU again. It will create one structure and stores all the CPU details in it. After that it performs "Bogo MIPS"calculation. Using "Bogo MIPS" calculation kernel estimates the cpu speed. At bootup time, you can see the message " Bogo MIPS is ….." .
  2. Kernel re-initializes parallel ports, serial ports and all the on-board controllers like USB, IDE, SCSI, Serial, parallel, timers, RTC etc. These startup drivers are also called BSP drivers or Board Support Drivers.
  3. Interrupts will be enabled. All the data structures required to hold the interrupts including interrupt descriptor table will be setup , i.e. which device is using which interrupt, IRQ details will be filled.

  4. File system required to read from this disk, /boot , /root , /etc , /home etc. is initialized. File system must be loaded now so that can now start using disk.

  5. After this loader will be started. Loader starts a process that is registered in the PCB with PID '0' . Name of this process is swapper.

  6. "swapper" will start a thread called "init" thread. "init" is a kernel thread. "init" kernel thread will look into /bin and look for a program whose name is "init". This kernel thread is told for where to look for init process via boot parameter in bootloader configuration file. If kernel thread doesn't find init there , it becomes a reason for kernel panic and the booting stops there. This may also happen if file system is not initialized . "init" thread looks into /bin and starts executing init process. init's parent is "init" thread. /bin/init is registered as PID 1 and this is the first user space process.

Kernel has loaded, but the booting process has not stopped yet.

Linux Boot Process – Boot Loader

Posted: 26 Aug 2013 03:40 AM PDT

In order for a computer to successfully boot into device we know, a computer should pass some process which we refer as boot process. The BIOS, operating system, and harware components must all be working properly. Failure of any of these three elemens will likely result in a failed boot sequence.

The first sector of a boot device is called as sector '0′ or the Master Boot Record (MBR) . BIOS can read only sector '0', it can’t read any other sector. The size of the MBR is only 512 bytes. It has three components: primary boot loader info in first 446 bytes, partition table in next 64 bytes, MBR validation check in last 2 bytes.

To load Operating System, a special program called boot loader written here. Boot loader even helps us to boot more than one operating systems on the machine (called chaining).

The infamous boot loaders for Linux are GRUB and LILO. GRUB (Grand Unified Boot loader) is used by default on majority of Linux distributions. GRUB is capable of booting DOS, Windows, Linux, and BSD operating system. The LILO (Linux Loader) is an old boot loader, used by several distribution.

When BIOS finished initialized the system, it will jump to Master Boot Record and loads the boot loader from there.

Boot loader does:

  1. Bring the kernel (and all the kernel needs to bootstrap) into memory
  2. Provide kernel with the information it needs to work correctly
  3. Switch to an environment that the kernel will like
  4. Transfer control to the kernel.

Boot loaders can be divided into some categorizes by the design: single stage boot loader, two stage boot loader, and mixed stage boot loader.

A single stage boot loader is a boot loader which consists of a single file that is loaded entirely by the BIOS. This image performs the steps described above to start the kernel. However, on x86 the boot loader is limited to the 512 bytes.

A two stage boot loader actually consists of two boot loaders after each other. The first being small which then load the seconf one. The second one can then contain all the code needed for loading kernel. GRUB uses two.

Mixed boot loader is a boot loader similar to two stage boot loader. it splits the bootloader in two parts, where the first half (512 bytes) can load the rest. This can be achieved by inserting a ’512-bytes’ break in the ASM code, making sure the rest of the loader is put after the bootsector.

In Linux, after boot loader is loaded into memory it looks into /boot directory and loads the kernel image. Note here, that it is boot loader that expects all the files and kernel image needed for booting under /boot directory. This is the reason why kernel image and all boot related files are kept under /boot directory.

Once boot loader loads kernel image to memory , the control is passed to kernel image .

Tidak ada komentar:

Posting Komentar