Skip to content
Open
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
2 changes: 2 additions & 0 deletions crates/osutils/src/mkinitrd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ mod functional_test {
fn test_regenerate_initrd() {
let pattern = if osrelease::is_azl3().unwrap() {
"/boot/initramfs-*.azl3.img"
} else if osrelease::is_azl4().unwrap() {
"/boot/initramfs-*.azl4.img"
} else {
"/boot/initrd.img-*"
};
Expand Down
47 changes: 47 additions & 0 deletions crates/osutils/src/osrelease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ pub fn is_azl3() -> Result<bool, Error> {
Ok(OsRelease::read()?.get_distro().is_azl3())
}

/// Returns whether the host is running Azure Linux 4.
pub fn is_azl4() -> Result<bool, Error> {
Ok(OsRelease::read()?.get_distro().is_azl4())
}

/// Represents the contents of the /etc/os-release file.
///
/// See <https://www.freedesktop.org/software/systemd/man/latest/os-release.html>
Expand Down Expand Up @@ -146,6 +151,8 @@ impl OsRelease {
AzureLinuxRelease::AzL2
} else if v.starts_with("3.") {
AzureLinuxRelease::AzL3
} else if v.starts_with("4.") {
AzureLinuxRelease::AzL4
} else {
trace!("Unknown Azure Linux release: {v}");
AzureLinuxRelease::Other
Expand Down Expand Up @@ -342,6 +349,10 @@ impl Distro {
self == &Distro::AzureLinux(AzureLinuxRelease::AzL3)
}

pub fn is_azl4(&self) -> bool {
self == &Distro::AzureLinux(AzureLinuxRelease::AzL4)
}

Comment thread
Britel marked this conversation as resolved.
pub fn is_acl(&self) -> bool {
self == &Distro::AzureContainerLinux
}
Expand All @@ -354,6 +365,7 @@ pub enum AzureLinuxRelease {
Other,
AzL2,
AzL3,
AzL4,
}

#[cfg(test)]
Expand Down Expand Up @@ -429,6 +441,41 @@ mod tests {
);
}

#[test]
fn test_parse_azl4() {
let data = indoc::indoc! {
r#"
NAME="Azure Linux"
VERSION="4.0 (Four Alpha2)"
RELEASE_TYPE=development
ID=azurelinux
ID_LIKE=fedora
VERSION_ID="4.0"
VERSION_CODENAME=""
PRETTY_NAME="Azure Linux 4.0 (Four Alpha2)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=azurelinux-logo-icon
CPE_NAME="cpe:/o:azurelinuxproject:azurelinux:4.0"
DEFAULT_HOSTNAME="azurelinux"
HOME_URL="https://aka.ms/azurelinux"
DOCUMENTATION_URL="https://aka.ms/azurelinux"
SUPPORT_URL="https://aka.ms/azurelinux"
BUG_REPORT_URL="https://aka.ms/azurelinux"
SUPPORT_END=2026-05-15
"#,
};

let os_release = OsRelease::parse(data);
assert_eq!(os_release.id, Some("azurelinux".to_string()));
assert_eq!(os_release.version_id, Some("4.0".to_string()));
assert_eq!(os_release.id_like, Some("fedora".to_string()));
assert_eq!(os_release.release_type, Some("development".to_string()));
assert_eq!(
os_release.get_distro(),
Distro::AzureLinux(AzureLinuxRelease::AzL4)
);
}

#[test]
fn test_parse_extension_release() {
let data = indoc::indoc! {
Expand Down
25 changes: 25 additions & 0 deletions crates/osutils/src/testutils/osrelease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@ const AZURE_LINUX_3_OS_RELEASE: &str = indoc::indoc! {
"#,
};

/// Azure Linux 4.0 sample os-release file.
const AZURE_LINUX_4_OS_RELEASE: &str = indoc::indoc! {
r#"
NAME="Azure Linux"
VERSION="4.0 (Cloud Variant Beta)"
RELEASE_TYPE=development
ID=azurelinux
ID_LIKE=fedora
VERSION_ID="4.0"
VERSION_CODENAME=""
PRETTY_NAME="Azure Linux 4.0 (Cloud Variant Beta)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=azurelinux-logo-icon
CPE_NAME="cpe:/o:azurelinuxproject:azurelinux:4.0"
DEFAULT_HOSTNAME="azurelinux"
HOME_URL="https://aka.ms/azurelinux"
DOCUMENTATION_URL="https://aka.ms/azurelinux"
SUPPORT_URL="https://aka.ms/azurelinux"
BUG_REPORT_URL="https://aka.ms/azurelinux"
VARIANT="Cloud Variant"
VARIANT_ID=cloud
"#,
};

/// Creates a mock /etc/os-release file with the given Azure Linux release.
pub fn make_mock_os_release(root_path: &Path, azl_release: AzureLinuxRelease) -> Result<(), Error> {
let os_release_content = match azl_release {
AzureLinuxRelease::AzL2 => AZURE_LINUX_2_OS_RELEASE,
AzureLinuxRelease::AzL3 => AZURE_LINUX_3_OS_RELEASE,
AzureLinuxRelease::AzL4 => AZURE_LINUX_4_OS_RELEASE,
AzureLinuxRelease::Other => bail!("Unsupported Azure Linux release 'other'"),
};

Expand Down
17 changes: 9 additions & 8 deletions crates/trident/src/engine/boot/grub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ pub(super) fn update_configs(ctx: &EngineContext) -> Result<(), Error> {
let boot_grub_config_path = Path::new(ROOT_MOUNT_POINT_PATH).join(GRUB2_CONFIG_RELATIVE_PATH);

// Update GRUB config on the boot device (volume holding /boot)
match ctx.host_os_release.get_distro() {
Distro::AzureLinux(AzureLinuxRelease::AzL3) => {
update_grub_config_azl3(ctx, &root_device_path, &boot_grub_config_path)?;
// Use the *image* distro (the OS being installed), not the host (MOS ISO).
match ctx.image_distro() {
Distro::AzureLinux(AzureLinuxRelease::AzL3 | AzureLinuxRelease::AzL4) => {
update_grub_config(ctx, &root_device_path, &boot_grub_config_path)?;
}

d => bail!("Unsupported distro for GRUB config update: {d:?}"),
Expand All @@ -85,13 +86,13 @@ pub(super) fn update_configs(ctx: &EngineContext) -> Result<(), Error> {
))
}

/// Updates the GRUB config for Azure Linux 3.0 using OS modifier.
fn update_grub_config_azl3(
/// Updates the GRUB config for Azure Linux using OS modifier.
fn update_grub_config(
ctx: &EngineContext,
root_device_path: &Path,
boot_grub_config_path: &Path,
) -> Result<(), Error> {
// For azl 3.0, we need to disable cloud-init's network configuration when Trident is
// For azl 3.0+, we need to disable cloud-init's network configuration when Trident is
// configuring the network. This is done by setting the 'network-config' kernel parameter
// to 'disabled'.
if ctx.spec.os.netplan.is_some() {
Expand All @@ -103,7 +104,7 @@ fn update_grub_config_azl3(
.context("Failed to disable default cloud-init network config")?;
}

debug!("Updating GRUB config for Azure Linux 3.0 with OS modifier");
debug!("Updating GRUB config with OS modifier");

// OS modifier will read values of verity, selinux, root device, and overlay from original GRUB config
// stamp them into /etc/default/grub and regenerate the GRUB config using grub-mkconfig.
Expand Down Expand Up @@ -222,7 +223,7 @@ fn update_grub_config_azl3(
osmodifier::modify_boot(&osmod_ctx, &config)
.context("Failed to apply boot configuration modifications")?;

debug!("Finished updating GRUB config for Azure Linux 3.0 with OS modifier");
debug!("Finished updating GRUB config with OS modifier");

Ok(())
}
Expand Down
14 changes: 13 additions & 1 deletion crates/trident/src/engine/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,20 @@ impl EngineContext {
}

/// Retrieves the distribution of the OS image.
///
/// Prefers the image's own os-release (e.g., from the COSI being installed).
/// Falls back to the host os-release only when no image is mounted
/// (functional tests, runtime operations outside an install flow).
///
/// If an image IS present but its distro is unrecognized, the image's
/// distro is returned as-is (Distro::Other) so callers can bail
/// explicitly rather than silently using the host's distro.
pub(crate) fn image_distro(&self) -> Distro {
self.image_os_release().get_distro()
if self.image.is_some() {
self.image_os_release().get_distro()
} else {
self.host_os_release.get_distro()
}
Comment thread
Britel marked this conversation as resolved.
}
}

Expand Down
Loading