Chapter 11. System Startup and Customizing a Linux System

In the last chapter, you learned about using traps and signals. You also learned about creating menus with the help of dialog utility.

In this chapter, you will learn about Linux system startup, from power on to the user login and how to customize a Linux system environment.

System startup, inittab, and run levels

When we power on the Linux system, the Shell scripts are run one after another and the Linux system is initialized. These scripts start various services, daemons, start databases, mount discs, and many more applications. Even during the shutting down of the system, certain Shell scripts are executed so that important system data and information can be saved to the disk and the applications are properly shut down. These are called boot, startup, and shutdown scripts. These scripts are copied during installation of the Linux operating system in your computer. As a developer or administrator, understanding these scripts may help you in understating and debugging the Linux system. If required, you can customize these scripts if the need arises.

The kernel startup and init process

In our computers, there is one EPROM chip called BIOS, which is situated on the motherboard or main board of our computers. When we power on, the processor starts executing a program from BIOS. The program from BIOS, does a power on self-test such as checking memory and other peripherals. Then the BIOS program initializes the basic hardware required for PC operation, such as initializing the PCI bus, video devices, and similar.

Finally, BIOS checks the boot device sequence and queries the first boot device. This BIOS program then reads the master boot record of the first boot device, which is normally a hard disk, USB device, or DVD. Once BIOS reads the master boot record of the first boot device, then the boot loader is started. The boot loader reads kernel binary and copies it in the RAM memory. The boot loader checks if the kernel binary is clean and not corrupt. If the integrity check is good then it uncompresses the kernel in the RAM. The bootloader then calls the start_kernel()function, which is a part of kernel. Once the start_kernel()function is called, the kernel is started.

The kernel then initializes the subsystems of kernel such as process management, filesystem, device drivers, memory management, network management, and similar other modules of the kernel. Then, it mounts the root file system, and kernel creates the first process called init. This init process reads the /etc/inittab file. In inittab, the run level information is stored. As per this information, the operating system is initialized process init.

The typical /etc/inittab content will be as follows:

$ cat /etc/inittab

Output:

# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:

In the preceding line, the number 5 after ID specifies that the system should be started in run level 5. It means that the system should be started in X11, such as a graphical user interface. We will study more about run levels in the next section.

Nowadays, many distributions have modified the boot-up sequence. They have removed the /etc/inittab file and used different applications to customize the boot-up process.

Understanding run levels

There are seven run levels. The system will be started in run level 1 to 5. Run level 0 is used for shutting down the system. Run level 6 is used for rebooting the system. The graphical user interface is started in run level 5. The following is the summary of different run levels:

Sr. No.

Run level number

Description

1

0

Halting the system

2

1

Single-user mode

3

2

Multi-user mode

4

3

Multi-user with network support

5

4

Not used

6

5

Graphical user interface with multi-user and networking support

7

6

Rebooting the system

We need to be in the root-user mode to use the init command.

If we give the following command, then the system will shutdown:

# init 0

To reboot the system use the following command:

# init 6

If the system is running in the command-line mode, and if you want to start your server in the graphical user mode, then use the following command:

# init 5

System initialization boot scripts

In the Linux system, the following folders will be present in the /etc/ folder:

Sr. No.

Folder name

Description

1

rc0.d/

The scripts called during shutting down

2

rc1.d/

The run level 1 scripts

3

rc2.d/

The run level 2 scripts

4

rc3.d/

The run level 3 scripts

5

rc4.d/

The run level 4 scripts

6

rc5.d/

The run level 5 scripts

7

rc6.d/

The run level 6 scripts

8

rcS.d/

The scripts called before every run level

9

rc.local

The final script called after run level initialization

Every run level folder will have script names starting either with S or K. When starting the system, the scripts with names starting with S are called one after another. When shutting down, all the script names starting with K are called one after another.

For example, if the system has to be started in run level 5, then initially all the scripts from the rcS.d folder will be called, then all the scripts from rc5.d will be called. Finally, the rc.local script will be called.

The content of /etc/rc.local is as follows:

$ cat /etc/rc.local

Output:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change
# the execution bits.
#
# By default this script does nothing.
exit 0

We can add our customization commands before the exit 0 line in the preceding rc.local script.

Before any user is logged in, the mentioned scripts will be called. After this, user login initialization will be started. This is explained in the following sessions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset