refraction-forger/crates/forge-engine/src/tools/bootloader.rs
Till Wegmueller 48f8db1236
Initial implementation of refraction-forger
Standalone workspace with 4 crates for building optimized OS images
and publishing to OCI registries:

- spec-parser: KDL image spec parsing with include resolution and
  profile-based conditional filtering
- forge-oci: OCI image creation (tar layers, manifests, Image Layout)
  and registry push via oci-client
- forge-engine: Build pipeline with Phase 1 (rootfs assembly via native
  package managers with -R) and Phase 2 (QCOW2/OCI/artifact targets),
  plus dyn-compatible ToolRunner trait for external tool execution
- forger: CLI binary with build, validate, inspect, push, and targets
  commands

Ported KDL specs and overlay files from the vm-manager prototype.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 15:30:22 +01:00

78 lines
2.1 KiB
Rust

use crate::error::ForgeError;
use crate::tools::ToolRunner;
use tracing::info;
/// Install the bootloader into the staging root.
///
/// For illumos: uses `bootadm` to install the boot archive and UEFI loader.
/// For Linux: uses `grub-install` with chroot.
#[cfg(target_os = "illumos")]
pub async fn install(
runner: &dyn ToolRunner,
staging_root: &str,
pool_name: &str,
bootloader_type: &str,
) -> Result<(), ForgeError> {
info!(staging_root, pool_name, bootloader_type, "Installing bootloader (illumos)");
// Install the boot archive
runner
.run("bootadm", &["update-archive", "-R", staging_root])
.await?;
if bootloader_type == "uefi" {
// Install the UEFI bootloader
runner
.run(
"bootadm",
&["install-bootloader", "-M", "-f", "-P", pool_name, "-R", staging_root],
)
.await?;
}
Ok(())
}
#[cfg(target_os = "linux")]
pub async fn install(
runner: &dyn ToolRunner,
staging_root: &str,
_pool_name: &str,
bootloader_type: &str,
) -> Result<(), ForgeError> {
info!(staging_root, bootloader_type, "Installing bootloader (Linux)");
match bootloader_type {
"grub" | "uefi" => {
runner
.run(
"chroot",
&[staging_root, "grub-install", "--target=x86_64-efi"],
)
.await?;
}
other => {
return Err(ForgeError::Qcow2Build {
step: "bootloader_install".to_string(),
detail: format!("Unsupported bootloader type: {other}"),
});
}
}
Ok(())
}
#[cfg(not(any(target_os = "linux", target_os = "illumos")))]
pub async fn install(
_runner: &dyn ToolRunner,
_staging_root: &str,
_pool_name: &str,
bootloader_type: &str,
) -> Result<(), ForgeError> {
Err(ForgeError::Qcow2Build {
step: "bootloader_install".to_string(),
detail: format!(
"Bootloader installation is not supported on this platform (type: {bootloader_type})"
),
})
}