Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 2 additions & 30 deletions crates/trident/src/engine/boot/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/trident/src/engine/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf> {
pub(crate) fn get_root_block_device_path(&self) -> Option<PathBuf> {
self.get_root_block_device_id()
.and_then(|id| self.get_block_device_path(&id))
}
Expand Down
5 changes: 2 additions & 3 deletions crates/trident/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ 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},
storage_graph::graph::StorageGraph,
};

use crate::{
engine::boot::BootSubsystem,
subsystems::{
esp::EspSubsystem,
extensions::ExtensionsSubsystem,
grub::GrubSubsystem,
hooks::HooksSubsystem,
initrd::InitrdSubsystem,
management::ManagementSubsystem,
Expand Down Expand Up @@ -145,7 +144,7 @@ lazy_static::lazy_static! {
Box::<MosConfigSubsystem>::default(),
Box::<EspSubsystem>::default(),
Box::<StorageSubsystem>::default(),
Box::<BootSubsystem>::default(),
Box::<GrubSubsystem>::default(),
Box::<NetworkSubsystem>::default(),
Box::<OsConfigSubsystem>::default(),
Box::<ManagementSubsystem>::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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!(
Expand Down
31 changes: 31 additions & 0 deletions crates/trident/src/subsystems/grub/mod.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 1 addition & 0 deletions crates/trident/src/subsystems/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading