<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://matomo.mintarc.com/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tommy</id>
	<title>Mintarc Forge - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://matomo.mintarc.com/mediawiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Tommy"/>
	<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Special:Contributions/Tommy"/>
	<updated>2026-06-15T09:38:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=MediaWiki:Common.js&amp;diff=1051</id>
		<title>MediaWiki:Common.js</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=MediaWiki:Common.js&amp;diff=1051"/>
		<updated>2026-01-11T14:57:48Z</updated>

		<summary type="html">&lt;p&gt;Tommy: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Crypt_pad&amp;diff=1050</id>
		<title>Crypt pad</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Crypt_pad&amp;diff=1050"/>
		<updated>2025-12-07T02:58:46Z</updated>

		<summary type="html">&lt;p&gt;Tommy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CryptPad is an open-source, privacy-focused collaboration platform designed to provide secure and encrypted tools for document editing, file sharing, and team collaboration. Developed as an alternative to mainstream platforms like Google Docs, CryptPad prioritizes user privacy through its robust implementation of end-to-end encryption. This ensures that all data is encrypted on the user&#039;s device before being transmitted to the server, making it inaccessible to service providers, administrators, or potential attackers. Its zero-knowledge architecture means that even the platform&#039;s operators cannot access users&#039; content, offering confidentiality.&lt;br /&gt;
&lt;br /&gt;
CryptPad provides a suite of applications tailored for collaborative work. These include tools for rich text editing, spreadsheets, slideshows, Kanban boards for project management, code/Markdown editing, whiteboards for brainstorming, and polls for decision-making. Each application supports real-time collaboration, allowing multiple users to work on the same document simultaneously while maintaining data security. Unlike traditional platforms, CryptPad uses symmetric encryption with a unique key for each document. This key is embedded in the document&#039;s link, enabling seamless sharing but requiring users to manage access carefully since links effectively serve as decryption keys.&lt;br /&gt;
&lt;br /&gt;
The platform&#039;s commitment to open-source principles is evident in its publicly available source code, hosted on GitHub under the AGPLv3 license. This transparency allows developers and organizations to audit the code for security vulnerabilities or customize it to meet specific needs. CryptPad can be self-hosted, giving users full control over their data and compliance with data sovereignty regulations. For those who prefer managed services, CryptPad offers a cloud-hosted version at CryptPad.fr with free and paid subscription tiers based on storage capacity and additional features.&lt;br /&gt;
&lt;br /&gt;
A key strength of CryptPad lies in its privacy-centric design. User accounts are secured using cryptographic keys derived from their username and password. This approach ensures that passwords are never stored on the server and that even usernames remain invisible to administrators. Additionally, CryptPad minimizes metadata exposure by preventing operators from accessing document content or user activity logs. However, users are advised to select trustworthy server instances and follow best practices such as using strong passwords and enabling two-factor authentication (2FA) to maximize security.&lt;br /&gt;
&lt;br /&gt;
Despite its strengths in privacy and security, CryptPad has some limitations. For example, when sharing a document link, the embedded decryption key grants irrevocable access to recipients. To revoke access, users must create a copy of the document and destroy the original. Moreover, while CryptPad is private by design, it does not guarantee anonymity; IP addresses and other metadata may still be visible to server operators unless mitigated with tools like VPNs or Tor.&lt;br /&gt;
&lt;br /&gt;
CryptPad also incorporates features aimed at enhancing usability and accessibility. Recent updates have introduced Web Content Accessibility Guidelines (WCAG) compliance improvements and mobile optimizations to ensure a seamless experience across devices. The platform supports integration with services like Nextcloud for encrypted file storage and collaboration within existing ecosystems. Additionally, administrative tools allow server operators to moderate content effectively by archiving or deleting accounts that violate terms of service.&lt;br /&gt;
&lt;br /&gt;
CryptPad is a collaboration suite that combines open-source flexibility with encryption to deliver a secure alternative to proprietary platforms. Its emphasis on privacy makes it particularly appealing for individuals and organizations handling sensitive information or seeking compliance with strict data protection standards. While it requires careful management of shared links and trust in server operators for certain aspects of security, CryptPad remains one of the most robust tools available for secure online collaboration.&lt;br /&gt;
&lt;br /&gt;
Check it out&lt;br /&gt;
https://cryptpad.fr/&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Only_Office&amp;diff=1049</id>
		<title>Only Office</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Only_Office&amp;diff=1049"/>
		<updated>2025-12-07T02:57:30Z</updated>

		<summary type="html">&lt;p&gt;Tommy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ONLYOFFICE ==&lt;br /&gt;
ONLYOFFICE is a versatile office suite and collaboration platform designed to provide a comprehensive set of tools for document editing, project management, and team collaboration. It is available as an open-source solution, making it highly customizable and accessible to individuals, businesses, and organizations seeking transparency and control over their software.&lt;br /&gt;
&lt;br /&gt;
At its core, ONLYOFFICE includes a suite of editors for creating and managing text documents, spreadsheets, presentations, and fillable PDF forms. These editors are designed with high compatibility with Microsoft Office formats, ensuring seamless integration into existing workflows. The platform also supports advanced features such as real-time co-editing, version control, commenting, and built-in communication tools like chat and video calls. Users can deploy ONLYOFFICE in various environments on-premises or in the cloud and integrate it with popular platforms like Nextcloud, WordPress, or Moodle for enhanced functionality.&lt;br /&gt;
&lt;br /&gt;
ONLYOFFICE&#039;s open-source nature is central to its identity. Released under the AGPL 3.0 license for its core components and Apache 2.0 for certain modules like ONLYOFFICE Groups, the platform allows users to access its source code on GitHub. This openness enables developers to modify the software according to their needs, contribute improvements to the community, or integrate ONLYOFFICE into custom applications. The open-source approach also ensures compliance with data sovereignty principles, giving users full control over their data without reliance on proprietary cloud services.&lt;br /&gt;
&lt;br /&gt;
The platform emphasizes security through robust measures such as encryption (at rest, in transit, and end-to-end), GDPR compliance, and flexible access controls. These features make it suitable for industries requiring stringent data protection standards. Additionally, ONLYOFFICE offers tools like CRM modules, project management features with Gantt charts and time tracking, email integration, and calendar synchronization—all of which can be tailored to specific organizational needs.&lt;br /&gt;
&lt;br /&gt;
ONLYOFFICE is a good open-source office suite that combines professional-grade document editing with collaborative tools for teams of all sizes. Its open-source licensing fosters transparency and adaptability while prioritizing security and compatibility with industry standards.&lt;br /&gt;
&lt;br /&gt;
Check it out here:&lt;br /&gt;
https://www.onlyoffice.com/&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Only_Office&amp;diff=1048</id>
		<title>Only Office</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Only_Office&amp;diff=1048"/>
		<updated>2025-12-07T02:57:13Z</updated>

		<summary type="html">&lt;p&gt;Tommy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ONLY OFFICE ==&lt;br /&gt;
ONLYOFFICE is a versatile office suite and collaboration platform designed to provide a comprehensive set of tools for document editing, project management, and team collaboration. It is available as an open-source solution, making it highly customizable and accessible to individuals, businesses, and organizations seeking transparency and control over their software.&lt;br /&gt;
&lt;br /&gt;
At its core, ONLYOFFICE includes a suite of editors for creating and managing text documents, spreadsheets, presentations, and fillable PDF forms. These editors are designed with high compatibility with Microsoft Office formats, ensuring seamless integration into existing workflows. The platform also supports advanced features such as real-time co-editing, version control, commenting, and built-in communication tools like chat and video calls. Users can deploy ONLYOFFICE in various environments on-premises or in the cloud and integrate it with popular platforms like Nextcloud, WordPress, or Moodle for enhanced functionality.&lt;br /&gt;
&lt;br /&gt;
ONLYOFFICE&#039;s open-source nature is central to its identity. Released under the AGPL 3.0 license for its core components and Apache 2.0 for certain modules like ONLYOFFICE Groups, the platform allows users to access its source code on GitHub. This openness enables developers to modify the software according to their needs, contribute improvements to the community, or integrate ONLYOFFICE into custom applications. The open-source approach also ensures compliance with data sovereignty principles, giving users full control over their data without reliance on proprietary cloud services.&lt;br /&gt;
&lt;br /&gt;
The platform emphasizes security through robust measures such as encryption (at rest, in transit, and end-to-end), GDPR compliance, and flexible access controls. These features make it suitable for industries requiring stringent data protection standards. Additionally, ONLYOFFICE offers tools like CRM modules, project management features with Gantt charts and time tracking, email integration, and calendar synchronization—all of which can be tailored to specific organizational needs.&lt;br /&gt;
&lt;br /&gt;
ONLYOFFICE is a good open-source office suite that combines professional-grade document editing with collaborative tools for teams of all sizes. Its open-source licensing fosters transparency and adaptability while prioritizing security and compatibility with industry standards.&lt;br /&gt;
&lt;br /&gt;
Check it out here:&lt;br /&gt;
https://www.onlyoffice.com/&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Only_Office&amp;diff=1047</id>
		<title>Only Office</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Only_Office&amp;diff=1047"/>
		<updated>2025-12-07T02:56:59Z</updated>

		<summary type="html">&lt;p&gt;Tommy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== ONLY OFFICE ==&lt;br /&gt;
ONLYOFFICE is a versatile office suite and collaboration platform designed to provide a comprehensive set of tools for document editing, project management, and team collaboration. It is available as an open-source solution, making it highly customizable and accessible to individuals, businesses, and organizations seeking transparency and control over their software.&lt;br /&gt;
&lt;br /&gt;
At its core, ONLYOFFICE includes a suite of editors for creating and managing text documents, spreadsheets, presentations, and fillable PDF forms. These editors are designed with high compatibility with Microsoft Office formats, ensuring seamless integration into existing workflows. The platform also supports advanced features such as real-time co-editing, version control, commenting, and built-in communication tools like chat and video calls. Users can deploy ONLYOFFICE in various environments on-premises or in the cloud—and integrate it with popular platforms like Nextcloud, WordPress, or Moodle for enhanced functionality.&lt;br /&gt;
&lt;br /&gt;
ONLYOFFICE&#039;s open-source nature is central to its identity. Released under the AGPL 3.0 license for its core components and Apache 2.0 for certain modules like ONLYOFFICE Groups, the platform allows users to access its source code on GitHub. This openness enables developers to modify the software according to their needs, contribute improvements to the community, or integrate ONLYOFFICE into custom applications. The open-source approach also ensures compliance with data sovereignty principles, giving users full control over their data without reliance on proprietary cloud services.&lt;br /&gt;
&lt;br /&gt;
The platform emphasizes security through robust measures such as encryption (at rest, in transit, and end-to-end), GDPR compliance, and flexible access controls. These features make it suitable for industries requiring stringent data protection standards. Additionally, ONLYOFFICE offers tools like CRM modules, project management features with Gantt charts and time tracking, email integration, and calendar synchronization—all of which can be tailored to specific organizational needs.&lt;br /&gt;
&lt;br /&gt;
ONLYOFFICE is a good open-source office suite that combines professional-grade document editing with collaborative tools for teams of all sizes. Its open-source licensing fosters transparency and adaptability while prioritizing security and compatibility with industry standards.&lt;br /&gt;
&lt;br /&gt;
Check it out here:&lt;br /&gt;
https://www.onlyoffice.com/&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Main_Page&amp;diff=1046</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Main_Page&amp;diff=1046"/>
		<updated>2025-09-09T02:47:52Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Welcome to mintarc forge */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__FORCETOC__&lt;br /&gt;
== Welcome to mintarc forge ==&lt;br /&gt;
This a place that you can use to explore or learn more about Free and Opens Source Software (FOSS)&lt;br /&gt;
as well as Opens Source Software (OSS)&lt;br /&gt;
&lt;br /&gt;
You can also read our blog here:.&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Mintarc_Blog#: mintarc Blog]&lt;br /&gt;
&lt;br /&gt;
日本語ページはこちら:&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Main_Page_JA#: 日本語メインページ]&lt;br /&gt;
&lt;br /&gt;
== What is FOSS and OSS ==&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Free_and_Open_Source_Software_(en)#:FOSS Free and Open Source Software]&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Open_Source_Software#Summary:OSS Open Source Software]&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=FOSS_and_OSS_Tools#: FOSS and OSS Tools]&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Linux_stuff Linux Stuff]&lt;br /&gt;
&lt;br /&gt;
== Understanding how Licensing Works ==&lt;br /&gt;
&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Explaining_Licenses#Summary:EL Explaining Licensese]&lt;br /&gt;
&lt;br /&gt;
== The Importance of Privacy and Data Ownership ==&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Data_Privacy_and_Data_Ownership#Summary:DPD Data Privacy and Data Ownership]&lt;br /&gt;
&lt;br /&gt;
== FOSS vs Proprietary in Terms of Cost ==&lt;br /&gt;
* [https://matomo.mintarc.com/mediawiki/index.php?title=Cost_Breakdown_of_FOSS_vs._Proprietary_Software##Cost_Breakdown_of_FOSS_vs._Proprietary_Software:Cost Cost Breakdown of FOSS vs. Proprietary Software]&lt;br /&gt;
&lt;br /&gt;
== The mintarc Process==&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Current State Assessment&#039;&#039;&#039;&lt;br /&gt;
The first step in assisting a company with OSS or FOSS adoption is to conduct a comprehensive assessment of their current IT environment. This involves analyzing existing systems, software, and processes to understand how they operate and where there may be opportunities for improvement. By engaging with key stakeholders, we can gather insights into the organization&#039;s specific needs, challenges, and goals.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Define Goals for FOSS Adoption&#039;&#039;&#039;&lt;br /&gt;
Once the current state is understood, the next step is to work collaboratively with the organization to define clear objectives for adopting FOSS. This may include goals such as reducing software licensing costs, increasing flexibility in software development, enhancing security through community-driven updates, or avoiding vendor lock-in. Establishing these goals will provide a framework for evaluating potential solutions.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Identify Suitable FOSS Solutions&#039;&#039;&#039;&lt;br /&gt;
With defined goals in place, we will research and identify FOSS options that align with the organization’s needs. This involves evaluating various solutions based on their features, community support, documentation quality, and security update frequency. By presenting a curated list of suitable options, we help the organization make informed decisions about which FOSS solutions to consider.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Develop an Implementation Plan&#039;&#039;&#039;&lt;br /&gt;
After selecting appropriate FOSS solutions, we will develop a detailed implementation plan tailored to the organization’s unique context. This plan will outline a phased approach for deployment, including timelines and milestones. Additionally, it will identify necessary resources—such as personnel and technology—and establish a training program to ensure that staff are prepared for the transition.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Conduct a Pilot Project&#039;&#039;&#039;&lt;br /&gt;
Before fully implementing the chosen FOSS solution across the organization, it is advisable to conduct a pilot project. This small-scale test allows the organization to evaluate the effectiveness of the solution in a controlled environment. We will help design this pilot, monitor its progress, and gather feedback from users to assess performance and identify any potential issues that need addressing.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Full-Scale Implementation&#039;&#039;&#039;&lt;br /&gt;
If the pilot project proves successful, We will assist in rolling out the FOSS solution across the entire organization. This phase involves managing the migration process carefully to minimize disruption to business operations. We will provide guidance on best practices for deployment and ensure that any challenges encountered during this phase are promptly addressed.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Integration&#039;&#039;&#039;&lt;br /&gt;
Recognizing that each organization has unique requirements, we will work on integrating the FOSS solution as needed. This may involve configuring settings to enhance functionality. Furthermore, ensuring seamless integration with existing systems is crucial; we will facilitate this process to ensure that all components work together effectively.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Training and Support&#039;&#039;&#039;&lt;br /&gt;
To maximize the benefits of the new FOSS solution, comprehensive training programs will be provided for employees. We will develop training materials and sessions tailored to different user groups within the organization. Additionally, ongoing technical support will be available to assist users with any questions or issues they may encounter after implementation.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Monitoring and Optimization&#039;&#039;&#039;&lt;br /&gt;
Once the FOSS solution is fully operational, it is important to continuously monitor its performance. We can establish metrics for evaluating effectiveness and gather feedback from users regularly. This ongoing assessment allows for optimization of the solution based on real-world usage and ensures that it continues to meet organizational needs over time.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Long-Term Strategic Planning&#039;&#039;&#039;&lt;br /&gt;
Finally, as organizations become more comfortable with OSS/FOSS solutions, we will help explore ways to contribute back to the open-source community. This could involve participating in development efforts or sharing insights gained during implementation. Additionally, we will assist in developing long-term strategies for expanding FOSS utilization within the organization, ensuring that they remain agile and responsive to future technological changes.&lt;br /&gt;
&lt;br /&gt;
We can effectively guide organizations through their journey of adopting OSS/FOSS solutions, paving the way for successful implementation and long-term value creation.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Iso_building&amp;diff=1045</id>
		<title>Iso building</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Iso_building&amp;diff=1045"/>
		<updated>2025-08-04T12:34:49Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Live System */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=ISO Building=&lt;br /&gt;
When you get ready to compile the ISO ensure you pay attention to these things&lt;br /&gt;
&lt;br /&gt;
==Install and configure the rootfs==&lt;br /&gt;
You need to prep the rootfs so that you can compile it this means you wan to configure it and install software that you will use in the ISO.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mount --bind /dev /paths to your/chroot_folder/dev &lt;br /&gt;
sudo mount --bind /proc /paths to your/chroot_folder/proc &lt;br /&gt;
sudo mount --bind /sys /paths to your/chroot_folder/sys &lt;br /&gt;
sudo mount -t devpts devpts /paths to your/chroot_folder/dev/pts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When building an ISO from a chroot folder, you need to bind certain system directories (/dev, /proc, /sys, and /dev/pts) to the chroot environment before installing software. This is because these directories provide essential system-level interfaces that allow the chroot environment to function as if it were a complete operating system. &lt;br /&gt;
Here&#039;s why each mount is necessary:&lt;br /&gt;
#&#039;&#039;&#039;/dev&#039;&#039;&#039;: This directory contains device files that represent hardware devices (e.g., disks, terminals). Binding /dev ensures that the chroot environment has access to these device files, which are often required during package installation or configuration processes.&lt;br /&gt;
#&#039;&#039;&#039;/proc&#039;&#039;&#039;: The /proc directory is a virtual filesystem that provides information about system processes and hardware. Many installation scripts and tools rely on data from /proc for system configuration.&lt;br /&gt;
#&#039;&#039;&#039;/sys&#039;&#039;&#039;: Similar to /proc, /sys is a virtual filesystem that provides information about the kernel and hardware devices. Binding /sys allows software inside the chroot to interact with the kernel as needed.&lt;br /&gt;
#&#039;&#039;&#039;/dev/pts&#039;&#039;&#039;: This is required for pseudo-terminal devices (used by terminal emulators). Without binding this directory, terminal-based tools may fail to work properly inside the chroot environment.&lt;br /&gt;
&lt;br /&gt;
These bindings ensure that the chroot environment behaves like a regular system, allowing software installations and configurations to proceed smoothly. Once these directories are mounted, you can install packages or make other modifications within the chroot environment as part of your ISO-building process&lt;br /&gt;
&lt;br /&gt;
Once those mounts are in place then go into the rootfs and install al the software you need and make all the configurations you prefer.&lt;br /&gt;
&lt;br /&gt;
==Setting up ISOLinux boot loader==&lt;br /&gt;
ISOLINUX is a specialized bootloader from the Syslinux suite designed for booting Linux systems from ISO 9660 filesystems (CDs/DVDs) and El Torito-compliant media. &lt;br /&gt;
*&#039;&#039;&#039;ISO 9660/El Torito Support&#039;&#039;&#039;: Boots directly from CDs/DVDs without requiring floppy emulation in &amp;quot;no emulation&amp;quot; mode, ensuring compatibility with modern BIOS/UEFI systems.&lt;br /&gt;
*&#039;&#039;&#039;Hybrid ISO Capability&#039;&#039;&#039;:Generates ISOs that can be written to both CDs and USB drives (via embedded MBR), simplifying cross-media booting.&lt;br /&gt;
*&#039;&#039;&#039;Lightweight Design&#039;&#039;&#039;: Minimalist footprint, ideal for live CDs and installation media (e.g., Ubuntu/Debian installers).&lt;br /&gt;
*&#039;&#039;&#039;Customizable Boot Menus&#039;&#039;&#039;: Configurable via isolinux.cfg with options for text/graphical menus, kernel parameters, and multi-boot entries.&lt;br /&gt;
&lt;br /&gt;
The reason we use this is because of legacy hardware, it is not meant for UEFI booting, we include it in Peppermint a as a bootloader primarily for BIOS-based booting of optical media (CDs/DVDs) and legacy compatibility&lt;br /&gt;
&lt;br /&gt;
===Files used for our configs are ===&lt;br /&gt;
Core Bootloader Files:&lt;br /&gt;
*isolinux.bin	Bootloader binary for BIOS systems. Required for El Torito bootable CDs.&lt;br /&gt;
*isolinux.cfg	Configuration file defining boot menu entries, kernel paths, and parameters.&lt;br /&gt;
*boot.cat	Boot catalog file generated by mkisofs to list bootable images.&lt;br /&gt;
&lt;br /&gt;
Menu System Files&lt;br /&gt;
*vesamenu.c32	Graphical menu module for VESA-compatible splash screens.&lt;br /&gt;
*menu.cfg	Menu configuration (often included by isolinux.cfg for modularity).&lt;br /&gt;
*stdmenu.cfg	Standard menu template (optional).&lt;br /&gt;
*recovery.cfg	Menu entries for recovery/rescue modes.&lt;br /&gt;
*live.cfg	Configuration for live session boot options.&lt;br /&gt;
*utilities.cfg	Tools menu (e.g., memory tests, hardware diagnostics).&lt;br /&gt;
&lt;br /&gt;
Compatibility Modules:&lt;br /&gt;
*libcom32.c32	Core library for COM32 modules (required for advanced features).&lt;br /&gt;
*libmenu.c32	Menu-handling library.&lt;br /&gt;
*libutil.c32	Utility functions (e.g., file parsing).&lt;br /&gt;
*ldlinux.c32	Loader for SYSLINUX extensions.&lt;br /&gt;
&lt;br /&gt;
Hardware Utilities:&lt;br /&gt;
*hdt.c32	Hardware Detection Tool (lists CPU, RAM, PCI devices).&lt;br /&gt;
*pci.ids	Database of PCI hardware identifiers used by hdt.c32.&lt;br /&gt;
&lt;br /&gt;
Boot Process Flow&lt;br /&gt;
#BIOS Loads isolinux.bin: The El Torito boot sector points to isolinux.bin, which initializes the bootloader.&lt;br /&gt;
#Read isolinux.cfg: Defines boot entries (e.g., &amp;quot;Live Session&amp;quot; or &amp;quot;Install&amp;quot;) and kernel parameters.&lt;br /&gt;
#Load Modules: &lt;br /&gt;
##vesamenu.c32 renders graphical menus.&lt;br /&gt;
##hdt.c32 provides hardware diagnostics.&lt;br /&gt;
#Launch Kernel:Specified by KERNEL directives in isolinux.cfg (e.g., /boot/vmlinuz).&lt;br /&gt;
&lt;br /&gt;
===Example isolinux.cfg Structure===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEFAULT vesamenu.c32&lt;br /&gt;
PROMPT 0&lt;br /&gt;
TIMEOUT 300&lt;br /&gt;
&lt;br /&gt;
MENU TITLE Boot Menu&lt;br /&gt;
MENU INCLUDE stdmenu.cfg&lt;br /&gt;
&lt;br /&gt;
LABEL live&lt;br /&gt;
  MENU LABEL ^Start Live Session&lt;br /&gt;
  KERNEL /boot/vmlinuz&lt;br /&gt;
  APPEND initrd=/boot/initrd.img root=/dev/sr0&lt;br /&gt;
&lt;br /&gt;
LABEL recovery&lt;br /&gt;
  MENU LABEL ^Recovery Mode&lt;br /&gt;
  KERNEL /boot/vmlinuz&lt;br /&gt;
  APPEND initrd=/boot/initrd.img single&lt;br /&gt;
&lt;br /&gt;
MENU INCLUDE utilities.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Configure Grub==&lt;br /&gt;
GRUB is required for UEFI systems because it provides native UEFI compatibility, which ISOLINUX lacks. Peppermit also needs to include the grub configurations&lt;br /&gt;
&lt;br /&gt;
===boot/grub/ Directory (GRUB Configuration)===&lt;br /&gt;
*grub.cfg	Main GRUB configuration for UEFI/BIOS booting. Contains boot menu entries and kernel parameters.&lt;br /&gt;
*config.cfg	Custom configuration (likely sourced by grub.cfg). Used to modularize settings (e.g., variables, device detection).&lt;br /&gt;
*install.cfg	Installer-specific configuration (e.g., kernel paths for Debian/Ubuntu installations).&lt;br /&gt;
*install_start.cfg	Pre-installation boot logic (e.g., hardware checks or initramfs setup).&lt;br /&gt;
*loopback.cfg	Loopback boot configuration for ISO-based installations (e.g., loopback loop /cdrom/image.iso).&lt;br /&gt;
*theme.cfg	GRUB theme settings (fonts, colors, backgrounds).&lt;br /&gt;
&lt;br /&gt;
===Example grub.cfg===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
menuentry &amp;quot;Live ISO&amp;quot; {&lt;br /&gt;
  set root=(hd0,1)&lt;br /&gt;
  loopback loop /iso/image.iso&lt;br /&gt;
  linux (loop)/boot/vmlinuz boot=live&lt;br /&gt;
  initrd (loop)/boot/initrd.img&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example theme.cfg===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set theme=/boot/grub/themes/custom/theme.txt  # Defined in theme.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Example loopback.cfg===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
menuentry &amp;quot;Boot ISO&amp;quot; {&lt;br /&gt;
  loopback loop (hd1)/path/to/image.iso&lt;br /&gt;
  linux (loop)/casper/vmlinuz boot=casper&lt;br /&gt;
  initrd (loop)/casper/initrd.img&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Live System==&lt;br /&gt;
The live folder in a Linux ISO is critical for live system functionality, which allows users to boot and run an operating system directly from media (USB/CD) without installation. &lt;br /&gt;
&lt;br /&gt;
===Core Live System Files===&lt;br /&gt;
The live folder contains key components for booting a functional OS:&lt;br /&gt;
*Filesystem.squashfs: Compressed read-only OS root filesystem (includes /bin, /usr, etc.).&lt;br /&gt;
**vmlinuz: Linux kernel loaded during boot.&lt;br /&gt;
**initrd.img: Initial RAM disk with tools to mount SquashFS and initialize hardware.&lt;br /&gt;
&lt;br /&gt;
===How It Works===&lt;br /&gt;
*Boot Process:&lt;br /&gt;
**GRUB/ISOLINUX loads vmlinuz and initrd.img, which decompress filesystem.squashfs into RAM or a temporary disk layer.&lt;br /&gt;
*Union Mounts:&lt;br /&gt;
**Combines the read-only SquashFS with a writeable layer (e.g., tmpfs in RAM or casper-rw for persistence).&lt;br /&gt;
&lt;br /&gt;
===Use Cases===&lt;br /&gt;
*Testing/Portability:&lt;br /&gt;
**Run Linux without altering the host system’s disk.&lt;br /&gt;
*System Recovery:&lt;br /&gt;
**Access broken systems via live tools (e.g., gparted, fsck).&lt;br /&gt;
*Installation:&lt;br /&gt;
**Many installers (e.g., Ubuntu) run as live sessions before writing to disk.&lt;br /&gt;
===Persistence (Optional)===&lt;br /&gt;
*casper-rw File/Partition:&lt;br /&gt;
**Stores user data (e.g., installed apps, files) across reboots.&lt;br /&gt;
**Non-Persistent Mode:&lt;br /&gt;
*Changes are discarded after shutdown (uses RAM for temporary writes).&lt;br /&gt;
&lt;br /&gt;
===Example Folder structure===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/live/&lt;br /&gt;
├── filesystem.squashfs  # OS root (compressed)&lt;br /&gt;
├── vmlinuz              # Kernel&lt;br /&gt;
└── initrd.img           # Initial RAM disk&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Make the filesystem.squashfs==&lt;br /&gt;
filesystem.squashfs is a compressed, read-only filesystem image used in Linux live environments (inthis case Debian) and embedded systems. &lt;br /&gt;
Here&#039;s a structured breakdown:&lt;br /&gt;
*Compression: Uses algorithms like zlib, lz4, lzo, xz, or zstd to minimize size.&lt;br /&gt;
*Read-Only: Protects system integrity by preventing writes to the base OS.&lt;br /&gt;
*Efficiency:&lt;br /&gt;
**Small inodes: ~8 bytes per inode (directory/file metadata).&lt;br /&gt;
**Block sizes: Up to 1 MB (default 128 KB) for better compression ratios.&lt;br /&gt;
&lt;br /&gt;
We use this as it enables booting an OS directly from USB/CD without installation&lt;br /&gt;
&lt;br /&gt;
===Example command===&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mksquashfs /pathto your chroot /path to save the/live/filesystem.squashfs -comp xz -e boot&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#Generate with mksquashfs&lt;br /&gt;
#Uses XZ compression (high ratio, slower than alternatives like lz4 or zstd). that is -comp xz&lt;br /&gt;
#Excludes the /boot directory from the image (common for ISOs where boot files are stored separately in /isolinux/ or /boot/grub/) that is -e boot&lt;br /&gt;
&lt;br /&gt;
==Compile the ISO==&lt;br /&gt;
In this case we use xorriso. This is a command-line tool for creating, modifying, and burning ISO 9660 filesystem images. It serves as both a standalone ISO manipulator and a modern replacement for older tools like mkisofs and genisoimage&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo xorriso -as mkisofs -o ./yourisoname.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -R -V &amp;quot;YourISO&amp;quot; -follow-links ./iso_configs&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets break down the commands&lt;br /&gt;
&lt;br /&gt;
#xorriso -as mkisofs - Emulates mkisofs behavior for compatibility with legacy ISO creation workflows&lt;br /&gt;
#-o ./yourisoname.iso  - Specifies the output ISO filename (mylive.iso in the current directory)&lt;br /&gt;
#-b isolinux/isolinux.bin - Sets BIOS boot image (ISOLINUX bootloader)&lt;br /&gt;
#-c isolinux/boot.cat - Specifies the boot catalog path (required for El Torito BIOS booting)&lt;br /&gt;
#-no-emul-boot - Boots directly from isolinux.bin without emulating a floppy disk&lt;br /&gt;
#-boot-load-size 4 - Loads 4 sectors (512B each) of isolinux.bin into memory (historical requirement for older BIOSes)&lt;br /&gt;
#-boot-info-table - Embeds a BIOS boot information table (required by ISOLINUX)&lt;br /&gt;
#-eltorito-alt-boot- Enables dual boot entries (BIOS + UEFI) in the ISO&#039;s El Torito catalog&lt;br /&gt;
#--e boot/grub/efi.img - Points UEFI firmware to the GRUB EFI binary within the ISO&lt;br /&gt;
#-R  - Enables Rock Ridge extensions for Unix permissions/long filenames &lt;br /&gt;
#-V &amp;quot;YourISO&amp;quot; -Sets the volume label&lt;br /&gt;
#-follow-links - Preserves symbolic links instead of copying their targets&lt;br /&gt;
#./iso_configs - Source directory containing files to include in the ISO&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Iso_building&amp;diff=1044</id>
		<title>Iso building</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Iso_building&amp;diff=1044"/>
		<updated>2025-08-04T12:28:33Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Install and confifgure the rootfs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=ISO Building=&lt;br /&gt;
When you get ready to compile the ISO ensure you pay attention to these things&lt;br /&gt;
&lt;br /&gt;
==Install and configure the rootfs==&lt;br /&gt;
You need to prep the rootfs so that you can compile it this means you wan to configure it and install software that you will use in the ISO.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo mount --bind /dev /paths to your/chroot_folder/dev &lt;br /&gt;
sudo mount --bind /proc /paths to your/chroot_folder/proc &lt;br /&gt;
sudo mount --bind /sys /paths to your/chroot_folder/sys &lt;br /&gt;
sudo mount -t devpts devpts /paths to your/chroot_folder/dev/pts&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When building an ISO from a chroot folder, you need to bind certain system directories (/dev, /proc, /sys, and /dev/pts) to the chroot environment before installing software. This is because these directories provide essential system-level interfaces that allow the chroot environment to function as if it were a complete operating system. &lt;br /&gt;
Here&#039;s why each mount is necessary:&lt;br /&gt;
#&#039;&#039;&#039;/dev&#039;&#039;&#039;: This directory contains device files that represent hardware devices (e.g., disks, terminals). Binding /dev ensures that the chroot environment has access to these device files, which are often required during package installation or configuration processes.&lt;br /&gt;
#&#039;&#039;&#039;/proc&#039;&#039;&#039;: The /proc directory is a virtual filesystem that provides information about system processes and hardware. Many installation scripts and tools rely on data from /proc for system configuration.&lt;br /&gt;
#&#039;&#039;&#039;/sys&#039;&#039;&#039;: Similar to /proc, /sys is a virtual filesystem that provides information about the kernel and hardware devices. Binding /sys allows software inside the chroot to interact with the kernel as needed.&lt;br /&gt;
#&#039;&#039;&#039;/dev/pts&#039;&#039;&#039;: This is required for pseudo-terminal devices (used by terminal emulators). Without binding this directory, terminal-based tools may fail to work properly inside the chroot environment.&lt;br /&gt;
&lt;br /&gt;
These bindings ensure that the chroot environment behaves like a regular system, allowing software installations and configurations to proceed smoothly. Once these directories are mounted, you can install packages or make other modifications within the chroot environment as part of your ISO-building process&lt;br /&gt;
&lt;br /&gt;
Once those mounts are in place then go into the rootfs and install al the software you need and make all the configurations you prefer.&lt;br /&gt;
&lt;br /&gt;
==Setting up ISOLinux boot loader==&lt;br /&gt;
ISOLINUX is a specialized bootloader from the Syslinux suite designed for booting Linux systems from ISO 9660 filesystems (CDs/DVDs) and El Torito-compliant media. &lt;br /&gt;
*&#039;&#039;&#039;ISO 9660/El Torito Support&#039;&#039;&#039;: Boots directly from CDs/DVDs without requiring floppy emulation in &amp;quot;no emulation&amp;quot; mode, ensuring compatibility with modern BIOS/UEFI systems.&lt;br /&gt;
*&#039;&#039;&#039;Hybrid ISO Capability&#039;&#039;&#039;:Generates ISOs that can be written to both CDs and USB drives (via embedded MBR), simplifying cross-media booting.&lt;br /&gt;
*&#039;&#039;&#039;Lightweight Design&#039;&#039;&#039;: Minimalist footprint, ideal for live CDs and installation media (e.g., Ubuntu/Debian installers).&lt;br /&gt;
*&#039;&#039;&#039;Customizable Boot Menus&#039;&#039;&#039;: Configurable via isolinux.cfg with options for text/graphical menus, kernel parameters, and multi-boot entries.&lt;br /&gt;
&lt;br /&gt;
The reason we use this is because of legacy hardware, it is not meant for UEFI booting, we include it in Peppermint a as a bootloader primarily for BIOS-based booting of optical media (CDs/DVDs) and legacy compatibility&lt;br /&gt;
&lt;br /&gt;
===Files used for our configs are ===&lt;br /&gt;
Core Bootloader Files:&lt;br /&gt;
*isolinux.bin	Bootloader binary for BIOS systems. Required for El Torito bootable CDs.&lt;br /&gt;
*isolinux.cfg	Configuration file defining boot menu entries, kernel paths, and parameters.&lt;br /&gt;
*boot.cat	Boot catalog file generated by mkisofs to list bootable images.&lt;br /&gt;
&lt;br /&gt;
Menu System Files&lt;br /&gt;
*vesamenu.c32	Graphical menu module for VESA-compatible splash screens.&lt;br /&gt;
*menu.cfg	Menu configuration (often included by isolinux.cfg for modularity).&lt;br /&gt;
*stdmenu.cfg	Standard menu template (optional).&lt;br /&gt;
*recovery.cfg	Menu entries for recovery/rescue modes.&lt;br /&gt;
*live.cfg	Configuration for live session boot options.&lt;br /&gt;
*utilities.cfg	Tools menu (e.g., memory tests, hardware diagnostics).&lt;br /&gt;
&lt;br /&gt;
Compatibility Modules:&lt;br /&gt;
*libcom32.c32	Core library for COM32 modules (required for advanced features).&lt;br /&gt;
*libmenu.c32	Menu-handling library.&lt;br /&gt;
*libutil.c32	Utility functions (e.g., file parsing).&lt;br /&gt;
*ldlinux.c32	Loader for SYSLINUX extensions.&lt;br /&gt;
&lt;br /&gt;
Hardware Utilities:&lt;br /&gt;
*hdt.c32	Hardware Detection Tool (lists CPU, RAM, PCI devices).&lt;br /&gt;
*pci.ids	Database of PCI hardware identifiers used by hdt.c32.&lt;br /&gt;
&lt;br /&gt;
Boot Process Flow&lt;br /&gt;
#BIOS Loads isolinux.bin: The El Torito boot sector points to isolinux.bin, which initializes the bootloader.&lt;br /&gt;
#Read isolinux.cfg: Defines boot entries (e.g., &amp;quot;Live Session&amp;quot; or &amp;quot;Install&amp;quot;) and kernel parameters.&lt;br /&gt;
#Load Modules: &lt;br /&gt;
##vesamenu.c32 renders graphical menus.&lt;br /&gt;
##hdt.c32 provides hardware diagnostics.&lt;br /&gt;
#Launch Kernel:Specified by KERNEL directives in isolinux.cfg (e.g., /boot/vmlinuz).&lt;br /&gt;
&lt;br /&gt;
===Example isolinux.cfg Structure===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEFAULT vesamenu.c32&lt;br /&gt;
PROMPT 0&lt;br /&gt;
TIMEOUT 300&lt;br /&gt;
&lt;br /&gt;
MENU TITLE Boot Menu&lt;br /&gt;
MENU INCLUDE stdmenu.cfg&lt;br /&gt;
&lt;br /&gt;
LABEL live&lt;br /&gt;
  MENU LABEL ^Start Live Session&lt;br /&gt;
  KERNEL /boot/vmlinuz&lt;br /&gt;
  APPEND initrd=/boot/initrd.img root=/dev/sr0&lt;br /&gt;
&lt;br /&gt;
LABEL recovery&lt;br /&gt;
  MENU LABEL ^Recovery Mode&lt;br /&gt;
  KERNEL /boot/vmlinuz&lt;br /&gt;
  APPEND initrd=/boot/initrd.img single&lt;br /&gt;
&lt;br /&gt;
MENU INCLUDE utilities.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Configure Grub==&lt;br /&gt;
GRUB is required for UEFI systems because it provides native UEFI compatibility, which ISOLINUX lacks. Peppermit also needs to include the grub configurations&lt;br /&gt;
&lt;br /&gt;
===boot/grub/ Directory (GRUB Configuration)===&lt;br /&gt;
*grub.cfg	Main GRUB configuration for UEFI/BIOS booting. Contains boot menu entries and kernel parameters.&lt;br /&gt;
*config.cfg	Custom configuration (likely sourced by grub.cfg). Used to modularize settings (e.g., variables, device detection).&lt;br /&gt;
*install.cfg	Installer-specific configuration (e.g., kernel paths for Debian/Ubuntu installations).&lt;br /&gt;
*install_start.cfg	Pre-installation boot logic (e.g., hardware checks or initramfs setup).&lt;br /&gt;
*loopback.cfg	Loopback boot configuration for ISO-based installations (e.g., loopback loop /cdrom/image.iso).&lt;br /&gt;
*theme.cfg	GRUB theme settings (fonts, colors, backgrounds).&lt;br /&gt;
&lt;br /&gt;
===Example grub.cfg===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
menuentry &amp;quot;Live ISO&amp;quot; {&lt;br /&gt;
  set root=(hd0,1)&lt;br /&gt;
  loopback loop /iso/image.iso&lt;br /&gt;
  linux (loop)/boot/vmlinuz boot=live&lt;br /&gt;
  initrd (loop)/boot/initrd.img&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example theme.cfg===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set theme=/boot/grub/themes/custom/theme.txt  # Defined in theme.cfg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===Example loopback.cfg===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
menuentry &amp;quot;Boot ISO&amp;quot; {&lt;br /&gt;
  loopback loop (hd1)/path/to/image.iso&lt;br /&gt;
  linux (loop)/casper/vmlinuz boot=casper&lt;br /&gt;
  initrd (loop)/casper/initrd.img&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Live System==&lt;br /&gt;
The live folder in a Linux ISO is critical for live system functionality, which allows users to boot and run an operating system directly from media (USB/CD) without installation. &lt;br /&gt;
&lt;br /&gt;
===Core Live System Files===&lt;br /&gt;
The live folder contains key components for booting a functional OS:&lt;br /&gt;
*Filesystem.squashfs: Compressed read-only OS root filesystem (includes /bin, /usr, etc.)[^2^][^5^].&lt;br /&gt;
**vmlinuz: Linux kernel loaded during boot[^2^][^5^].&lt;br /&gt;
**initrd.img: Initial RAM disk with tools to mount SquashFS and initialize hardware[^2^][^5^].&lt;br /&gt;
&lt;br /&gt;
===How It Works===&lt;br /&gt;
*Boot Process:&lt;br /&gt;
**GRUB/ISOLINUX loads vmlinuz and initrd.img, which decompress filesystem.squashfs into RAM or a temporary disk layer[^2^][^5^].&lt;br /&gt;
*Union Mounts:&lt;br /&gt;
**Combines the read-only SquashFS with a writeable layer (e.g., tmpfs in RAM or casper-rw for persistence)[^2^][^5^].&lt;br /&gt;
&lt;br /&gt;
===Use Cases===&lt;br /&gt;
*Testing/Portability:&lt;br /&gt;
**Run Linux without altering the host system’s disk[^3^][^5^].&lt;br /&gt;
*System Recovery:&lt;br /&gt;
**Access broken systems via live tools (e.g., gparted, fsck)[^3^][^8^].&lt;br /&gt;
*Installation:&lt;br /&gt;
**Many installers (e.g., Ubuntu) run as live sessions before writing to disk[^1^][^5^].&lt;br /&gt;
===Persistence (Optional)===&lt;br /&gt;
*casper-rw File/Partition:&lt;br /&gt;
**Stores user data (e.g., installed apps, files) across reboots[^2^][^5^].&lt;br /&gt;
**Non-Persistent Mode:&lt;br /&gt;
*Changes are discarded after shutdown (uses RAM for temporary writes)[^2^].&lt;br /&gt;
&lt;br /&gt;
===Example Folder structure===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/live/&lt;br /&gt;
├── filesystem.squashfs  # OS root (compressed)&lt;br /&gt;
├── vmlinuz              # Kernel&lt;br /&gt;
└── initrd.img           # Initial RAM disk&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Make the filesystem.squashfs==&lt;br /&gt;
filesystem.squashfs is a compressed, read-only filesystem image used in Linux live environments (inthis case Debian) and embedded systems. &lt;br /&gt;
Here&#039;s a structured breakdown:&lt;br /&gt;
*Compression: Uses algorithms like zlib, lz4, lzo, xz, or zstd to minimize size.&lt;br /&gt;
*Read-Only: Protects system integrity by preventing writes to the base OS.&lt;br /&gt;
*Efficiency:&lt;br /&gt;
**Small inodes: ~8 bytes per inode (directory/file metadata).&lt;br /&gt;
**Block sizes: Up to 1 MB (default 128 KB) for better compression ratios.&lt;br /&gt;
&lt;br /&gt;
We use this as it enables booting an OS directly from USB/CD without installation&lt;br /&gt;
&lt;br /&gt;
===Example command===&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mksquashfs /pathto your chroot /path to save the/live/filesystem.squashfs -comp xz -e boot&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#Generate with mksquashfs&lt;br /&gt;
#Uses XZ compression (high ratio, slower than alternatives like lz4 or zstd). that is -comp xz&lt;br /&gt;
#Excludes the /boot directory from the image (common for ISOs where boot files are stored separately in /isolinux/ or /boot/grub/) that is -e boot&lt;br /&gt;
&lt;br /&gt;
==Compile the ISO==&lt;br /&gt;
In this case we use xorriso. This is a command-line tool for creating, modifying, and burning ISO 9660 filesystem images. It serves as both a standalone ISO manipulator and a modern replacement for older tools like mkisofs and genisoimage&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo xorriso -as mkisofs -o ./yourisoname.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -R -V &amp;quot;YourISO&amp;quot; -follow-links ./iso_configs&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lets break down the commands&lt;br /&gt;
&lt;br /&gt;
#xorriso -as mkisofs - Emulates mkisofs behavior for compatibility with legacy ISO creation workflows&lt;br /&gt;
#-o ./yourisoname.iso  - Specifies the output ISO filename (mylive.iso in the current directory)&lt;br /&gt;
#-b isolinux/isolinux.bin - Sets BIOS boot image (ISOLINUX bootloader)&lt;br /&gt;
#-c isolinux/boot.cat - Specifies the boot catalog path (required for El Torito BIOS booting)&lt;br /&gt;
#-no-emul-boot - Boots directly from isolinux.bin without emulating a floppy disk&lt;br /&gt;
#-boot-load-size 4 - Loads 4 sectors (512B each) of isolinux.bin into memory (historical requirement for older BIOSes)&lt;br /&gt;
#-boot-info-table - Embeds a BIOS boot information table (required by ISOLINUX)&lt;br /&gt;
#-eltorito-alt-boot- Enables dual boot entries (BIOS + UEFI) in the ISO&#039;s El Torito catalog&lt;br /&gt;
#--e boot/grub/efi.img - Points UEFI firmware to the GRUB EFI binary within the ISO&lt;br /&gt;
#-R  - Enables Rock Ridge extensions for Unix permissions/long filenames &lt;br /&gt;
#-V &amp;quot;YourISO&amp;quot; -Sets the volume label&lt;br /&gt;
#-follow-links - Preserves symbolic links instead of copying their targets&lt;br /&gt;
#./iso_configs - Source directory containing files to include in the ISO&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=1043</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=1043"/>
		<updated>2025-06-19T13:24:29Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* BIOS and UEFI Fundamentals */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity...&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
This section will help explain what tools are available for filesystem management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools for Manipulating Filesystems mkfs and fsck==&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This command erases all data on /dev/sdb1 and creates a fresh ext4 filesystem. Similarly, to create an XFS filesystem, you would use:&lt;br /&gt;
 sudo mkfs.xfs /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
Once filesystems are in use, the fsck (filesystem check) tool helps maintain their integrity. fsck scans the filesystem for inconsistencies and can repair many types of corruption. The command automatically detects the filesystem type, but you can also use filesystem-specific versions like fsck.ext4 or fsck.xfs. For example, to check and repair an ext4 filesystem, you might run:&lt;br /&gt;
 sudo fsck.ext4 -y /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
The -y flag automatically answers &amp;quot;yes&amp;quot; to any prompts, allowing the tool to fix issues without user intervention.&lt;br /&gt;
&lt;br /&gt;
==Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore==&lt;br /&gt;
For ext4 filesystems, several specialized tools exist for maintenance and management. The tune2fs command allows you to adjust filesystem parameters after creation. For instance, you can change the maximum mount count before a forced check is required:&lt;br /&gt;
 sudo tune2fs -c 30 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This sets the maximum mount count to 30, meaning the filesystem will be checked after every 30 mounts.&lt;br /&gt;
&lt;br /&gt;
To examine detailed information about an ext4 filesystem, dumpe2fs is invaluable. It prints out superblock details, block group information, and more. For example:&lt;br /&gt;
 sudo dumpe2fs /dev/sdb1 | less&lt;br /&gt;
&lt;br /&gt;
This command provides a scrollable view of the filesystem’s internal structure.&lt;br /&gt;
&lt;br /&gt;
For backup and recovery, the dump and restore utilities are used. dump creates a backup archive of a filesystem, while restore can extract files or entire filesystems from that archive. A typical backup command might be:&lt;br /&gt;
 sudo dump -0uf /backup/sdb1.dump /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This performs a level-0 (full) backup of /dev/sdb1 to /backup/sdb1.dump. To restore from this backup, you would use:&lt;br /&gt;
 cd /mnt/restorepoint&lt;br /&gt;
 sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
cd /mnt/restorepoint&lt;br /&gt;
sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
This command restores the contents of the dump archive to the specified directory.&lt;br /&gt;
&lt;br /&gt;
Tools for Manipulating XFS: xfs_info, xfs_check, xfs_repair, xfsdump, xfsrestore&lt;br /&gt;
&lt;br /&gt;
XFS filesystems have their own suite of management tools. xfs_info displays detailed information about an XFS filesystem, such as its geometry and configuration. For example:&lt;br /&gt;
 sudo xfs_info /mnt/data&lt;br /&gt;
&lt;br /&gt;
If you suspect corruption, xfs_check (now deprecated in favor of xfs_repair) and xfs_repair are used to verify and fix filesystem problems. Always unmount the filesystem before running these tools. For example:&lt;br /&gt;
 sudo umount /mnt/data&lt;br /&gt;
 sudo xfs_repair /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
For backup and restore, xfsdump and xfsrestore are used. xfsdump creates a backup of the filesystem, while xfsrestore restores it. For instance:&lt;br /&gt;
 sudo xfsdump -l 0 -f /backup/xfs.dump /mnt/data&lt;br /&gt;
 sudo xfsrestore -f /backup/xfs.dump /mnt/restore&lt;br /&gt;
&lt;br /&gt;
This sequence backs up the /mnt/data filesystem and restores it to /mnt/restore.&lt;br /&gt;
&lt;br /&gt;
==Tools to Manipulate Basic Btrfs: Subvolumes and Snapshots==&lt;br /&gt;
Btrfs is a modern filesystem that supports advanced features like subvolumes and snapshots. Subvolumes are separate, mountable parts of the filesystem, while snapshots are read-only or read-write copies of subvolumes at a point in time. To create a subvolume, use:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs subvolume create /mnt/data/subvol1&lt;br /&gt;
&lt;br /&gt;
To create a snapshot of this subvolume:&lt;br /&gt;
 sudo btrfs subvolume snapshot /mnt/data/subvol1 /mnt/data/snapshots/subvol1_snap&lt;br /&gt;
&lt;br /&gt;
These features are useful for backups, testing, and system rollbacks.&lt;br /&gt;
&lt;br /&gt;
==Convert and Manipulate ext4 Filesystems to Btrfs: btrfs, btrfs-convert==&lt;br /&gt;
&lt;br /&gt;
If you wish to convert an existing ext2, ext3, or ext4 filesystem to Btrfs without losing data, the btrfs-convert tool is available. It preserves the original data and allows you to roll back if needed. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs-convert /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
After conversion, you can use the btrfs command suite to manage the filesystem, create subvolumes, take snapshots, and more.&lt;br /&gt;
&lt;br /&gt;
==Monitoring the Health of HDD and SSD: smartd, smartctl==&lt;br /&gt;
SMART (Self-Monitoring, Analysis, and Reporting Technology) tools help you monitor and predict hardware failures in storage devices. The smartctl command provides detailed information about a disk’s health, including temperature, error logs, and test results. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo smartctl -a /dev/sda&lt;br /&gt;
&lt;br /&gt;
This outputs all available SMART data for the device. To run a long self-test:&lt;br /&gt;
 sudo smartctl -t long /dev/sda&lt;br /&gt;
&lt;br /&gt;
For continuous monitoring, the smartd daemon can be enabled. It regularly checks all configured drives and can send notifications if problems are detected. To enable it, edit /etc/smartd.conf as needed and start the service:&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl enable --now smartd&lt;br /&gt;
&lt;br /&gt;
This proactive monitoring helps you catch disk failures before they lead to data loss.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=853</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=853"/>
		<updated>2025-05-01T01:20:50Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Building the Kernel and Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
This section will help explain what tools are available for filesystem management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools for Manipulating Filesystems mkfs and fsck==&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This command erases all data on /dev/sdb1 and creates a fresh ext4 filesystem. Similarly, to create an XFS filesystem, you would use:&lt;br /&gt;
 sudo mkfs.xfs /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
Once filesystems are in use, the fsck (filesystem check) tool helps maintain their integrity. fsck scans the filesystem for inconsistencies and can repair many types of corruption. The command automatically detects the filesystem type, but you can also use filesystem-specific versions like fsck.ext4 or fsck.xfs. For example, to check and repair an ext4 filesystem, you might run:&lt;br /&gt;
 sudo fsck.ext4 -y /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
The -y flag automatically answers &amp;quot;yes&amp;quot; to any prompts, allowing the tool to fix issues without user intervention.&lt;br /&gt;
&lt;br /&gt;
==Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore==&lt;br /&gt;
For ext4 filesystems, several specialized tools exist for maintenance and management. The tune2fs command allows you to adjust filesystem parameters after creation. For instance, you can change the maximum mount count before a forced check is required:&lt;br /&gt;
 sudo tune2fs -c 30 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This sets the maximum mount count to 30, meaning the filesystem will be checked after every 30 mounts.&lt;br /&gt;
&lt;br /&gt;
To examine detailed information about an ext4 filesystem, dumpe2fs is invaluable. It prints out superblock details, block group information, and more. For example:&lt;br /&gt;
 sudo dumpe2fs /dev/sdb1 | less&lt;br /&gt;
&lt;br /&gt;
This command provides a scrollable view of the filesystem’s internal structure.&lt;br /&gt;
&lt;br /&gt;
For backup and recovery, the dump and restore utilities are used. dump creates a backup archive of a filesystem, while restore can extract files or entire filesystems from that archive. A typical backup command might be:&lt;br /&gt;
 sudo dump -0uf /backup/sdb1.dump /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This performs a level-0 (full) backup of /dev/sdb1 to /backup/sdb1.dump. To restore from this backup, you would use:&lt;br /&gt;
 cd /mnt/restorepoint&lt;br /&gt;
 sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
cd /mnt/restorepoint&lt;br /&gt;
sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
This command restores the contents of the dump archive to the specified directory.&lt;br /&gt;
&lt;br /&gt;
Tools for Manipulating XFS: xfs_info, xfs_check, xfs_repair, xfsdump, xfsrestore&lt;br /&gt;
&lt;br /&gt;
XFS filesystems have their own suite of management tools. xfs_info displays detailed information about an XFS filesystem, such as its geometry and configuration. For example:&lt;br /&gt;
 sudo xfs_info /mnt/data&lt;br /&gt;
&lt;br /&gt;
If you suspect corruption, xfs_check (now deprecated in favor of xfs_repair) and xfs_repair are used to verify and fix filesystem problems. Always unmount the filesystem before running these tools. For example:&lt;br /&gt;
 sudo umount /mnt/data&lt;br /&gt;
 sudo xfs_repair /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
For backup and restore, xfsdump and xfsrestore are used. xfsdump creates a backup of the filesystem, while xfsrestore restores it. For instance:&lt;br /&gt;
 sudo xfsdump -l 0 -f /backup/xfs.dump /mnt/data&lt;br /&gt;
 sudo xfsrestore -f /backup/xfs.dump /mnt/restore&lt;br /&gt;
&lt;br /&gt;
This sequence backs up the /mnt/data filesystem and restores it to /mnt/restore.&lt;br /&gt;
&lt;br /&gt;
==Tools to Manipulate Basic Btrfs: Subvolumes and Snapshots==&lt;br /&gt;
Btrfs is a modern filesystem that supports advanced features like subvolumes and snapshots. Subvolumes are separate, mountable parts of the filesystem, while snapshots are read-only or read-write copies of subvolumes at a point in time. To create a subvolume, use:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs subvolume create /mnt/data/subvol1&lt;br /&gt;
&lt;br /&gt;
To create a snapshot of this subvolume:&lt;br /&gt;
 sudo btrfs subvolume snapshot /mnt/data/subvol1 /mnt/data/snapshots/subvol1_snap&lt;br /&gt;
&lt;br /&gt;
These features are useful for backups, testing, and system rollbacks.&lt;br /&gt;
&lt;br /&gt;
==Convert and Manipulate ext4 Filesystems to Btrfs: btrfs, btrfs-convert==&lt;br /&gt;
&lt;br /&gt;
If you wish to convert an existing ext2, ext3, or ext4 filesystem to Btrfs without losing data, the btrfs-convert tool is available. It preserves the original data and allows you to roll back if needed. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs-convert /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
After conversion, you can use the btrfs command suite to manage the filesystem, create subvolumes, take snapshots, and more.&lt;br /&gt;
&lt;br /&gt;
==Monitoring the Health of HDD and SSD: smartd, smartctl==&lt;br /&gt;
SMART (Self-Monitoring, Analysis, and Reporting Technology) tools help you monitor and predict hardware failures in storage devices. The smartctl command provides detailed information about a disk’s health, including temperature, error logs, and test results. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo smartctl -a /dev/sda&lt;br /&gt;
&lt;br /&gt;
This outputs all available SMART data for the device. To run a long self-test:&lt;br /&gt;
 sudo smartctl -t long /dev/sda&lt;br /&gt;
&lt;br /&gt;
For continuous monitoring, the smartd daemon can be enabled. It regularly checks all configured drives and can send notifications if problems are detected. To enable it, edit /etc/smartd.conf as needed and start the service:&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl enable --now smartd&lt;br /&gt;
&lt;br /&gt;
This proactive monitoring helps you catch disk failures before they lead to data loss.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=852</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=852"/>
		<updated>2025-05-01T01:20:36Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Installing the Kernel and Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
This section will help explain what tools are available for filesystem management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools for Manipulating Filesystems mkfs and fsck==&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This command erases all data on /dev/sdb1 and creates a fresh ext4 filesystem. Similarly, to create an XFS filesystem, you would use:&lt;br /&gt;
 sudo mkfs.xfs /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
Once filesystems are in use, the fsck (filesystem check) tool helps maintain their integrity. fsck scans the filesystem for inconsistencies and can repair many types of corruption. The command automatically detects the filesystem type, but you can also use filesystem-specific versions like fsck.ext4 or fsck.xfs. For example, to check and repair an ext4 filesystem, you might run:&lt;br /&gt;
 sudo fsck.ext4 -y /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
The -y flag automatically answers &amp;quot;yes&amp;quot; to any prompts, allowing the tool to fix issues without user intervention.&lt;br /&gt;
&lt;br /&gt;
==Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore==&lt;br /&gt;
For ext4 filesystems, several specialized tools exist for maintenance and management. The tune2fs command allows you to adjust filesystem parameters after creation. For instance, you can change the maximum mount count before a forced check is required:&lt;br /&gt;
 sudo tune2fs -c 30 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This sets the maximum mount count to 30, meaning the filesystem will be checked after every 30 mounts.&lt;br /&gt;
&lt;br /&gt;
To examine detailed information about an ext4 filesystem, dumpe2fs is invaluable. It prints out superblock details, block group information, and more. For example:&lt;br /&gt;
 sudo dumpe2fs /dev/sdb1 | less&lt;br /&gt;
&lt;br /&gt;
This command provides a scrollable view of the filesystem’s internal structure.&lt;br /&gt;
&lt;br /&gt;
For backup and recovery, the dump and restore utilities are used. dump creates a backup archive of a filesystem, while restore can extract files or entire filesystems from that archive. A typical backup command might be:&lt;br /&gt;
 sudo dump -0uf /backup/sdb1.dump /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This performs a level-0 (full) backup of /dev/sdb1 to /backup/sdb1.dump. To restore from this backup, you would use:&lt;br /&gt;
 cd /mnt/restorepoint&lt;br /&gt;
 sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
cd /mnt/restorepoint&lt;br /&gt;
sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
This command restores the contents of the dump archive to the specified directory.&lt;br /&gt;
&lt;br /&gt;
Tools for Manipulating XFS: xfs_info, xfs_check, xfs_repair, xfsdump, xfsrestore&lt;br /&gt;
&lt;br /&gt;
XFS filesystems have their own suite of management tools. xfs_info displays detailed information about an XFS filesystem, such as its geometry and configuration. For example:&lt;br /&gt;
 sudo xfs_info /mnt/data&lt;br /&gt;
&lt;br /&gt;
If you suspect corruption, xfs_check (now deprecated in favor of xfs_repair) and xfs_repair are used to verify and fix filesystem problems. Always unmount the filesystem before running these tools. For example:&lt;br /&gt;
 sudo umount /mnt/data&lt;br /&gt;
 sudo xfs_repair /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
For backup and restore, xfsdump and xfsrestore are used. xfsdump creates a backup of the filesystem, while xfsrestore restores it. For instance:&lt;br /&gt;
 sudo xfsdump -l 0 -f /backup/xfs.dump /mnt/data&lt;br /&gt;
 sudo xfsrestore -f /backup/xfs.dump /mnt/restore&lt;br /&gt;
&lt;br /&gt;
This sequence backs up the /mnt/data filesystem and restores it to /mnt/restore.&lt;br /&gt;
&lt;br /&gt;
==Tools to Manipulate Basic Btrfs: Subvolumes and Snapshots==&lt;br /&gt;
Btrfs is a modern filesystem that supports advanced features like subvolumes and snapshots. Subvolumes are separate, mountable parts of the filesystem, while snapshots are read-only or read-write copies of subvolumes at a point in time. To create a subvolume, use:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs subvolume create /mnt/data/subvol1&lt;br /&gt;
&lt;br /&gt;
To create a snapshot of this subvolume:&lt;br /&gt;
 sudo btrfs subvolume snapshot /mnt/data/subvol1 /mnt/data/snapshots/subvol1_snap&lt;br /&gt;
&lt;br /&gt;
These features are useful for backups, testing, and system rollbacks.&lt;br /&gt;
&lt;br /&gt;
==Convert and Manipulate ext4 Filesystems to Btrfs: btrfs, btrfs-convert==&lt;br /&gt;
&lt;br /&gt;
If you wish to convert an existing ext2, ext3, or ext4 filesystem to Btrfs without losing data, the btrfs-convert tool is available. It preserves the original data and allows you to roll back if needed. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs-convert /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
After conversion, you can use the btrfs command suite to manage the filesystem, create subvolumes, take snapshots, and more.&lt;br /&gt;
&lt;br /&gt;
==Monitoring the Health of HDD and SSD: smartd, smartctl==&lt;br /&gt;
SMART (Self-Monitoring, Analysis, and Reporting Technology) tools help you monitor and predict hardware failures in storage devices. The smartctl command provides detailed information about a disk’s health, including temperature, error logs, and test results. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo smartctl -a /dev/sda&lt;br /&gt;
&lt;br /&gt;
This outputs all available SMART data for the device. To run a long self-test:&lt;br /&gt;
 sudo smartctl -t long /dev/sda&lt;br /&gt;
&lt;br /&gt;
For continuous monitoring, the smartd daemon can be enabled. It regularly checks all configured drives and can send notifications if problems are detected. To enable it, edit /etc/smartd.conf as needed and start the service:&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl enable --now smartd&lt;br /&gt;
&lt;br /&gt;
This proactive monitoring helps you catch disk failures before they lead to data loss.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=851</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=851"/>
		<updated>2025-05-01T01:20:26Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Installing the Kernel and Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
This section will help explain what tools are available for filesystem management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools for Manipulating Filesystems mkfs and fsck==&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This command erases all data on /dev/sdb1 and creates a fresh ext4 filesystem. Similarly, to create an XFS filesystem, you would use:&lt;br /&gt;
 sudo mkfs.xfs /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
Once filesystems are in use, the fsck (filesystem check) tool helps maintain their integrity. fsck scans the filesystem for inconsistencies and can repair many types of corruption. The command automatically detects the filesystem type, but you can also use filesystem-specific versions like fsck.ext4 or fsck.xfs. For example, to check and repair an ext4 filesystem, you might run:&lt;br /&gt;
 sudo fsck.ext4 -y /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
The -y flag automatically answers &amp;quot;yes&amp;quot; to any prompts, allowing the tool to fix issues without user intervention.&lt;br /&gt;
&lt;br /&gt;
==Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore==&lt;br /&gt;
For ext4 filesystems, several specialized tools exist for maintenance and management. The tune2fs command allows you to adjust filesystem parameters after creation. For instance, you can change the maximum mount count before a forced check is required:&lt;br /&gt;
 sudo tune2fs -c 30 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This sets the maximum mount count to 30, meaning the filesystem will be checked after every 30 mounts.&lt;br /&gt;
&lt;br /&gt;
To examine detailed information about an ext4 filesystem, dumpe2fs is invaluable. It prints out superblock details, block group information, and more. For example:&lt;br /&gt;
 sudo dumpe2fs /dev/sdb1 | less&lt;br /&gt;
&lt;br /&gt;
This command provides a scrollable view of the filesystem’s internal structure.&lt;br /&gt;
&lt;br /&gt;
For backup and recovery, the dump and restore utilities are used. dump creates a backup archive of a filesystem, while restore can extract files or entire filesystems from that archive. A typical backup command might be:&lt;br /&gt;
 sudo dump -0uf /backup/sdb1.dump /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This performs a level-0 (full) backup of /dev/sdb1 to /backup/sdb1.dump. To restore from this backup, you would use:&lt;br /&gt;
 cd /mnt/restorepoint&lt;br /&gt;
 sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
cd /mnt/restorepoint&lt;br /&gt;
sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
This command restores the contents of the dump archive to the specified directory.&lt;br /&gt;
&lt;br /&gt;
Tools for Manipulating XFS: xfs_info, xfs_check, xfs_repair, xfsdump, xfsrestore&lt;br /&gt;
&lt;br /&gt;
XFS filesystems have their own suite of management tools. xfs_info displays detailed information about an XFS filesystem, such as its geometry and configuration. For example:&lt;br /&gt;
 sudo xfs_info /mnt/data&lt;br /&gt;
&lt;br /&gt;
If you suspect corruption, xfs_check (now deprecated in favor of xfs_repair) and xfs_repair are used to verify and fix filesystem problems. Always unmount the filesystem before running these tools. For example:&lt;br /&gt;
 sudo umount /mnt/data&lt;br /&gt;
 sudo xfs_repair /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
For backup and restore, xfsdump and xfsrestore are used. xfsdump creates a backup of the filesystem, while xfsrestore restores it. For instance:&lt;br /&gt;
 sudo xfsdump -l 0 -f /backup/xfs.dump /mnt/data&lt;br /&gt;
 sudo xfsrestore -f /backup/xfs.dump /mnt/restore&lt;br /&gt;
&lt;br /&gt;
This sequence backs up the /mnt/data filesystem and restores it to /mnt/restore.&lt;br /&gt;
&lt;br /&gt;
==Tools to Manipulate Basic Btrfs: Subvolumes and Snapshots==&lt;br /&gt;
Btrfs is a modern filesystem that supports advanced features like subvolumes and snapshots. Subvolumes are separate, mountable parts of the filesystem, while snapshots are read-only or read-write copies of subvolumes at a point in time. To create a subvolume, use:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs subvolume create /mnt/data/subvol1&lt;br /&gt;
&lt;br /&gt;
To create a snapshot of this subvolume:&lt;br /&gt;
 sudo btrfs subvolume snapshot /mnt/data/subvol1 /mnt/data/snapshots/subvol1_snap&lt;br /&gt;
&lt;br /&gt;
These features are useful for backups, testing, and system rollbacks.&lt;br /&gt;
&lt;br /&gt;
==Convert and Manipulate ext4 Filesystems to Btrfs: btrfs, btrfs-convert==&lt;br /&gt;
&lt;br /&gt;
If you wish to convert an existing ext2, ext3, or ext4 filesystem to Btrfs without losing data, the btrfs-convert tool is available. It preserves the original data and allows you to roll back if needed. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs-convert /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
After conversion, you can use the btrfs command suite to manage the filesystem, create subvolumes, take snapshots, and more.&lt;br /&gt;
&lt;br /&gt;
==Monitoring the Health of HDD and SSD: smartd, smartctl==&lt;br /&gt;
SMART (Self-Monitoring, Analysis, and Reporting Technology) tools help you monitor and predict hardware failures in storage devices. The smartctl command provides detailed information about a disk’s health, including temperature, error logs, and test results. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo smartctl -a /dev/sda&lt;br /&gt;
&lt;br /&gt;
This outputs all available SMART data for the device. To run a long self-test:&lt;br /&gt;
 sudo smartctl -t long /dev/sda&lt;br /&gt;
&lt;br /&gt;
For continuous monitoring, the smartd daemon can be enabled. It regularly checks all configured drives and can send notifications if problems are detected. To enable it, edit /etc/smartd.conf as needed and start the service:&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl enable --now smartd&lt;br /&gt;
&lt;br /&gt;
This proactive monitoring helps you catch disk failures before they lead to data loss.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=850</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=850"/>
		<updated>2025-05-01T01:03:12Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
This section will help explain what tools are available for filesystem management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools for Manipulating Filesystems mkfs and fsck==&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This command erases all data on /dev/sdb1 and creates a fresh ext4 filesystem. Similarly, to create an XFS filesystem, you would use:&lt;br /&gt;
 sudo mkfs.xfs /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
Once filesystems are in use, the fsck (filesystem check) tool helps maintain their integrity. fsck scans the filesystem for inconsistencies and can repair many types of corruption. The command automatically detects the filesystem type, but you can also use filesystem-specific versions like fsck.ext4 or fsck.xfs. For example, to check and repair an ext4 filesystem, you might run:&lt;br /&gt;
 sudo fsck.ext4 -y /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
The -y flag automatically answers &amp;quot;yes&amp;quot; to any prompts, allowing the tool to fix issues without user intervention.&lt;br /&gt;
&lt;br /&gt;
==Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore==&lt;br /&gt;
For ext4 filesystems, several specialized tools exist for maintenance and management. The tune2fs command allows you to adjust filesystem parameters after creation. For instance, you can change the maximum mount count before a forced check is required:&lt;br /&gt;
 sudo tune2fs -c 30 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This sets the maximum mount count to 30, meaning the filesystem will be checked after every 30 mounts.&lt;br /&gt;
&lt;br /&gt;
To examine detailed information about an ext4 filesystem, dumpe2fs is invaluable. It prints out superblock details, block group information, and more. For example:&lt;br /&gt;
 sudo dumpe2fs /dev/sdb1 | less&lt;br /&gt;
&lt;br /&gt;
This command provides a scrollable view of the filesystem’s internal structure.&lt;br /&gt;
&lt;br /&gt;
For backup and recovery, the dump and restore utilities are used. dump creates a backup archive of a filesystem, while restore can extract files or entire filesystems from that archive. A typical backup command might be:&lt;br /&gt;
 sudo dump -0uf /backup/sdb1.dump /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This performs a level-0 (full) backup of /dev/sdb1 to /backup/sdb1.dump. To restore from this backup, you would use:&lt;br /&gt;
 cd /mnt/restorepoint&lt;br /&gt;
 sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
cd /mnt/restorepoint&lt;br /&gt;
sudo restore -rf /backup/sdb1.dump&lt;br /&gt;
&lt;br /&gt;
This command restores the contents of the dump archive to the specified directory.&lt;br /&gt;
&lt;br /&gt;
Tools for Manipulating XFS: xfs_info, xfs_check, xfs_repair, xfsdump, xfsrestore&lt;br /&gt;
&lt;br /&gt;
XFS filesystems have their own suite of management tools. xfs_info displays detailed information about an XFS filesystem, such as its geometry and configuration. For example:&lt;br /&gt;
 sudo xfs_info /mnt/data&lt;br /&gt;
&lt;br /&gt;
If you suspect corruption, xfs_check (now deprecated in favor of xfs_repair) and xfs_repair are used to verify and fix filesystem problems. Always unmount the filesystem before running these tools. For example:&lt;br /&gt;
 sudo umount /mnt/data&lt;br /&gt;
 sudo xfs_repair /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
For backup and restore, xfsdump and xfsrestore are used. xfsdump creates a backup of the filesystem, while xfsrestore restores it. For instance:&lt;br /&gt;
 sudo xfsdump -l 0 -f /backup/xfs.dump /mnt/data&lt;br /&gt;
 sudo xfsrestore -f /backup/xfs.dump /mnt/restore&lt;br /&gt;
&lt;br /&gt;
This sequence backs up the /mnt/data filesystem and restores it to /mnt/restore.&lt;br /&gt;
&lt;br /&gt;
==Tools to Manipulate Basic Btrfs: Subvolumes and Snapshots==&lt;br /&gt;
Btrfs is a modern filesystem that supports advanced features like subvolumes and snapshots. Subvolumes are separate, mountable parts of the filesystem, while snapshots are read-only or read-write copies of subvolumes at a point in time. To create a subvolume, use:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs subvolume create /mnt/data/subvol1&lt;br /&gt;
&lt;br /&gt;
To create a snapshot of this subvolume:&lt;br /&gt;
 sudo btrfs subvolume snapshot /mnt/data/subvol1 /mnt/data/snapshots/subvol1_snap&lt;br /&gt;
&lt;br /&gt;
These features are useful for backups, testing, and system rollbacks.&lt;br /&gt;
&lt;br /&gt;
==Convert and Manipulate ext4 Filesystems to Btrfs: btrfs, btrfs-convert==&lt;br /&gt;
&lt;br /&gt;
If you wish to convert an existing ext2, ext3, or ext4 filesystem to Btrfs without losing data, the btrfs-convert tool is available. It preserves the original data and allows you to roll back if needed. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo btrfs-convert /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
After conversion, you can use the btrfs command suite to manage the filesystem, create subvolumes, take snapshots, and more.&lt;br /&gt;
&lt;br /&gt;
==Monitoring the Health of HDD and SSD: smartd, smartctl==&lt;br /&gt;
SMART (Self-Monitoring, Analysis, and Reporting Technology) tools help you monitor and predict hardware failures in storage devices. The smartctl command provides detailed information about a disk’s health, including temperature, error logs, and test results. For example:&lt;br /&gt;
&lt;br /&gt;
 sudo smartctl -a /dev/sda&lt;br /&gt;
&lt;br /&gt;
This outputs all available SMART data for the device. To run a long self-test:&lt;br /&gt;
 sudo smartctl -t long /dev/sda&lt;br /&gt;
&lt;br /&gt;
For continuous monitoring, the smartd daemon can be enabled. It regularly checks all configured drives and can send notifications if problems are detected. To enable it, edit /etc/smartd.conf as needed and start the service:&lt;br /&gt;
&lt;br /&gt;
 sudo systemctl enable --now smartd&lt;br /&gt;
&lt;br /&gt;
This proactive monitoring helps you catch disk failures before they lead to data loss.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=849</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=849"/>
		<updated>2025-05-01T00:59:56Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Filesystem managment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
This section will help explain what tools are available for filesystem management&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Tools for Manipulating Filesystems mkfs and fsck==&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This command erases all data on /dev/sdb1 and creates a fresh ext4 filesystem. Similarly, to create an XFS filesystem, you would use:&lt;br /&gt;
 sudo mkfs.xfs /dev/sdb2&lt;br /&gt;
&lt;br /&gt;
Once filesystems are in use, the fsck (filesystem check) tool helps maintain their integrity. fsck scans the filesystem for inconsistencies and can repair many types of corruption. The command automatically detects the filesystem type, but you can also use filesystem-specific versions like fsck.ext4 or fsck.xfs. For example, to check and repair an ext4 filesystem, you might run:&lt;br /&gt;
 sudo fsck.ext4 -y /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
The -y flag automatically answers &amp;quot;yes&amp;quot; to any prompts, allowing the tool to fix issues without user intervention.&lt;br /&gt;
&lt;br /&gt;
==Tools for Operating ext4: tune2fs, dumpe2fs, dump, restore==&lt;br /&gt;
For ext4 filesystems, several specialized tools exist for maintenance and management. The tune2fs command allows you to adjust filesystem parameters after creation. For instance, you can change the maximum mount count before a forced check is required:&lt;br /&gt;
 sudo tune2fs -c 30 /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This sets the maximum mount count to 30, meaning the filesystem will be checked after every 30 mounts.&lt;br /&gt;
&lt;br /&gt;
To examine detailed information about an ext4 filesystem, dumpe2fs is invaluable. It prints out superblock details, block group information, and more. For example:&lt;br /&gt;
 sudo dumpe2fs /dev/sdb1 | less&lt;br /&gt;
&lt;br /&gt;
This command provides a scrollable view of the filesystem’s internal structure.&lt;br /&gt;
&lt;br /&gt;
For backup and recovery, the dump and restore utilities are used. dump creates a backup archive of a filesystem, while restore can extract files or entire filesystems from that archive. A typical backup command might be:&lt;br /&gt;
 sudo dump -0uf /backup/sdb1.dump /dev/sdb1&lt;br /&gt;
&lt;br /&gt;
This performs a level-0 (full) backup of /dev/sdb1 to /backup/sdb1.dump. To restore from this backup, you would use:&lt;br /&gt;
 cd /mnt/restorepoint&lt;br /&gt;
 sudo restore -rf /backup/sdb1.dump&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=848</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=848"/>
		<updated>2025-05-01T00:57:05Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Filesystem managment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
Tools for Manipulating Filesystems mkfs and fsck&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
 sudo mkfs.ext4 /dev/sdb1&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=847</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=847"/>
		<updated>2025-05-01T00:56:56Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Filesystem managment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;br /&gt;
Tools for Manipulating Filesystems mkfs and fsck&lt;br /&gt;
The mkfs (make filesystem) utility is used to create a new filesystem on a storage device or partition. It acts as a front-end to filesystem-specific commands such as mkfs.ext4, mkfs.xfs, or mkfs.vfat. For example, if you want to format a partition as ext4, you would run:&lt;br /&gt;
    sudo mkfs.ext4 /dev/sdb1&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=846</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=846"/>
		<updated>2025-04-30T08:15:38Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Using UUIDs to Identify and Mount Filesystems */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;br /&gt;
&lt;br /&gt;
=Filesystem managment=&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=845</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=845"/>
		<updated>2025-04-30T08:10:34Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Filesystem setup and mount */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;br /&gt;
The /etc/fstab file, known as the file system table, is a critical configuration file in Linux systems. It defines how and where disk partitions, block devices, and remote file systems should be mounted, particularly during system boot. Each line in /etc/fstab represents a single file system and includes six fields: the device identifier (such as a device file, UUID, or label), the mount point, the file system type, mount options, a dump flag for backups, and the fsck order for file system checks at boot. Using UUIDs or PARTUUIDs to identify devices is recommended, as device names like /dev/sda1 can change between boots, leading to potential mounting errors&lt;br /&gt;
&lt;br /&gt;
==Mounting and Unmounting Filesystems==&lt;br /&gt;
To manually mount a file system, the mount command is used. It attaches the specified device to a directory in the file system hierarchy, known as the mount point. For example, mount /dev/sdb1 /mnt/data mounts the device /dev/sdb1 at /mnt/data. To detach, the umount command is used, specifying either the device or the mount point. If a file system is busy, unmounting will fail unless the -l (lazy) or -f (force) options are used. The current mount status can be checked with /etc/mtab or /proc/mounts, which list all active mounts. On modern systems, systemd also manages mounts and can influence the mount order, which is important for ensuring that dependencies between file systems are respected during boot.&lt;br /&gt;
&lt;br /&gt;
==Managing Swap Partitions and Files==&lt;br /&gt;
Swap space can be provided either by a dedicated partition or a swap file. The mkswap command is used to initialize a swap area on a device or file. To enable swap, the swapon command activates it, while swapoff deactivates it. Swap entries can also be defined in /etc/fstab to ensure they are automatically enabled at boot. Proper management of swap is crucial for system performance, especially on systems with limited RAM.&lt;br /&gt;
&lt;br /&gt;
==Using UUIDs to Identify and Mount Filesystems==&lt;br /&gt;
UUIDs (Universally Unique Identifiers) provide a stable and unique way to identify storage devices and partitions. They are generated when a file system is created and are not affected by device name changes. Tools like blkid and lsblk can display UUIDs and other file system metadata. For example, blkid /dev/sda1 or lsblk -f will show the UUID, file system type, and label for the specified device. Using UUIDs in /etc/fstab ensures reliable mounting regardless of how the kernel assigns device names during boot.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The /etc/fstab file automates and standardizes the mounting of file systems and swap areas on Linux systems. Manual mounting and unmounting are performed with mount and umount, and the status of mounts can be checked with /etc/mtab and /proc/mounts. Swap management is handled with mkswap, swapon, and swapoff. To avoid issues with changing device names, UUIDs should be used to reference devices, which can be obtained with blkid and lsblk. This approach ensures a good and reliable storage configuration across reboots and hardware changes&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=844</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=844"/>
		<updated>2025-04-30T08:07:12Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Obtaining a Kernel Dump */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;br /&gt;
&lt;br /&gt;
=Filesystem setup and mount=&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=843</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=843"/>
		<updated>2025-04-30T08:05:52Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Management and troubleshooting during kernel execution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;br /&gt;
To obtain details about the currently running Linux kernel and its modules, several command-line utilities are available. The uname command is the most direct way to check the kernel version. Executing uname -r outputs the kernel release, while uname -a provides additional information such as the kernel name, version, and machine architecture. Another method is to inspect /proc/version, which contains the kernel build details. The /lib/modules/$(uname -r)/modules.dep file lists module dependencies for the current kernel version&lt;br /&gt;
&lt;br /&gt;
For kernel modules, utilities like depmod and modinfo are essential. depmod generates a list of module dependencies, which is crucial for module management. modinfo displays information about a specific kernel module, including its parameters, author, and description.&lt;br /&gt;
&lt;br /&gt;
==Loading and Unloading Kernel Modules==&lt;br /&gt;
Kernel modules can be managed manually using several utilities. insmod inserts a module into the kernel, but it does not resolve dependencies. modprobe is more advanced, as it automatically loads any dependencies required by the module. To view all loaded modules, lsmod lists them along with their sizes and usage counts. If you need to remove a module, rmmod unloads it from the kernel. modprobe -r can also be used to remove modules, handling dependencies as necessary.&lt;br /&gt;
&lt;br /&gt;
==Determining When a Module Can Be Unloaded==&lt;br /&gt;
A kernel module can be unloaded only if it is not in use by any processes or other modules. The lsmod command displays a usage count for each loaded module. If the usage count is zero, the module can typically be unloaded safely. Attempting to remove a module with active dependencies or usage will result in an error, preventing potential system instability.&lt;br /&gt;
&lt;br /&gt;
==Determining Module Parameters==&lt;br /&gt;
Modules often accept parameters at load time, which can be viewed using the modinfo command. This utility lists all parameters a module can receive. Additionally, configuration files in /etc/modprobe.d/ can be used to set persistent module parameters. These files allow administrators to specify options that are applied whenever a module is loaded.&lt;br /&gt;
&lt;br /&gt;
==Checking the Kernel Version==&lt;br /&gt;
The kernel version is most commonly checked using the uname -r command, which prints the release number of the running kernel&lt;br /&gt;
. More detailed information, including the build time and compiler version, is available with uname -a or by reading /proc/version. The /lib/modules/kernel-version/modules.dep file is also tied to the specific kernel version and contains information about module dependencies.&lt;br /&gt;
&lt;br /&gt;
==Loading Modules with Different Names==&lt;br /&gt;
Linux allows the system to load modules using aliases or alternative names instead of the actual file names. This is configured in files under /etc/modprobe.d/, where alias directives can map a device or module name to a specific module file. This mechanism is useful for hardware abstraction and compatibility with different naming conventions.&lt;br /&gt;
&lt;br /&gt;
==The /proc File System==&lt;br /&gt;
The /proc file system provides a virtual interface to kernel data structures. The /proc/sys/kernel/ directory contains tunable kernel parameters. These parameters can be modified at runtime using the sysctl utility or by editing /etc/sysctl.conf and files in /etc/sysctl.d/. Changes can be applied immediately with /sbin/sysctl.&lt;br /&gt;
&lt;br /&gt;
==Configuring initrd==&lt;br /&gt;
The initial RAM disk (initrd) is a temporary root file system loaded into memory during the boot process. Tools such as dracut, mkinitrd, and mkinitramfs are used to generate or update the initrd image. This image contains necessary drivers and modules required for booting, especially on systems with complex storage configurations.&lt;br /&gt;
&lt;br /&gt;
==The /sys File System (sysfs)==&lt;br /&gt;
The /sys file system, or sysfs, is a virtual file system that exposes kernel objects, device information, and module data to user space. It is typically mounted at /sys and provides detailed information about devices, drivers, and kernel subsystems. Unlike /dev, which provides device nodes for direct access, /sys is primarily for viewing and managing device attributes and relationships.&lt;br /&gt;
&lt;br /&gt;
==Contents of /boot and /lib/modules==&lt;br /&gt;
The /boot directory contains files required for the system to boot, such as the kernel image (vmlinuz), initial RAM disk images (initrd or initramfs), and bootloader configuration files. The /lib/modules/$(uname -r)/ directory stores all kernel modules for the current kernel version, along with dependency files and module configuration data.&lt;br /&gt;
&lt;br /&gt;
==Tools for Hardware Information==&lt;br /&gt;
Several command-line tools are available to analyze hardware information. dmesg prints kernel ring buffer messages, which include hardware initialization logs. lspci lists PCI devices, lsusb shows USB devices, and lsdev displays information about system devices. journalctl can be used to view system logs, including kernel and hardware events.&lt;br /&gt;
&lt;br /&gt;
==udev Rules and Module Configuration==&lt;br /&gt;
udev is the device manager for the Linux kernel, handling dynamic device node creation. Tools like udevmonitor and udevadm monitor allow real-time monitoring of device events. udev rules, stored in /etc/udev/, define how devices are named, what permissions they have, and which modules or scripts are triggered on device events. Module configuration files in /etc can specify options or aliases for modules, integrating with udev actions&lt;br /&gt;
&lt;br /&gt;
==Obtaining a Kernel Dump==&lt;br /&gt;
To capture a kernel dump for debugging, utilities such as kdump and kexec are used. kdump sets up a crash kernel and captures memory dumps when a kernel panic occurs. kexec allows booting into a new kernel directly from the running system, which is often used in conjunction with kdump for crash analysis. These tools help diagnose critical kernel failures by preserving system state at the time of a crash.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=842</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=842"/>
		<updated>2025-04-30T03:01:20Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Workflow Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Management and troubleshooting during kernel execution=&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=841</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=841"/>
		<updated>2025-04-30T02:59:40Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* What is Systemd? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd? - Systemd boot customization=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=840</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=840"/>
		<updated>2025-04-30T02:57:32Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Initrd Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Version-Specific Considerations==&lt;br /&gt;
*&#039;&#039;&#039;Kernel 2.6.x&#039;&#039;&#039;: Uses make oldconfig for backward compatibility.&lt;br /&gt;
*&#039;&#039;&#039;Kernel 5.x&#039;&#039;&#039;: Supports make menuconfig with modern features like CONFIG_KASAN for memory sanitization.&lt;br /&gt;
*&#039;&#039;&#039;Compression&#039;&#039;&#039;: Use CONFIG_KERNEL_XZ for xz compression (smaller size) or CONFIG_KERNEL_GZIP for faster decompression[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Download and Extract&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.7.tar.xz  &lt;br /&gt;
tar xvf linux-6.0.7.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-6.0.7  &lt;br /&gt;
make menuconfig  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc) &amp;amp;&amp;amp; sudo make modules_install &amp;amp;&amp;amp; sudo make install&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Bootloader&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=839</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=839"/>
		<updated>2025-04-30T02:54:07Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Initrd Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;: Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=838</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=838"/>
		<updated>2025-04-30T02:53:51Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* DKMS for Kernel Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
==Initrd Configuration==&lt;br /&gt;
&#039;&#039;&#039;Initial RAM Disk (initrd)&#039;&#039;&#039; loads critical modules before the root filesystem mounts:&lt;br /&gt;
*&#039;&#039;&#039;Generate with Dracut&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dracut --force /boot/initramfs-&amp;lt;version&amp;gt;.img &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Generate with mkinitramfs&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkinitramfs -o /boot/initrd.img-&amp;lt;version&amp;gt; &amp;lt;version&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Troubleshoot&#039;&#039;&#039;:&lt;br /&gt;
Use lsinitrd /boot/initramfs-&amp;lt;version&amp;gt;.img to verify included drivers[^prev^].&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=837</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=837"/>
		<updated>2025-04-30T02:51:21Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Installing the Kernel and Modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Bootloader Configuration==&lt;br /&gt;
After installation, update the bootloader to recognize the new kernel:&lt;br /&gt;
*&#039;&#039;&#039;GRUB&#039;&#039;&#039; (most distributions):&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo grub2-mkconfig -o /boot/grub2/grub.cfg&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;systemd-boot (UEFI systems)&#039;&#039;&#039;:&lt;br /&gt;
Add a new entry in /boot/efi/loader/entries/ referencing the kernel and initrd[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Module Configuration Files==&lt;br /&gt;
Module behavior is defined in:&lt;br /&gt;
*/etc/modprobe.d/: Contains override files (e.g., blacklist.conf to block problematic modules).&lt;br /&gt;
*/etc/modules-load.d/: Lists modules to load at boot (e.g., vfio.conf for virtualization)[^prev^].&lt;br /&gt;
&lt;br /&gt;
==DKMS for Kernel Modules==&lt;br /&gt;
&#039;&#039;&#039;Dynamic Kernel Module Support (DKMS)&#039;&#039;&#039; automates module rebuilding for new kernels:&lt;br /&gt;
*Add a Module:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms add -m nvidia -v 470.141.03&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Build and Install&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo dkms build -m nvidia -v 470.141.03  &lt;br /&gt;
sudo dkms install -m nvidia -v 470.141.03[7]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Verify Status&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;dkms status  # Shows installed modules and kernel compatibility[7]&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=836</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=836"/>
		<updated>2025-04-30T02:48:12Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Customizing Kernel Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;br /&gt;
&lt;br /&gt;
==Building the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Compile the Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Parallel build using all CPU cores[8]&amp;lt;/pre&amp;gt;&lt;br /&gt;
This generates vmlinux (uncompressed kernel) and arch/x86/boot/bzImage (bootable image).&lt;br /&gt;
* &#039;&#039;&#039;Build Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;make modules  # Compiles loadable modules (*.ko files)[9]&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Installing the Kernel and Modules==&lt;br /&gt;
*&#039;&#039;&#039;Install Modules&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make modules_install  # Copies modules to /lib/modules/&amp;lt;version&amp;gt;/[1][5]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install Kernel&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo make install  # Copies bzImage to /boot/vmlinuz-&amp;lt;version&amp;gt; and updates GRUB[1]&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Update Module Dependencies&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo depmod -a  # Generates /lib/modules/&amp;lt;version&amp;gt;/modules.dep[^prev^]&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=835</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=835"/>
		<updated>2025-04-30T02:44:18Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Customizing Kernel Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
*&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
**make menuconfig for an ncurses-based interface.&lt;br /&gt;
**make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
*&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=834</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=834"/>
		<updated>2025-04-30T02:43:54Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Customizing Kernel Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
#&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
*make menuconfig for an ncurses-based interface.&lt;br /&gt;
*make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
#&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=833</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=833"/>
		<updated>2025-04-30T02:43:43Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Kernel Makefile and Targets */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;br /&gt;
&lt;br /&gt;
==Customizing Kernel Configuration==&lt;br /&gt;
To modify the kernel configuration:&lt;br /&gt;
#&#039;&#039;&#039;Copy the Current Config&#039;&#039;&#039;:&lt;br /&gt;
&amp;lt;pre&amp;gt;cp /boot/config-$(uname -r) /usr/src/linux/.config  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#&#039;&#039;&#039;Launch Configuration Tools&#039;&#039;&#039;:&lt;br /&gt;
*make menuconfig for an ncurses-based interface.&lt;br /&gt;
*make xconfig for a Qt GUI (requires qt5-devel).&lt;br /&gt;
#&#039;&#039;&#039;Adjust Settings&#039;&#039;&#039;:&lt;br /&gt;
Enable/disable features like CONFIG_DEBUG_KERNEL for debugging or CONFIG_NET_VENDOR_INTEL for Intel NIC drivers.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=832</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=832"/>
		<updated>2025-04-30T02:41:18Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Compiling the Linux Kernel: Core Components and Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;br /&gt;
&lt;br /&gt;
==Kernel Makefile and Targets==&lt;br /&gt;
The &#039;&#039;&#039;Kernel Makefile&#039;&#039;&#039; orchestrates the compilation process. Key targets include:&lt;br /&gt;
&lt;br /&gt;
*all: Compiles the kernel (vmlinux) and modules (*.ko).&lt;br /&gt;
*config/menuconfig/xconfig: Configure kernel options via text/TUI/GUI interfaces.&lt;br /&gt;
*oldconfig: Updates an existing .config file to include new options while retaining user choices.&lt;br /&gt;
*mrproper: Cleans the source tree, including .config and generated files.&lt;br /&gt;
*bzImage: Generates a compressed kernel image for x86/x86_64 systems.&lt;br /&gt;
*modules/modules_install: Builds and installs loadable modules to /lib/modules/&amp;lt;version&amp;gt;/.&lt;br /&gt;
*rpm-pkg/deb-pkg: Creates distribution-specific packages for easy deployment.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=831</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=831"/>
		<updated>2025-04-30T02:39:31Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* /usr/src/linux/ Directory Structure */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
===/usr/src/linux/ Directory Structure===&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=830</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=830"/>
		<updated>2025-04-30T02:39:19Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Compiling the Linux Kernel: Core Components and Workflow */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;br /&gt;
==/usr/src/linux/ Directory Structure==&lt;br /&gt;
The /usr/src/linux/ directory typically contains the kernel source code, configuration files, and build artifacts. The .config file within this directory stores the kernel’s build configuration, including enabled features, drivers, and hardware support. This file is generated during the configuration phase (e.g., via make menuconfig) and defines compilation parameters such as processor architecture, filesystem support, and security settings.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=829</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=829"/>
		<updated>2025-04-30T02:38:42Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Practical Workflow Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;br /&gt;
&lt;br /&gt;
=Compiling the Linux Kernel: Core Components and Workflow=&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=828</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=828"/>
		<updated>2025-04-30T02:29:04Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Versioning and Distribution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;br /&gt;
&lt;br /&gt;
==Practical Workflow Example==&lt;br /&gt;
*&#039;&#039;&#039;Extract Kernel Sources:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;tar xvf linux-5.15.0.tar.xz -C /usr/src/&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Configure:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cd /usr/src/linux-5.15.0  &lt;br /&gt;
make menuconfig  # Enable/disable kernel features via TUI  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Compile:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;make -j$(nproc)  # Build kernel and modules  &lt;br /&gt;
make modules_install  # Install modules to /lib/modules/5.15.0/  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*&#039;&#039;&#039;Install:&#039;&#039;&#039;&lt;br /&gt;
&amp;lt;pre&amp;gt;cp arch/x86/boot/bzImage /boot/vmlinuz-5.15.0  &lt;br /&gt;
update-grub  # Update bootloader entries  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This structure ensures modularity, enabling efficient updates and hardware support across diverse systems&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=827</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=827"/>
		<updated>2025-04-30T02:27:01Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Kernel Module Management */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;br /&gt;
==Versioning and Distribution==&lt;br /&gt;
*&#039;&#039;&#039;Kernel Versioning&#039;&#039;&#039;: Follows x.y.z format (e.g., 5.15.0), where x is the major version, y the minor, and z the patch. Stable releases receive incremental patches (e.g., 5.15.1), while -rc suffixes denote release candidates (e.g., 5.16-rc3).&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Distributions&#039;&#039;&#039;: Ship customized kernels (e.g., Red Hat’s kernel-3.10.0-1160.el7.x86_64) with backported fixes and vendor-specific drivers. The uname -r command reveals the running kernel version.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=826</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=826"/>
		<updated>2025-04-30T02:26:16Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Kernel Module Management */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading&#039;&#039;&#039;: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection&#039;&#039;&#039;: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=825</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=825"/>
		<updated>2025-04-30T02:26:03Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* /usr/src/linux/Documentation/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Management==&lt;br /&gt;
Kernel modules are dynamically loaded components that extend kernel functionality (e.g., device drivers, filesystems). Key concepts include:&lt;br /&gt;
*&#039;&#039;&#039;Compilation&#039;&#039;&#039;: Modules are built using the kernel’s build system. A trivial module hello-1.ko might include:&lt;br /&gt;
&amp;lt;pre&amp;gt;#include &amp;lt;linux/module.h&amp;gt;  &lt;br /&gt;
MODULE_LICENSE(&amp;quot;GPL&amp;quot;);  &lt;br /&gt;
static int __init hello_init(void) { printk(&amp;quot;Hello, kernel\n&amp;quot;); return 0; }  &lt;br /&gt;
module_init(hello_init);  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Compilation requires a Makefile referencing the kernel’s build directory:&lt;br /&gt;
&amp;lt;pre&amp;gt;obj-m += hello-1.o  &lt;br /&gt;
all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Loading: Use insmod hello-1.ko or modprobe hello-1 (which resolves dependencies).&lt;br /&gt;
*&#039;&#039;&#039;Inspection: modinfo hello-1 displays module metadata (license, version), while lsmod lists loaded modules.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=824</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=824"/>
		<updated>2025-04-30T02:24:07Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* /usr/src/linux/Documentation/ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security&#039;&#039;&#039;: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=823</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=823"/>
		<updated>2025-04-30T02:23:45Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Kernel Modules and Documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
===/usr/src/linux/===&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;br /&gt;
&lt;br /&gt;
===/usr/src/linux/Documentation/===&lt;br /&gt;
A repository of kernel documentation, including:&lt;br /&gt;
*&#039;&#039;&#039;Process Guides&#039;&#039;&#039;: Files like process/howto.rst explain kernel development workflows.&lt;br /&gt;
*&#039;&#039;&#039;Driver Documentation&#039;&#039;&#039;: Instructions for device drivers (e.g., Documentation/networking/device_drivers/ethernet/intel/e1000e.rst).&lt;br /&gt;
*&#039;&#039;&#039;ABI Specification&#039;&#039;&#039;s: Stability guarantees for sysfs/procfs interfaces (e.g., Documentation/ABI/stable/sysfs-class-net).&lt;br /&gt;
*&#039;&#039;&#039;Security: Guidelines like Documentation/security/credentials.rst detail kernel security models.This directory is critical for developers debugging hardware interactions or implementing kernel features[^prev^].&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=822</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=822"/>
		<updated>2025-04-30T02:22:14Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Linux Kernel Distribution Format */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;br /&gt;
bzImage and xz Compression&lt;br /&gt;
The &#039;&#039;&#039;bzImage&#039;&#039;&#039; (big zImage) is a compressed Linux kernel executable format used in x86 and x86-64 architectures. Despite its name, it does not use bzip2 compression. Instead, it employs &#039;&#039;&#039;gzip&#039;&#039;&#039; by default for compressing the kernel image, though modern systems may use &#039;&#039;&#039;xz&#039;&#039;&#039; (LZMA2 algorithm) for higher compression ratios. The bzImage structure splits the kernel into two parts:&lt;br /&gt;
#&#039;&#039;&#039;Setup Code&#039;&#039;&#039;: A small assembly stub (loaded below 1 MB in memory) responsible for decompressing the kernel and transitioning to protected mode.&lt;br /&gt;
#&#039;&#039;&#039;Compressed Kernel&#039;&#039;&#039;: The main kernel code compressed with gzip/xz, decompressed into high memory (above 1 GB on 64-bit systems).&lt;br /&gt;
The xz compression reduces kernel size significantly, improving boot times on systems with slow storage (e.g., embedded devices). For example, a 10 MB uncompressed kernel might shrink to 4 MB with xz, compared to 6 MB with gzip[^prev^]&lt;br /&gt;
&lt;br /&gt;
==Kernel Modules and Documentation==&lt;br /&gt;
/usr/src/linux/&lt;br /&gt;
&lt;br /&gt;
This directory traditionally contains kernel source code, including:&lt;br /&gt;
*&#039;&#039;&#039;Source Files&#039;&#039;&#039;: Core kernel code (e.g., kernel/sched.c for task scheduling).&lt;br /&gt;
*&#039;&#039;&#039;Header Files&#039;&#039;&#039;: Architecture-specific headers (e.g., arch/x86/include/asm/io.h for x86 I/O operations).&lt;br /&gt;
*&#039;&#039;&#039;Build System&#039;&#039;&#039;: Makefiles and Kconfig files for compiling modules or custom kernels.On modern distributions, this is often a symbolic link to /usr/src/linux-[version] (e.g., /usr/src/linux-5.15.0). Administrators use this to compile kernel modules or apply patches.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=821</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=821"/>
		<updated>2025-04-30T02:19:41Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* What is Systemd? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=What is Systemd?=&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=820</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=820"/>
		<updated>2025-04-30T02:19:22Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* Integration with Journalctl */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;br /&gt;
&lt;br /&gt;
=Linux Kernel Distribution Format=&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=819</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=819"/>
		<updated>2025-04-30T02:06:54Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemd-delta: Managing Configuration Overrides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
==Rescue and Emergency Modes==&lt;br /&gt;
*&#039;&#039;&#039;Rescue Mode&#039;&#039;&#039;: Boots to a minimal root shell with critical services. Use systemctl rescue or append systemd.unit=rescue.target to the kernel command line. Ideal for fixing broken packages or misconfigured network settings[^prev^].&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;Emergency Mode&#039;&#039;&#039;: Provides a bare-bones environment without mounting most filesystems. Trigger via systemctl emergency or systemd.unit=emergency.target. Required for repairing corrupted /etc/fstab or root filesystem errors[^prev^].&lt;br /&gt;
&lt;br /&gt;
==Integration with Journalctl==&lt;br /&gt;
Systemd’s logging tool, journalctl, centralizes log collection. For example, journalctl -u nginx --since &amp;quot;1 hour ago&amp;quot; filters logs for Nginx in the past hour, while journalctl -b shows all boot-related messages.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=818</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=818"/>
		<updated>2025-04-30T02:05:29Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemd-delta: Managing Configuration Overrides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=817</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=817"/>
		<updated>2025-04-30T02:05:03Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemd-delta: Managing Configuration Overrides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  &lt;br /&gt;
echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd:&amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; &lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=816</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=816"/>
		<updated>2025-04-30T02:04:39Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemd-delta: Managing Configuration Overrides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
To increase the file handle limit for Nginx:&lt;br /&gt;
*Create an override:&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  &lt;br /&gt;
echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
*Reload systemd: &amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; to apply changes.&lt;br /&gt;
*Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=815</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=815"/>
		<updated>2025-04-30T02:04:16Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemd-delta: Managing Configuration Overrides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
 To increase the file handle limit for Nginx:&lt;br /&gt;
#Create an override:&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  &lt;br /&gt;
echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#Reload systemd: &amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; to apply changes.&lt;br /&gt;
#Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=814</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=814"/>
		<updated>2025-04-30T02:03:57Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemd-delta: Managing Configuration Overrides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
 To increase the file handle limit for Nginx:&lt;br /&gt;
#Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  &lt;br /&gt;
echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &lt;br /&gt;
&amp;lt;/pre&amp;gt;#Reload systemd: &amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; to apply changes.&lt;br /&gt;
#Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
	<entry>
		<id>https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=813</id>
		<title>Linuc</title>
		<link rel="alternate" type="text/html" href="https://matomo.mintarc.com/mediawiki/index.php?title=Linuc&amp;diff=813"/>
		<updated>2025-04-30T02:03:40Z</updated>

		<summary type="html">&lt;p&gt;Tommy: /* systemctl Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=2.01: System Boot and Linux Kernel=&lt;br /&gt;
==BIOS and UEFI Fundamentals==&lt;br /&gt;
The BIOS (Basic Input/Output System) and UEFI (Unified Extensible Firmware Interface) are firmware interfaces responsible for initializing hardware during system startup and loading the operating system. BIOS, the older standard, relies on the Master Boot Record (MBR) partitioning scheme, which supports up to four primary partitions and boot drives up to 2.2 TB. In contrast, UEFI uses the GUID Partition Table (GPT), allowing up to 128 partitions and boot drives exceeding 9 zettabytes. UEFI also introduces the EFI System Partition (ESP), a FAT-formatted partition storing bootloaders, kernel images, and UEFI applications like efibootmgr. The ESP is critical for UEFI systems, as it hosts the grubx64.efi bootloader and enables Secure Boot to verify firmware integrity.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Configuration and Shell Usage==&lt;br /&gt;
Modifying boot options varies by firmware type. In UEFI systems, efibootmgr manages boot entries, allowing users to adjust boot order, set active/inactive entries, and create new boot options via commands like efibootmgr -o 0001,0002. For Windows, bcdedit /default {GUID} changes the default OS entry. In BIOS-based systems, GRUB’s command-line interface provides direct control using commands such as kernel /vmlinuz root=/dev/sda1 to specify the kernel and initrd /initramfs.img to load the initial RAM disk. GRUB’s shell also supports disk exploration with ls (hd0,1)/ and boot troubleshooting via grub-install.&lt;br /&gt;
&lt;br /&gt;
==GRUB Boot Menu Generation==&lt;br /&gt;
The GRUB boot menu is regenerated using grub2-mkconfig, which synthesizes configuration files from /etc/default/grub and scripts in /etc/grub.d/. Customizations like timeout adjustments or theme changes are added to /etc/default/grub, and executing grub2-mkconfig -o /boot/grub2/grub.cfg applies these changes. For UEFI systems, the configuration resides in /boot/efi/EFI/[distro]/grub.cfg, while BIOS systems use /boot/grub2/grub.cfg.&lt;br /&gt;
&lt;br /&gt;
==Kernel Module Loading with initrd/initramfs==&lt;br /&gt;
The initrd (initial RAM disk) or initramfs (initial RAM filesystem) preloads essential kernel modules and drivers before the root filesystem is mounted. Modules like storage controllers or filesystem drivers are included by editing /etc/initramfs-tools/modules and rebuilding with update-initramfs -u. For example, adding netconsole to initrd involves creating a hook script in /etc/initramfs-tools/hooks/ to ensure the module is included during initramfs generation.&lt;br /&gt;
&lt;br /&gt;
==Hardware Initialization and Filesystem Mounting==&lt;br /&gt;
During boot, the kernel initializes hardware via udev, which dynamically loads kernel modules based on detected devices. After module loading, the kernel mounts the root filesystem specified by the root= parameter in the bootloader. If the root filesystem is encrypted or on a RAID array, initrd handles decryption or assembly before passing control to the OS.&lt;br /&gt;
&lt;br /&gt;
==Service Initialization with systemd==&lt;br /&gt;
Post-filesystem mount, systemd initializes services defined in systemd.unit files. The default target (e.g., multi-user.target or graphical.target) is set using systemctl set-default, while systemctl enable [service] configures services to start at boot. Systemd also manages dependencies, ensuring services like networking or logging start in the correct order.&lt;br /&gt;
&lt;br /&gt;
==Boot Loader Installation and Filesystem Structure==&lt;br /&gt;
The grub-install or grub2-install command installs GRUB to the MBR (for BIOS) or ESP (for UEFI). Key directories include:&lt;br /&gt;
*/boot/: Contains the kernel (vmlinuz) and initramfs.&lt;br /&gt;
*/boot/grub2/: Stores GRUB configuration files (e.g., grub.cfg) on BIOS systems.&lt;br /&gt;
*/boot/efi/: Houses UEFI bootloaders and the ESP partition contents.&lt;br /&gt;
&lt;br /&gt;
For UEFI installations, grub-install copies the grubx64.efi bootloader to /boot/efi/EFI/[distro]/, ensuring compatibility with firmware expectations.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==What is Systemd?==&lt;br /&gt;
Systemd is a modern system and service manager for Linux, designed to replace traditional init systems like SysV. As the first process started during boot (PID 1), it initializes hardware, mounts filesystems, and manages services through unit files-configuration files defining resources like services, sockets, and targets. Unlike SysV, systemd enables parallel service startup, reducing boot times, and integrates logging via journalctl for troubleshooting.&lt;br /&gt;
&lt;br /&gt;
==Paths and Their Roles==&lt;br /&gt;
#&#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;&lt;br /&gt;
##This directory stores default unit files provided by installed packages (e.g., nginx.service, sshd.socket). These files are managed by the system and should not be modified directly. For example, the sshd.service unit here defines how the SSH daemon starts, including dependencies and environment variables&lt;br /&gt;
#&#039;&#039;&#039;/etc/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Administrators place custom unit files and overrides here. When you modify a service (e.g., adding Restart=always to ensure a service auto-recovery), create a subdirectory like /etc/systemd/system/nginx.service.d/override.conf. These configurations take precedence over /usr/lib/systemd/, allowing tailored behavior without altering package defaults.&lt;br /&gt;
#&#039;&#039;&#039;/run/systemd/&#039;&#039;&#039;&lt;br /&gt;
##Runtime configurations reside here, generated dynamically during system operation. For instance, temporary service states or transient units (e.g., systemd-tmpfiles-clean.service) are stored here and cleared on reboot. This directory reflects the current system state, unlike /etc/ or /usr/lib/, which persist across reboots.&lt;br /&gt;
&lt;br /&gt;
==systemctl Commands==&lt;br /&gt;
*&#039;&#039;&#039;systemctl status [unit]&#039;&#039;&#039;: Displays the current state of a service, including active/inactive status, recent logs, and dependencies. For example, systemctl status apache2 reveals if the web server is running, its uptime, and error messages.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl list-units&#039;&#039;&#039;: Lists all loaded units (services, mounts, devices). Adding --type=service --state=failed filters to show only failed services, aiding quick diagnostics.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl start/stop [unit]&#039;&#039;&#039;: Directly controls service execution. For instance, systemctl stop mysql halts the database, while systemctl start nginx activates the web server.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl enable/disable [unit]&#039;&#039;&#039;: Configures autostart behavior. enable creates symlinks in /etc/systemd/system/[target].wants/, ensuring the service starts at boot. Conversely, disable removes these links.&lt;br /&gt;
&lt;br /&gt;
*&#039;&#039;&#039;systemctl mask/unmask [unit]&#039;&#039;&#039;: Prevents accidental activation. Masking (e.g., systemctl mask bluetooth) links the service to /dev/null, blocking all start attempts. Unmasking restores the original configuration.&lt;br /&gt;
&lt;br /&gt;
==systemd-delta: Managing Configuration Overrides==&lt;br /&gt;
This tool identifies conflicts between unit file layers (e.g., /usr/lib/ vs. /etc/). Running systemd-delta highlights modified files, showing where administrators have overridden defaults. For example, if you’ve customized nginx.service in /etc/, it flags this as an &amp;quot;overridden&amp;quot; unit, ensuring transparency in configuration management.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Workflow Example: Customizing a Service&#039;&#039;&#039;&lt;br /&gt;
 To increase the file handle limit for Nginx:&lt;br /&gt;
#Create an override:&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo mkdir -p /etc/systemd/system/nginx.service.d/  &lt;br /&gt;
echo -e &#039;[Service]\nLimitNOFILE=65536&#039; | sudo tee /etc/systemd/system/nginx.service.d/override.conf  &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
#Reload systemd: &amp;lt;pre&amp;gt;sudo systemctl daemon-reload&amp;lt;/pre&amp;gt; to apply changes.&lt;br /&gt;
#Restart Nginx: &amp;lt;pre&amp;gt;sudo systemctl restart nginx&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This ensures Nginx can handle more concurrent connections without altering the original package file in &#039;&#039;&#039;/usr/lib/systemd/&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Tommy</name></author>
	</entry>
</feed>