Linux Booting Procedure



Linux Booting procedure

The stages involved in Linux Booting Process are:
1. BIOS
2. Boot Loader
    - MBR
    - GRUB
3. Kernel
4. Init
5. Runlevel scripts
6. User Interface

STEP 1. BIOS
  • This is the first thing which loads once you power on your machine.
  • When you press the power button of the machine, CPU looks out into ROM for further instruction.
  • The ROM contains JUMP function in the form of instruction which tells the CPU to bring up the BIOS
  • BIOS determine all the list of bootable devices available in the system.
  • Prompts to select bootable device which can be Hard Disk, CD/DVD-ROM, Floppy Drive, USB Flash Memory Stick Etc..
  • Operating System tries to boot from Hard Disk where the MBR contains primary boot loader.

STEP 2. Boot Loader 
To be very brief this phase includes loading of the boot loader (MBR and GRUB/LILO) into memory to bring up the kernel.

MBR (Master Boot Record)
  • It is the first sector of the Hard Disk with a size of 512 bytes.
  • The first 434 - 446 bytes are the primary boot loader, 64 bytes for partition table and 6 bytes for MBR validation timestamp.
NOTE: Now MBR directly cannot load the kernel as it is unaware of the file system concept and requires a boot loader with file system driver for each supported file systems, so that they can be understood and accessed by the boot loader itself.

To overcome this situation GRUB is used with the details of the file system in
/boot/grub.conf and file system drivers

GRUB (Grand Unified Boot loader)

this loads the kernel in 3 stages

GRUB stage 1: 
  • The primary boot loader takes up less than 512 bytes of disk space in the MBR - too small a space to contain the instructions necessary to load a complex operating system. 
  • Instead the primary boot loader performs the function of loading either the stage 1.5 or stage 2 boot loader.
GRUB Stage 1.5: 
  • Stage 1 can load the stage 2 directly, but it is normally set up to load the stage 1.5. 
  • This can happen when the /boot partition is situated beyond the 1024 cylinder head of the hard drive. 
  • GRUB Stage 1.5 is located in the first 30 KB of Hard Disk immediately after MBR and before the first partition.
  • This space is utilized to store file system drivers and modules.
  • This enabled stage 1.5 to load stage 2 to load from any known location on the file system i.e. /boot/grub

GRUB Stage 2:
  • This is responsible for loading kernel from /boot/grub/grub.conf and any other modules needed
  • Loads a GUI interface i.e. splash image located at /grub/splash.xpm.gz with list of available kernels where you can manually select the kernel or else after the default timeout value the selected kernel will boot
The original file is /etc/grub.conf of which you can observe a symlink file at /boot/grub/grub.conf

STEP 3. Kernel
This can be considered the heart of operating system responsible for handling all system processes.

Kernel is loaded in the following stages:
  1. Kernel as soon as it is loaded configures hardware and memory allocated to the system.
  2. Next it uncompresses the initrd image (compressed using zlib into  zImage or bzImage formats) and mounts it and loads all the necessary drivers.
  3. Loading and unloading of kernel modules is done with the help of programs like insmod, and rmmod present in the initrd image.
  4. Looks out for hard disk types be it a LVM or RAID.
  5. Unmounts initrd image and frees up all the memory occupied by the disk image.
  6. Then kernel mounts the root partition as specified in grub.conf as read-only.
  7. Next it runs the init process
STEP 4. Init Process
  • Executes the system to boot into the run level as specified in /etc/inittab

You can check current runlevel details of your system using below command on the terminal

# who -r

         
run-level 3  Jan 28 23:29                   last=S
  • Next as per the fstab entry file system's integrity is checked and root partition is re-mounted as read-write (earlier it was mounted as read-only).

