6 Stages of Linux Boot Process (Startup Sequence)

by Ramesh Natarajan on February 7, 2011

Press the power button on your system, and after few moments you see the Linux login prompt.

Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?

The following are the 6 high level stages of a typical Linux boot process.

1. BIOS

  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks
  • Searches, loads, and executes the boot loader program.
  • It looks for boot loader in floppy, cd-rom, or hard drive. You can press a key (typically F12 of F2, but it depends on your system) during the BIOS startup to change the boot sequence.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
  • So, in simple terms BIOS loads and executes the MBR boot loader.

2. MBR

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is less than 512 bytes in size. This has three components 1) primary boot loader info in 1st 446 bytes 2) partition table info in next 64 bytes 3) mbr validation check in last 2 bytes.
  • It contains information about GRUB (or LILO in old systems).
  • So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB

  • GRUB stands for Grand Unified Bootloader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
  • #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/boot/grub/splash.xpm.gz
    hiddenmenu
    title CentOS (2.6.18-194.el5PAE)
              root (hd0,0)
              kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
              initrd /boot/initrd-2.6.18-194.el5PAE.img
  • As you notice from the above info, it contains kernel and initrd image.
  • So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel

  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. Do a ‘ps -ef | grep init’ and check the pid.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware.

5. Init

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels
    • 0 – halt
    • 1 – Single user mode
    • 2 – Multiuser, without NFS
    • 3 – Full multiuser mode
    • 4 – unused
    • 5 – X11
    • 6 – reboot
  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
  • Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
  • If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
  • Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

  • When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
  • Depending on your default init level setting, the system will execute the programs from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/
  • Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
  • Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
  • For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.

There you have it. That is what happens during the Linux boot process.

Share

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 54 comments… read them below or add one }

1 Pushpraj February 7, 2011 at 1:11 am

Excellent……!!! 2011 seems to be rocking for TGS viewers….

2 BalaC February 7, 2011 at 2:53 am

@Ramesh: This is offtopic discussion. Could you write a article on ack. Thanks

3 shezars February 7, 2011 at 4:02 am

you are rock,,, lol
nice,

4 Adam February 7, 2011 at 4:20 am

Great article :)
You could also write few words about grub2 – configuration files for grub doesn’t work in grub2. (Tested in ubuntu)

5 Edward February 7, 2011 at 4:30 am

very very nice,

tanx

6 Ajeya February 7, 2011 at 4:58 am

Hello Ramesh,

It would have been better if if you could have explained more on each topic. Probably each high level boot process would need a separate page.

This doc is good for begineers.

Thanks,
Ajeya Krishna K R

7 Abhijeet February 7, 2011 at 5:02 am

Good Graphics
Great Tutorial

Keep it up

8 sagar February 7, 2011 at 5:36 am

nice piece of information
thanks lot

9 sandeep February 7, 2011 at 6:38 am

Amazingggggggg good job Guys carry on

10 jameslee February 7, 2011 at 6:56 am

Thank u…

11 Kuldeep February 7, 2011 at 8:09 am

very well explained !!!!!!!!
Thanx alot…..

plz explain GRUB in detail…….How to use GRUB command prompt at system startup ??

12 Kyle February 7, 2011 at 11:02 am

These are very helpful. Keep ‘em coming please!

13 Yogesh Upadhyay February 7, 2011 at 1:22 pm

Excellent !!! TGS Rocks…

14 shanil February 7, 2011 at 2:08 pm

thanks alot, just in time to futher clarify things lol..As always, TGS rocks!!!

15 Júlio Hoffimann Mendes February 7, 2011 at 8:15 pm

I learn to much with your blog. Thank you.

Regards,
Júlio.

16 Steeven Paul Y February 7, 2011 at 10:04 pm

I know the terms GRUB, KERNEL,INIT, MBR. But i do not know how they work together. Thanks to Ramesh Natarajan, for his blog and useful posts.

17 Lord February 8, 2011 at 12:42 am

Thank you RAMESH. this was so good…

18 analogtek February 8, 2011 at 1:01 am

The file that most would want is. The menu.list that is in the /boot/grub/ directory on my debian system. I often edit this file for a manual kernel update,time out,boot image change.

19 Suresh.G February 8, 2011 at 2:33 am

Short and Sweet

