#Day3 AWS and DevOps Challenge : Understanding Linux Hardware Management and Boot Process
Table of contents
Introduction:
Linux is a powerful and versatile operating system that efficiently manages hardware resources and offers a robust boot process. In this blog post, we'll learn how Linux identifies and manages hardware devices and explore the stages of the Linux boot process.
Managing Hardware Resources:
Device Detection with udev: When you attach a hardware device like a USB disk to a Linux system, a kernel module detects the change and generates a "uevent." This event is then sent to the user space device manager daemon, called udev. Udev dynamically creates a device node associated with the newly attached USB drive in the
/dev/
filesystem, making the device accessible.To view kernel messages related to USB devices:
$ dmesg | grep -i usb
To get detailed information about a specific device (e.g.,
/dev/sda5
):$ udevadm info --query=path --name=/dev/sda5
To monitor kernel uevents:
$ udevadm monitor
Listing Hardware Devices:
To list PCI devices:
$ lspci
To list block devices:
$ lsblk
To display detailed CPU information:
$ lscpu
To view available memory:
$ lsmem --summary
To see memory usage:
$ free -m
Running commands with root privileges (using
sudo
):$ sudo lshw
Linux Boot Process:
The Linux boot process consists of four key stages:
BIOS POST (Power On Self Test): This stage, independent of Linux, ensures that hardware components are functioning correctly. If the POST test fails, the system may not proceed to the next stage.
Boot Loader (GRUB2): After a successful POST test, the BIOS loads and executes the boot code from the boot device (usually in
/boot
). The boot loader, such as GRUB2, presents boot options and loads the kernel into memory, supplying it with parameters.Kernel Initialization: Once in memory, the kernel decompresses and initializes hardware, memory management, and other tasks. The kernel then looks for the INIT process to set up the user space environment.
INIT Process (systemd): In modern Linux distributions, the INIT process typically calls the systemd daemon, which is responsible for making the system usable. It handles tasks like mounting file systems and managing system services. Systemd's advantage is its ability to parallelize service startup, reducing boot times.
To check the init system used:
$ ls -l /sbin/init
Systemd Targets (Run Levels):
Systemd introduces the concept of "targets" (similar to run levels in traditional init systems). These targets determine the system's operation mode.
Run Level 5: Graphical target (provides a graphical interface).
Run Level 3: Multiuser target (non-graphical mode).
To see the current run level:
$ runlevel
To view the default target:
$ systemctl get-default
To change the default target (e.g., to switch to multiuser mode):
$ systemctl set-default multi-user.target
Conclusion: Linux's hardware management and boot process are crucial aspects of its functionality. Understanding how Linux interacts with hardware and manages the boot process can help users troubleshoot issues, optimize system performance, and tailor their systems to specific needs. Whether you're a system administrator or a Linux enthusiast, this knowledge is valuable for working with Linux effectively.