STEP 5. Runlevel scripts
A no. of runlevel scripts are defined inside /etc/rc.d/rcx.d
  • Based on the selected runlevel, the init process then executes startup scripts located in subdirectories of the /etc/rc.d directory.
  • Scripts used for runlevels 0 to 6 are located in subdirectories /etc/rc.d/rc0.d through /etc/rc.d/rc6.d, respectively.
  • For more details on scripts inside /etc/rc.d follow the below link
    What are the s and k scripts in the etc rcx.d directories
  • Lastly, init runs whatever it finds in /etc/rc.d/rc.local (regardless of run level). rc.local is rather special in that it is executed every time that you change run levels.
NOTE: rc.local is not used in all the distros as for example Debian.

Next if everything goes fine you should be able to see the Login Screen on your system.

Linux Interview Questions and Answers

1.Create user with specified Home directory ..?

 Ans:      useradd -d "Directory Path" username
               Ex: useradd -d /var/aravi aravi

2. Create new user, user should change password by first login..?

 Ans:      useradd <user name>
               Ex: useradd aravi1; chage -d 0 aravi1; passwd aravi1

3. How to ditermine cronjob ran status..?

  Ans:

<After the Cron Script> Add the $? > <Log File>

Find the code below and its status

0  -- No problems.
1  -- An attempt has been made to start cron but there is already a /var/run/cron.pid file. If there really is no other cron daemon running (this does not include invokations of mcron) then you should remove this file before attempting to run cron.
2  -- In parsing a guile configuration file, a job command has been seen but the second argument is neither a procedure, list or string. This argument is the job's action, and needs to be specified in one of these forms.
3  -- In parsing a guile configuration file, a job command has been seen but the first argument is neither a procedure, list or string. This argument is the job's next-time specification, and needs to be specified in one of these forms.
4  -- An attempt to run cron has been made by a user who does not have permission to access the crontabs in /var/cron/tabs. These files should be readable only by root, and the cron daemon must be run as root.
5  -- An attempt to run mcron has been made, but there are no jobs to schedule!
6  -- The system administrator has blocked this user from using crontab with the files /var/cron/allow and /var/cron/deny.
7  -- Crontab has been run with more than one of the arguments -l, -r, -e. These are mutually exclusive options.
8  -- Crontab has been run with the -u option by a user other than root. Only root is allowed to use this option.
9  -- An invalid vixie-style time specification has been supplied.
10 -- An invalid vixie-style job specification has been supplied.
11 -- A bad line has been seen in /etc/crontab.
12 -- The last component of the name of the program was not one of mcron, cron, crond or crontab.
13 -- Either the ~/.cron directory does not exist, or there is a problem reading the files there.
15 -- Crontab has been run without any arguments at all. There is no default behaviour in this case.
16 -- Cron has been run by a user other than root.

4. What is zombie process in Linux ..?

Ans:  Zombie process is a process that has completed execution (via the exit system call) but still has an entry in the process table: it is a process in the "Terminated state".

5. How to find and kill zombie process in Linux ..?

Ans: To find zombie process in Linux use below command

$ ps axo stat,ppid,pid,comm | grep -w Z
$ kill -9 <PID>

6. How to find Linux system calls ..?

Ans: using $ strace command we can find system calls

7. What is the Difference between Hardlink and Softlink in Linux..?

Ans:
Hard Link:
A hardlink isn't a pointer to a file, it's a directory entry (a file) pointing to the same inode. Even if you change the name of the other file, a hardlink still points to the file. If you replace the other file with a new version (by copying it), a hardlink will not point to the new file. You can only have hardlinks within the same filesystem. With hardlinks you don't have concept of the original files and links, all are equal (think of it as a reference to an object). It's a very low level concept.

Soft Link:
A softlink is actually pointing to another path (a file name); it resolves the name of the file each time you access it through the symlink. If you move the file, the symlink will not follow. If you replace the file with another one, keeping the name, the symlink will point to the new file. Symlinks can span filesystems. With symlinks you have very clear distinction between the actual file and symlink, which stores no info beside the path about the file it points to.

8. How can I find all the Soft Links in my system ?

