What is Run Level in Linux?

Run-level is a system state on  how the process is starting and what process to run ,which service to enable and disable while booting is decided by the Run-level program.While booting process after the kernel has started the init program it reads the /etc/inittab file where  the default run-level entry saved. and then it starts all the services.

There are totally seven run-levels available in UNIX ,according to the OS  the run-level number may vary.

Types of Run-levels:

In Linux by default it boots either Run-level 3 or run-level 5.You can also modify or switch to different run-levels as per the  needs.

To check the current Run Level settings:
#who  -r

r=Run-level

Sample output for the above command would be

To check the current and previous Run-level details
#runlevel

Sample output for the above command would be

n

In the above output ,“N” indicates the run-level has not been changed since the system was booted.“3” is the current run-level

To change the default Run-level 

/etc/inittab file holds the default run-level entry,open this file with the vi editor and change the run-level number to your desired one as follows,

Here am going to change the run-level from 3 to run-level 5

#vi /etc/inittab

Modify the line as follows

remove 5 and add 3 in the above line,after update reboot the system to login n to the new run-level

To reboot use the following command
#init 6

I hope you find this guide useful

More good stuffs to come,Stay tuned!!!!

Mail me your queries to vasanth@linuxvasanth.com

 

#############################################################
For More Videos Subscribe My Youtube Channel  Linux Vasanth
If you found this article useful, Kindly Subscribe here 👉  Click this link to Subscribe

################################################################################

 

 

 

 

Booting Process Linux

Introduction:

In this article, we are going to learn about the booting process in Linux based Servers.As a system administrator knowing the backend process while power on the server is much needed in IT environment.It helps the administrator in resolving the issues during the booting process.

There are five phases available in booting process:

1)BIOS

2)BOOTLOADER

MBR

GRUB

3)KERNEL

4)INIT

5)RUNLEVEL SCRIPTS

Let us have a look at each phase in details

BIOS(Basic input and output system):
  • When you power on the server BIOS is the first program that loads.

After you press the power button the CPU will check in to the ROM for the further process

  • Because the ROM it has the instructions to tell CPU to start the BIOS

Then BIOS will check all the hardware and bootable devices available on your server After analyzing BIOS will check how to boot the operating system (hard disk or CD-ROM or DVD or network boot).

  • If it is a hard disk then it will look for the primary boot loader to start the operating system
BOOTLOADER:
  • Bootloader resides inside the MBR(Master boot recorder) chip, the bootloader program doesn’t know anything about the operating system filesystems, it knows only the partition table layout pieces of information and how many hard disks attached.
MBR:

The master boot recorder resides in the first sector of the hard disk.

  • The total size of the MBR is only 512 bytes.

From this total 512 bytes, the first  434 to 446 bytes are reserved for the primary bootloader, 64 bytes for the partition table and 6 bytes for the MBR timestamp validation.

  • As I have mentioned above the MBR is not aware of the operating system filesystem, so MBR cannot directly load the kernel program it requires a bootloader with the filesystem driver for each supported filesystem, then only they can be understood and accessed by the bootloader.

The Grub  has configuration file in that the details of the filesystem and the filesystem device drivers are loaded

/boot/grub/grub.conf

The original file for the grub is located in  /etc/grub.conf and this file is symbolic linked to /boot/grub/grub.conf

#ls -l  /etc/grub.conf

To view the Grub config file:

#cat /etc/grub.conf or cat /boot/grub/grub.conf

GRUB(GRand Unified Bootloader):

Grub loads the kernel in three stages

Grub stage1:

The total size of the MBR is 512 bytes, the size is too small and it has all the instructions to load the operating system.

  • The total number of space allocated for the bootstrap code in an MBR is 446 bytes, this 446-byte file for stage1 is named boot.img and it doesn’t contain the partition table information which is added separately with the boot record Because boot record must be so small and it doesn’t understand the filesystem structures.So the purpose of stage1 is to locate and load the stage1.5.After loading the stage1.5 in to the RAM stage1 takes control over to stage1.5.
Grub stage1.5:

As I have explained above the grub stage 1.5 must be located between the boot record itself and the first partition on the hard disk.The function of stage1.5 is to start executing the filesystem drivers that are necessary to load the stage2 from the /boot.

Grub stage2:

The grub stage1 can load the Grub stage 2 directly, but the stage1 is by default setup to load the stage2.The location for the stage2 is /boot/grub2 directory and the stage2 doesn’t have image files like stage1 and stage1.5 instead it has only all the runtime kernel modules that are needed to start the operating system.

Note: Stage2 of Grub2  loads the kernel in to the memory and provides the control of the server over to the kernel.
KERNEL:

1.Once the bootloader starts the kernel it uncompress the initrd image  it mount and load all the device drivers

initrd(initial ramdisk is to loading a temporary root file system in to the memory)

  • 2.Loading and unloading the kernel modules can be done with insmod and rmmod commands which is present inside the inirt image.

3.The kernel will mount the root partition as a read-only

  • 4.The kernel will check the /etc/fstsb file for the filesystem check integrity.

5.If no error found from the /etc/fstab file output then it starts the init process

INIT PROCESS:

Run the server in to run level as mentioned in /etc/inittab file

#cat /etc/inittab

Based on the selected run level, the init process then executes all the startup scripts located in /etc/rc.d/rcx.d

  • Note:All the run level scripts are located inside /etc/rc.d/rcx.d

If everything goes fine then it will display the Login screen……

Never miss an article from this blog, Kindly do like my FB page Learn Linux in an easier way

 

######################################################################################

If you found this article useful, Kindly subscribe👇

Click this link to Subscribe