initramfs module #14

Open
opened 2025-12-21 11:44:35 +00:00 by thabeta · 0 comments
Owner

The initramfs module provides comprehensive initramfs generation capabilities for Linux systems, creating minimal initial RAM filesystems that contain exactly the modules, binaries, and scripts needed for system boot. This module ensures fast startup times and minimal memory footprint by including only essential components.

The module handles the complex process of building initramfs images with specific configurations for different boot scenarios, including systemd integration, network support, and storage drivers. It supports multiple compression formats and can be customized for various deployment targets from embedded systems to cloud servers.

Functionality

  • Base initramfs creation: Initialize minimal initramfs structure with essential directories and basic system files
  • Binary inclusion: Add required binaries and libraries with automatic dependency resolution
  • Kernel module management: Include specific kernel modules needed for boot and hardware support
  • Script and hook system: Add initialization scripts and hooks that run at specific boot stages
  • Feature integration: Include support for systemd, networking, storage, and other subsystems
  • Compression and optimization: Apply various compression algorithms to reduce image size
  • Boot configuration: Generate boot parameters and configuration for different boot loaders

Module API

Initramfs Generation

  • InitramfsBuilder::new() -> Self - Create a new initramfs builder with default configuration
  • create_base_initramfs() -> Result<InitramfsBuilder, InitramfsError> - Initialize a base initramfs structure
  • add_binary(&mut self, binary: &str) -> &mut Self - Add a binary executable to the initramfs
  • add_binary_with_path(&mut self, binary: &str, dest: &str) -> &mut Self - Add binary to specific path
  • add_library(&mut self, library: &str) -> &mut Self - Add a shared library
  • resolve_dependencies(&mut self, binary: &str) -> Result<Vec<String>, InitramfsError> - Resolve binary dependencies
  • add_module(&mut self, module: &str) -> &mut Self - Add a kernel module to be loaded at boot
  • add_firmware(&mut self, firmware: &str) -> &mut Self - Add firmware files
  • add_script(&mut self, script: InitScript) -> &mut Self - Add an initialization script to run during boot
  • add_hook(&mut self, hook: InitHook) -> &mut Self - Add boot hook at specific stage

Feature Integration

  • add_systemd_support(&mut self) -> &mut Self - Include systemd services and support files
  • add_network_support(&mut self, modules: Vec<String>) -> &mut Self - Add network drivers and configuration
  • add_storage_support(&mut self, drivers: Vec<String>) -> &mut Self - Add storage drivers and filesystem support
  • add_crypto_support(&mut self) -> &mut Self - Add cryptographic modules and tools
  • add_udev_rules(&mut self, rules: Vec<UdevRule>) -> &mut Self - Add udev rules for device management
  • add_debug_tools(&mut self) -> &mut Self - Add debugging tools for troubleshooting

Compression and Building

  • compress_initramfs(&self, method: CompressionMethod) -> Result<PathBuf, InitramfsError> - Compress the initramfs
  • set_compression_level(&mut self, level: u32) -> &mut Self - Set compression level
  • build(&self) -> Result<PathBuf, InitramfsError> - Build the final initramfs image
  • build_uncompressed(&self) -> Result<PathBuf, InitramfsError> - Build without compression
  • verify_initramfs(&self, path: &Path) -> Result<VerificationReport, InitramfsError> - Verify initramfs integrity

Configuration Management

  • InitramfsConfig::new() -> Self - Create initramfs configuration
  • set_kernel_version(&mut self, version: &str) -> &mut Self - Set target kernel version
  • set_modules_directory(&mut self, path: &Path) -> &mut Self - Set modules directory path
  • add_early_module(&mut self, module: &str) -> &mut Self - Add module to load early
  • set_timeout(&mut self, timeout: Duration) -> &mut Self - Set boot timeout
  • enable_debug(&mut self) -> &mut Self - Enable debug output

Boot Integration

  • generate_boot_config(&self, format: BootFormat) -> Result<String, InitramfsError> - Generate boot config
  • create_boot_entry(&self, kernel_path: &Path, initramfs_path: &Path) -> BootEntry - Create boot entry
  • generate_cmdline(&self) -> Result<String, InitramfsError> - Generate kernel command line
  • add_kernel_param(&mut self, param: &str) -> &mut Self - Add kernel boot parameter