Ans. Use this command for the same “find /etc -type l -exec ls -li {} \;”

9. How can I find all the files having Hard Links in my system ?

Ans. Use this command for the same “find / -links +2 -type f -exec ls -li {} \;”

10. How to find whether a file is a softlink ?

Ans. Simply using this command “ls -l” will tell you whether a file is pointing to some other file or not.

11. How to check whether a file have any softlink pointing to it ?

Ans. Till now, I am not aware of any way to do that. If I will find any, I will surely update my post.

12. How can I find out the source file of a hard link ?

Ans. No, you can’t find out the source file of a hard link. Once hard link is created, there is no way to tell which was the first file created.

13. Can I make a Soft link to a Hard link and Vice Versa ?

Ans. Yes, both soft links and hard links acts as normal files of the file system, so you can do both.

14. What is the use of initrd directory..?

Ans. The Linux initial RAM disk (initrd) is a temporary root file system that is mounted during system boot to support the two-state boot process. The initrd contains various executables and drivers that permit the real root file system to be mounted

15. RHEL version comparison..?

Ans.
 
16. What is MYSQL query cache..?

Ans: The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again.


17. What is Difference between Swap and Pagefile ..?

Ans: SWAPFILES operate by swapping entire processes from system memory into the swapfile. This immediately frees up memory for other applications to use.
      PAGING FILES function by moving "pages: of a program from system memory into the paging file. These pages are 4KB in size. The entire program does not get swapped wholesale into the paging file, when next application is requested this paging file not immediately freedup.

18. How to check the MYSQL running processes ..?

Ans: You can run the MySQL command SHOW PROCESSLIST to see what queries are being processed.

19. How to identify which processes are taking more memory..?

Ans: Enter Command "top"
        Press SHIFT+F
        Press n (* N: %MEM       = Memory usage (RES))
        Press ENTER

                OR

use below command to see top 5 processes

$ ps -eo pmem,pcpu,vsize,pid,cmd | sort -k 1 -nr | head -5

19. TCP vs UDP ..?
Ans :

TCP - 
Transmission Control Protocol.
TCP is a connection-oriented protocol.
Use by other protocols HTTP, HTTPs, FTP, SMTP, Telnet.
The speed for TCP is slower than UDP.
TCP header size is 20 bytes
TCP does error checking
Acknowledgement segments

UDP - 
User Datagram Protocol or Universal Datagram Protocol
UDP is a connectionless protocol.
Use by other protocols DNS, DHCP, TFTP, SNMP, RIP, VOIP.
UDP is faster because there is no error-checking for packets.
UDP Header size is 8 bytes.
UDP does error checking, but no recovery options.
No Acknowledgment


.  what is the difference between bash & ksh..?

 Ans: 

Y Feature can be done using this shell.
N Feature is not present in the shell.
F Feature can only be done by using the shells function mechanism.
L The readline library must be linked into the shell to enable this Feature  
      
Description sh csh ksh bash tcsh zsh rc es
Job control N Y Y Y Y Y N N
Aliases N Y Y Y Y Y N N
Shell functions Y(1) N Y Y N Y Y Y
Sensible Input/Output redirection  Y N Y Y N Y Y Y
Directory stack N Y Y Y Y Y F F
Command history N Y Y Y Y Y L L
Command line editing N N Y Y Y Y L L
Vi Command line editing N N Y Y Y(3) Y L L
Emacs Command line editing N N Y Y Y Y L L
Rebindable Command line editing N N N Y Y Y L L
User name look up N Y Y Y Y Y L L
Login/Logout watching N N N N Y Y F F
Filename completion N Y(1) Y Y Y Y L L
Username completion N Y(2) Y Y Y Y L L
Hostname completion N Y(2) Y Y Y Y L L
History completion N N N Y Y Y L L
Fully programmable Completion N N N N Y Y N N
Mh Mailbox completion N N N N(4) N(6) N(6) N N
Co Processes N N Y N N Y N N
Builtin artithmetic evaluation N Y Y Y Y Y N N
Can follow symbolic links invisibly N N Y Y Y Y N N
Periodic command execution N N N N Y Y N N
Custom Prompt (easily) N N Y Y Y Y Y Y
Sun Keyboard Hack N N N N N Y N N
Spelling Correction N N N N Y Y N N
Process Substitution N N N Y(2) N Y Y Y
Freely Available N N N(5) Y Y Y Y Y
Checks Mailbox N Y Y Y Y Y F F
Tty Sanity Checking N N N N Y Y N N
Can cope with large argument lists Y N Y Y Y Y Y Y
Has non-interactive startup file N Y Y(7) Y(7) Y Y N N
Has non-login startup file N Y Y(7) Y Y Y N N
Can avoid user startup files N Y N Y N Y Y Y
Can specify startup file N N Y Y N N N N
Low level command redefinition N N N N N N N Y
Has anonymous functions N N N N N N Y Y
List Variables N Y Y N Y Y Y Y
Full signal trap handling Y N Y Y N Y Y Y
File no clobber ability N Y Y Y Y Y N F
Local variables N N Y Y N Y Y Y
Lexically scoped variables N N N N N N N Y
Exceptions N N N N N N N Y

Linux Introduction | RHCSA Tutorial | Tech Arkit





     UNIX is the first Operating system in the world, developed by Kem Thompson and Dennis Ritchie in 1969 at Bell Lab by AT&T Company

Distributions: Overview of various Linux distributions (Ubuntu, Fedora, CentOS, Debian, etc.) that build upon the Linux kernel.
  •             IBM    :           AIX
  •             SGI     :           IRIX
  •             Sun     :           Solaris
  • Free software foundation organization, they start a project by name GNU. The main aim of this project is to develop such an operating system that can run on any platform. 
  • In 1991, a student Linuz Torvalds developed a kernel named Linux’s kernel plus GNU application called Linux operating system.
  • Linux is an open source technology.
  • Different companies that provide Linux in Market are Redhat, SuSe, Scientific, Centos, and Knoppix etc.

Features:

Ø  Linux is the fastest Operating system in the world. It runs 2 to 3 times fast than windows OS.
Ø  Linux is the much secured OS because there is no any problem of virus.
Ø  Linux file format is text format and windows file format is binary format.
Ø  Linux is a very reliable OS because the kernel of Linux is very stable as compare to windows kernel not crashed easily.
Ø  Kernel of Linux is very small in size it can be stored in floppy.
Ø  Linux uses the x-Window system which is advanced network windowing system. Using this system we can display output of any workstation monitor attached in the network.

Advantages:

Ø  Virus Proof
Ø  Crash Proof
Ø  Economical
Ø  Multiuser, Multi-Tasking and Multiprocessing capacity

Login Modes:


Two modes:  

1. Text mode (CLI)   - All the commands can be executed   
2. Graphical Mode (GUI)

Open Source

       The idea behind Open Source software is rather simple: when programmers can read, distribute and change code, the code will mature. People can adapt it, fix it, debug it, and they can do it at a speed that dwarfs the performance of software developers at conventional companies. This software will be more flexible and of a better quality than software that has been developed using the conventional channels, because more people have tested it in more different conditions than the closed software developer ever can.

        The Open Source initiative started to make this clear to the commercial world, and very slowly, commercial vendors are starting to see the point. While lots of academics and technical people have already been convinced for 20 years now that this is the way to go, commercial vendors needed applications like the Internet to make them realize they can profit from Open Source. Now Linux has grown past the stage where it was almost exclusively an academic system, useful only to a handful of people with a technical background. Now Linux provides more than the operating system: there is an entire infrastructure supporting the chain of effort of creating an operating system, of making and testing programs for it, of bringing everything to the users, of supplying maintenance, updates and support and customizations, etcetera. Today, Linux is ready to accept the challenge of a fast-changing world.


 Please write your valuable comments...