Linux Tutorial

Linux File/Directory Management

Linux Packaging And Compression

Vim Text Editor

Linux Text Processing

Linux Software Installation

Linux User/User Group Management

Linux Permission Management

Linux Filesystem Management

Linux Advanced Filesystem Management

Linux System Management

Linux Backup and Recovery

Linux System Service Management

Linux System Log Management

Linux Boot Management

LAMP/LNMP Environment

SELinux Management

Linux System Startup Process (for CentOS)

In this tutorial, we will explore the Linux system startup process specifically for CentOS, a popular Linux distribution. The boot process consists of several stages, from powering on the hardware to loading the operating system and user applications.

CentOS uses systemd as its init system, which is responsible for managing services and system states during the startup process.

1. BIOS (Basic Input/Output System) or UEFI (Unified Extensible Firmware Interface)

When you power on a computer, the BIOS or UEFI initializes and performs a series of hardware checks, known as the Power-On Self Test (POST). The BIOS/UEFI is responsible for detecting and configuring hardware components, such as the CPU, memory, and storage devices.

Once POST is complete, the BIOS/UEFI searches for a bootable device in the order specified in its configuration. Typically, the boot order includes options like the hard drive, USB drive, CD/DVD drive, and network boot.

2. Boot Loader (GRUB)

The boot loader is responsible for loading the operating system. CentOS uses GRUB (GNU GRand Unified Bootloader) as its default boot loader. The boot loader typically displays a menu that allows the user to select an operating system or kernel version. Once the user makes a selection or the boot loader times out, it proceeds to load the selected operating system.

3. Kernel Loading

The boot loader loads the Linux kernel into memory and passes control to it. The kernel is responsible for managing system resources, such as the CPU, memory, and devices. The kernel performs various tasks during startup, such as:

  • Initializing the CPU and memory
  • Detecting and configuring hardware devices
  • Mounting the root filesystem (usually as read-only)

4. Init Process (systemd)

After the kernel is loaded and initialized, it starts the init process, which is the first user-space process with a process ID (PID) of 1. CentOS uses systemd as its init system. The init process is responsible for starting other system processes and services.

5. System Targets and Services

systemd uses targets (instead of runlevels) to manage system states. Targets are groups of services that should be started or stopped together. Common system targets in CentOS include:

  • poweroff.target: System halt (shutdown)
  • rescue.target: Single-user mode (maintenance mode)
  • multi-user.target: Multi-user mode with networking (text mode)
  • graphical.target: Multi-user mode with networking and graphical user interface (GUI)
  • reboot.target: System reboot

During the startup process, systemd starts the services required by the default target. By default, CentOS uses multi-user.target or graphical.target, depending on the system configuration.

To manage services in CentOS, you can use the systemctl command. Some common systemctl commands include:

  • List all system services: sudo systemctl list-units --type service
  • Check the status of a specific service: sudo systemctl status service_name
  • Start, stop, or restart a service: sudo systemctl start|stop|restart service_name
  • Enable or disable a service at boot: sudo systemctl enable|disable service_name

6. User Login

Once the system services are started and the target is set, the user is presented with a login prompt. This can be either a text-based prompt in a virtual console or a graphical login screen provided by a display manager, such as GDM (GNOME Display Manager), LightDM, or SDDM (Simple Desktop Display Manager).

  1. Viewing and analyzing CentOS boot logs:

    • Description: CentOS boot logs contain information about the system startup process. Logs are available in /var/log/ directory, and commands like journalctl can be used to analyze systemd logs.
    • Code:
      # Example: Viewing boot logs
      journalctl
      
  2. Configuring services to start on boot in CentOS:

    • Description: Configuring services to start on boot involves using tools like systemctl to enable or disable services for automatic startup.
    • Code:
      # Example: Enabling a service to start on boot
      sudo systemctl enable servicename
      
  3. Troubleshooting CentOS startup issues:

    • Description: Troubleshooting startup issues involves checking logs, verifying service configurations, and ensuring proper dependencies. Tools like journalctl and systemctl are essential.
    • Code:
      # Example: Checking systemd logs
      journalctl -xe
      
  4. Customizing the GRUB bootloader in CentOS:

    • Description: Customizing the GRUB bootloader involves editing the GRUB configuration file (/etc/default/grub) to modify kernel parameters, set default boot options, or change the appearance.
    • Code:
      # Example: Editing GRUB configuration
      sudo nano /etc/default/grub
      sudo grub2-mkconfig -o /boot/grub2/grub.cfg
      
  5. Managing systemd units during CentOS boot:

    • Description: Managing systemd units involves configuring and controlling services, targets, and other units during the boot process. The systemctl command is used for this purpose.
    • Code:
      # Example: Listing enabled units
      sudo systemctl list-unit-files --type=service