The initramfs module provides comprehensive initramfs generation capabilities for Linux systems, creating minimal initial RAM filesystems that contain exactly the modules, binaries, and scripts needed for system boot. This module ensures fast startup times and minimal memory footprint by including only essential components. The module handles the complex process of building initramfs images with specific configurations for different boot scenarios, including systemd integration, network support, and storage drivers. It supports multiple compression formats and can be customized for various deployment targets from embedded systems to cloud servers. ## Functionality - **Base initramfs creation**: Initialize minimal initramfs structure with essential directories and basic system files - **Binary inclusion**: Add required binaries and libraries with automatic dependency resolution - **Kernel module management**: Include specific kernel modules needed for boot and hardware support - **Script and hook system**: Add initialization scripts and hooks that run at specific boot stages - **Feature integration**: Include support for systemd, networking, storage, and other subsystems - **Compression and optimization**: Apply various compression algorithms to reduce image size - **Boot configuration**: Generate boot parameters and configuration for different boot loaders ## Module API ### Initramfs Generation - `InitramfsBuilder::new() -> Self` - Create a new initramfs builder with default configuration - `create_base_initramfs() -> Result<InitramfsBuilder, InitramfsError>` - Initialize a base initramfs structure - `add_binary(&mut self, binary: &str) -> &mut Self` - Add a binary executable to the initramfs - `add_binary_with_path(&mut self, binary: &str, dest: &str) -> &mut Self` - Add binary to specific path - `add_library(&mut self, library: &str) -> &mut Self` - Add a shared library - `resolve_dependencies(&mut self, binary: &str) -> Result<Vec<String>, InitramfsError>` - Resolve binary dependencies - `add_module(&mut self, module: &str) -> &mut Self` - Add a kernel module to be loaded at boot - `add_firmware(&mut self, firmware: &str) -> &mut Self` - Add firmware files - `add_script(&mut self, script: InitScript) -> &mut Self` - Add an initialization script to run during boot - `add_hook(&mut self, hook: InitHook) -> &mut Self` - Add boot hook at specific stage ### Feature Integration - `add_systemd_support(&mut self) -> &mut Self` - Include systemd services and support files - `add_network_support(&mut self, modules: Vec<String>) -> &mut Self` - Add network drivers and configuration - `add_storage_support(&mut self, drivers: Vec<String>) -> &mut Self` - Add storage drivers and filesystem support - `add_crypto_support(&mut self) -> &mut Self` - Add cryptographic modules and tools - `add_udev_rules(&mut self, rules: Vec<UdevRule>) -> &mut Self` - Add udev rules for device management - `add_debug_tools(&mut self) -> &mut Self` - Add debugging tools for troubleshooting ### Compression and Building - `compress_initramfs(&self, method: CompressionMethod) -> Result<PathBuf, InitramfsError>` - Compress the initramfs - `set_compression_level(&mut self, level: u32) -> &mut Self` - Set compression level - `build(&self) -> Result<PathBuf, InitramfsError>` - Build the final initramfs image - `build_uncompressed(&self) -> Result<PathBuf, InitramfsError>` - Build without compression - `verify_initramfs(&self, path: &Path) -> Result<VerificationReport, InitramfsError>` - Verify initramfs integrity ### Configuration Management - `InitramfsConfig::new() -> Self` - Create initramfs configuration - `set_kernel_version(&mut self, version: &str) -> &mut Self` - Set target kernel version - `set_modules_directory(&mut self, path: &Path) -> &mut Self` - Set modules directory path - `add_early_module(&mut self, module: &str) -> &mut Self` - Add module to load early - `set_timeout(&mut self, timeout: Duration) -> &mut Self` - Set boot timeout - `enable_debug(&mut self) -> &mut Self` - Enable debug output ### Boot Integration - `generate_boot_config(&self, format: BootFormat) -> Result<String, InitramfsError>` - Generate boot config - `create_boot_entry(&self, kernel_path: &Path, initramfs_path: &Path) -> BootEntry` - Create boot entry - `generate_cmdline(&self) -> Result<String, InitramfsError>` - Generate kernel command line - `add_kernel_param(&mut self, param: &str) -> &mut Self` - Add kernel boot parameter
despiegk added this to the later milestone 2025-12-21 20:41:15 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geomind_research/herolib_rust#14
No description provided.