20 Sameer Ambekar February 8, 2011 at 8:03 am

Really nice document for quick reference to Linux boot process!!!

21 afujita February 8, 2011 at 8:09 pm

Great article, thank you :)

22 Renjith G February 10, 2011 at 1:45 am

Good one. Thanks.

23 Mohan February 11, 2011 at 10:25 am

plz explain about how to configure zimbra mail server and how to migrate sendmail to zimbra

24 Roberto February 11, 2011 at 6:17 pm

An excelent article, I see another great article here.

25 Hem Chander March 1, 2011 at 2:57 pm

This is very helpful I was looking for similar one..thanks

26 Pablo March 7, 2011 at 10:16 am

Great article Ramesh! But is not completely valid for Ubuntu, which use upstart. Nothing on /etc/inittab, for eg.

27 Sameer June 7, 2011 at 7:07 am

Good doc.
Thanks

28 Verbila June 21, 2011 at 5:44 pm

Love this site, your explanations are excellent, and I like how you define terms and acronyms. Sometimes a man page can make my head spin – your site is the antidote to that – thanks!!

29 ethaqer July 4, 2011 at 8:50 pm

the best explanation ever …

thanks TGS

30 robin July 7, 2011 at 1:30 am

How many times did i ask myself how to find out order of linuxs’ start ?
when this time i saw your blog via TSG, i see thoroughly.

thanks a million

Best Regards
Robin Guo

31 Senthilkumar July 29, 2011 at 12:38 am

Awesome !! For beginners helped a lot..

32 D VIjay August 11, 2011 at 5:48 am

Excellent, in detail and simple. Thanks very much

33 karthick September 4, 2011 at 2:14 am

Actaully i have failed in my first interview for not answering the above question,but after reading the above answer.i ensure i will get success.its really gud explanation,especially beginners lyk me.Thanks a lot

34 dulanja September 19, 2011 at 1:11 am

great article! very useful! thanks a lot.

35 R.YADAV September 30, 2011 at 2:52 am

really…….my total confuse remove after read this article.Thank you………….

36 Gregory October 7, 2011 at 2:35 am

Are you sure that “Depending on your default init level setting, the system will execute the programs from one of the following directories.” ?
For example my system is running on level 3 but executes VERITAS init scripts from rc2.d during the boot as well.

37 Arun October 15, 2011 at 8:13 am

Very Nice.

38 rajesh October 20, 2011 at 10:02 pm

Excellent !!!!!!!!!!!!!!!!!!!!!
Enough detail and simple .
Thanks very much

Best regard,
rajesh

39 ender October 21, 2011 at 1:20 am

good work fine to know how linux boot and the basic’s of the init run level’s only by ubuntu you have init s (single user) and init u (re run init) as extra

40 evaa November 12, 2011 at 9:12 pm

wow, your explaination is simple yet full with information
very helpful ! <3

41 brijesh November 19, 2011 at 2:49 pm

greate usefull

42 Ketan November 30, 2011 at 1:34 pm

I am flabbergasted.. I have made automation on these parts on S and K .,.. It was too Easy to understand this.. The person who post this.. is really a cool techie.. U rock man..

43 hossein January 2, 2012 at 12:06 am

That was very useful information.
Thanks.

44 NARESH January 17, 2012 at 9:45 pm

Excellent. keep it up..

45 Arun January 24, 2012 at 9:52 pm

Nice. Very useful

46 Omkar January 27, 2012 at 9:32 am

short and sweet and precise explanation

47 Anonymous February 3, 2012 at 3:53 am

very good material and easy to understand …great work

48 54nju1 February 19, 2012 at 1:59 pm

Thanks dude, that was so helpful..

49 subhash March 13, 2012 at 8:27 am

it’s very nice material…..i like it……..superb ………

50 sandeep samale March 21, 2012 at 9:37 pm

HI this is very very useful information as interview point of view as well as for study how Linux boots. Great info Thank you very much Ramesh

51 Anuj April 12, 2012 at 9:28 am

Great and brief doc for Linux boot process. I truly liked it!!!

52 Ravi May 4, 2012 at 11:05 pm

Thanx

53 Deepika May 9, 2012 at 11:03 pm

Superb article with detailed information.

54 Deepak May 14, 2012 at 11:11 am

It is very nice article :)

Leave a Comment

Previous post:

Next post: