diff --git a/crates/trident/src/engine/boot/mod.rs b/crates/trident/src/engine/boot/mod.rs index 891b9b66c0..28997a9e8d 100644 --- a/crates/trident/src/engine/boot/mod.rs +++ b/crates/trident/src/engine/boot/mod.rs @@ -1,17 +1,12 @@ -use log::debug; use strum::IntoEnumIterator; use trident_api::{ constants::{AB_VOLUME_A_NAME, AB_VOLUME_B_NAME, AZURE_LINUX_INSTALL_ID_PREFIX, VAR_TMP_PATH}, - error::{ReportError, ServicingError, TridentError}, status::AbVolumeSelection, }; -use crate::engine::Subsystem; - use super::EngineContext; -pub(super) mod grub; pub mod uki; pub(crate) const ESP_EXTRACTION_DIRECTORY: &str = VAR_TMP_PATH; @@ -21,31 +16,6 @@ pub(crate) const ESP_EXTRACTION_DIRECTORY: &str = VAR_TMP_PATH; /// conventional system, and systemd-tmpfiles expects to find it that way. pub(crate) const ESP_EXTRACTION_DIRECTORY_MODE: u32 = 0o1777; -#[derive(Default, Debug)] -pub(super) struct BootSubsystem; -impl Subsystem for BootSubsystem { - fn name(&self) -> &'static str { - "boot" - } - - #[tracing::instrument(name = "boot_configuration", skip_all)] - fn configure(&mut self, ctx: &EngineContext) -> Result<(), TridentError> { - if ctx.is_uki()? { - debug!("Skipping grub configuration because UKI is in use"); - return Ok(()); - } - - if ctx.is_stream_image { - debug!("Skipping bootloader configuration during stream-image"); - return Ok(()); - } - - grub::update_configs(ctx).structured(ServicingError::UpdateGrubConfigs)?; - - Ok(()) - } -} - /// Returns the ESP directory name of the current install's update volume. /// /// Internally, calls `EngineContext::make_install_id` with the update volume returned by @@ -150,6 +120,8 @@ mod tests { use trident_api::status::ServicingType; + use crate::engine::EngineContext; + #[test] fn test_make_install_id() { // Test for index 0 diff --git a/crates/trident/src/engine/context/mod.rs b/crates/trident/src/engine/context/mod.rs index f0ed166334..4f6f474bb8 100644 --- a/crates/trident/src/engine/context/mod.rs +++ b/crates/trident/src/engine/context/mod.rs @@ -234,7 +234,7 @@ impl EngineContext { } /// Using the `/` mount point, fetches the root block device path. - pub(super) fn get_root_block_device_path(&self) -> Option { + pub(crate) fn get_root_block_device_path(&self) -> Option { self.get_root_block_device_id() .and_then(|id| self.get_block_device_path(&id)) } diff --git a/crates/trident/src/engine/mod.rs b/crates/trident/src/engine/mod.rs index a1bca74146..93eee4c335 100644 --- a/crates/trident/src/engine/mod.rs +++ b/crates/trident/src/engine/mod.rs @@ -10,7 +10,6 @@ use log::{debug, info, trace, warn}; use osutils::path::join_relative; use trident_api::{ config::Storage, - constants, error::{InternalError, TridentError, TridentResultExt}, is_default, status::{ServicingState, ServicingType}, @@ -18,10 +17,10 @@ use trident_api::{ }; use crate::{ - engine::boot::BootSubsystem, subsystems::{ esp::EspSubsystem, extensions::ExtensionsSubsystem, + grub::GrubSubsystem, hooks::HooksSubsystem, initrd::InitrdSubsystem, management::ManagementSubsystem, @@ -145,7 +144,7 @@ lazy_static::lazy_static! { Box::::default(), Box::::default(), Box::::default(), - Box::::default(), + Box::::default(), Box::::default(), Box::::default(), Box::::default(), diff --git a/crates/trident/src/engine/boot/grub.rs b/crates/trident/src/subsystems/grub/config.rs similarity index 99% rename from crates/trident/src/engine/boot/grub.rs rename to crates/trident/src/subsystems/grub/config.rs index 07e08f2853..debc6acc43 100644 --- a/crates/trident/src/engine/boot/grub.rs +++ b/crates/trident/src/subsystems/grub/config.rs @@ -16,11 +16,12 @@ use trident_api::{ constants::{ BOOT_MOUNT_POINT_PATH, ESP_EFI_DIRECTORY, GRUB2_CONFIG_FILENAME, GRUB2_CONFIG_RELATIVE_PATH, ROOT_MOUNT_POINT_PATH, TRIDENT_OVERLAY_LOWER_RELATIVE_PATH, - TRIDENT_OVERLAY_UPPER_RELATIVE_PATH, TRIDENT_OVERLAY_WORK_RELATIVE_PATH, + TRIDENT_OVERLAY_PATH, TRIDENT_OVERLAY_UPPER_RELATIVE_PATH, + TRIDENT_OVERLAY_WORK_RELATIVE_PATH, }, }; -use crate::engine::{constants::TRIDENT_OVERLAY_PATH, storage::verity, EngineContext}; +use crate::engine::{boot::get_update_esp_dir_name, storage::verity, EngineContext}; /// Updates the boot filesystem UUID on the search command inside the GRUB /// config. @@ -76,7 +77,7 @@ pub(super) fn update_configs(ctx: &EngineContext) -> Result<(), Error> { .esp_mount_path .as_path() .join(ESP_EFI_DIRECTORY) - .join(super::get_update_esp_dir_name(ctx).context("Failed to get update install ID")?) + .join(get_update_esp_dir_name(ctx).context("Failed to get update install ID")?) .join(GRUB2_CONFIG_FILENAME); update_grub_config_esp(&bootentry_config_path, &boot_uuid).context(format!( diff --git a/crates/trident/src/subsystems/grub/mod.rs b/crates/trident/src/subsystems/grub/mod.rs new file mode 100644 index 0000000000..66373306ab --- /dev/null +++ b/crates/trident/src/subsystems/grub/mod.rs @@ -0,0 +1,31 @@ +use log::debug; + +use trident_api::error::{ReportError, ServicingError, TridentError}; + +use crate::engine::{EngineContext, Subsystem}; + +mod config; + +#[derive(Default, Debug)] +pub(crate) struct GrubSubsystem; + +impl Subsystem for GrubSubsystem { + fn name(&self) -> &'static str { + "grub" + } + + #[tracing::instrument(name = "grub_configuration", skip_all)] + fn configure(&mut self, ctx: &EngineContext) -> Result<(), TridentError> { + if ctx.is_uki()? { + debug!("Skipping GRUB configuration because UKI is in use"); + return Ok(()); + } + + if ctx.is_stream_image { + debug!("Skipping GRUB configuration during stream-image"); + return Ok(()); + } + + config::update_configs(ctx).structured(ServicingError::UpdateGrubConfigs) + } +} diff --git a/crates/trident/src/engine/boot/test_files/grub_boot.cfg b/crates/trident/src/subsystems/grub/test_files/grub_boot.cfg similarity index 100% rename from crates/trident/src/engine/boot/test_files/grub_boot.cfg rename to crates/trident/src/subsystems/grub/test_files/grub_boot.cfg diff --git a/crates/trident/src/engine/boot/test_files/grub_esp.cfg b/crates/trident/src/subsystems/grub/test_files/grub_esp.cfg similarity index 100% rename from crates/trident/src/engine/boot/test_files/grub_esp.cfg rename to crates/trident/src/subsystems/grub/test_files/grub_esp.cfg diff --git a/crates/trident/src/subsystems/mod.rs b/crates/trident/src/subsystems/mod.rs index 3993ab3ffc..dc70c7a86f 100644 --- a/crates/trident/src/subsystems/mod.rs +++ b/crates/trident/src/subsystems/mod.rs @@ -1,5 +1,6 @@ pub(crate) mod esp; pub(crate) mod extensions; +pub(crate) mod grub; pub(crate) mod hooks; pub(crate) mod initrd; pub(crate) mod management;