Linux System Administration

0 of 85 lessons complete (0%)

Starting up and Shutting Down

Kernel Loading

You don’t have access to this lesson

Please register or sign in to access the course content.

Kernel loading refers to the process of loading the operating system kernel into memory and starting its execution. The kernel is the core part of the operating system that manages system resources, hardware communication, and provides essential services for all other software running on the computer.

Key Steps in Kernel Loading

  1. Bootloader Initialization:
    • When a computer starts, the bootloader (such as GRUB in many Unix-like systems) is the first program to run. Its primary job is to initialize hardware and load the kernel into memory.
    • The bootloader provides options for selecting which kernel or operating system to load and might also include configuration settings like kernel parameters.
  2. Kernel Loading:
    • The bootloader loads the kernel image (a compressed file containing the kernel code) into memory.
    • It then passes control to the kernel, which begins its initialization process.
  3. Kernel Initialization:
    • Hardware Detection: The kernel detects and initializes hardware components, such as CPUs, memory, and storage devices.
    • Device Drivers: The kernel loads necessary device drivers to interact with hardware components.
    • Filesystems: It mounts the root filesystem and sets up other filesystems as needed.
    • Processes and Services: The kernel starts essential system processes and services, such as init (or its modern equivalents like systemd).
  4. Transition to User Space:
    • After completing its initialization tasks, the kernel hands over control to the initial system process (init), which starts user-space applications and services.
    • This transition marks the beginning of the operating system’s normal operation, with the kernel managing the system’s resources and user processes running in user space.

Example of Kernel Loading Process

  1. Bootloader Stage:
    • GRUB Menu: You might see a GRUB menu where you can select the kernel version to boot.
    • Command: grub> kernel /boot/vmlinuz-5.10.0 root=/dev/sda1
  2. Kernel Image Loading:
    • GRUB Command: GRUB loads the kernel image specified by the command into memory.
  3. Kernel Initialization:
    • Messages: During startup, you might see messages related to hardware detection and initialization on the screen, such as “Loading kernel…”.
  4. Transition to User Space:
    • Initialization: The kernel transitions to the init process, which might start system services and display a login prompt or graphical user interface.

Kernel loading is a critical part of the system startup process, ensuring that the operating system can manage hardware resources and provide a stable environment for applications.

Kernel Loading and Related Commands

CommandPurposeKey OptionsExample
grubBootloader configuration and managementupdate-grub (update configuration), grub-install (install GRUB)Example:
1. Update GRUB configuration: sudo update-grub
2. Install GRUB to the MBR: sudo grub-install /dev/sda
dmesgDisplay kernel ring buffer messagesNoneExample:
1. Show kernel messages: dmesg
unameDisplay system information, including kernel version-r (kernel version), -a (all info)Example:
1. Show kernel version: uname -r
2. Show all system information: uname -a
lsmodList loaded kernel modulesNoneExample:
1. List modules: lsmod
modprobeAdd or remove kernel modules-r (remove module)Example:
1. Load a module: sudo modprobe <module_name>
2. Remove a module: sudo modprobe -r <module_name>
systemctlControl systemd services and initializationstart (start service), status (check status), enable (enable on boot)Example:
1. Start a service: sudo systemctl start <service>
2. Check status: sudo systemctl status <service>
3. Enable service on boot: sudo systemctl enable <service>
journalctlQuery and display messages from the journal-b (current boot), -u (service)Example:
1. Show logs for the current boot: journalctl -b
2. Show logs for a specific service: journalctl -u <service>

Example Usage:

  1. Update GRUB Configuration:bashCopy codesudo update-grub This command updates the GRUB configuration file based on the current system settings.
  2. Show Kernel Messages:bashCopy codedmesg This command displays messages from the kernel ring buffer, useful for troubleshooting hardware and boot issues.
  3. Show Kernel Version:bashCopy codeuname -r This command shows the currently running kernel version.
  4. List Loaded Kernel Modules:bashCopy codelsmod This command lists all currently loaded kernel modules.
  5. Load and Remove Kernel Modules:
    • Load a Module:bashCopy codesudo modprobe <module_name> This command loads the specified kernel module.
    • Remove a Module:bashCopy codesudo modprobe -r <module_name> This command removes the specified kernel module.
  6. Start and Manage Services with systemd:
    • Start a Service:bashCopy codesudo systemctl start <service> This command starts the specified service.
    • Check Service Status:bashCopy codesudo systemctl status <service> This command shows the status of the specified service.
    • Enable Service on Boot:bashCopy codesudo systemctl enable <service> This command enables the specified service to start automatically on boot.
  7. Query Logs with journalctl:
    • Show Logs for the Current Boot:bashCopy codejournalctl -b This command shows logs from the current boot session.
    • Show Logs for a Specific Service:bashCopy codejournalctl -u <service> This command shows logs related to the specified service.

These commands help manage and interact with the kernel and system services during the boot and operational phases of a Unix-like system.