Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 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 @@ -86,7 +87,7 @@ 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(
fn update_grub_config(
Comment thread
Britel marked this conversation as resolved.
Outdated
ctx: &EngineContext,
root_device_path: &Path,
boot_grub_config_path: &Path,
Expand Down
10 changes: 9 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,16 @@ 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 when no image is available (functional
/// tests, runtime operations outside an install flow).
pub(crate) fn image_distro(&self) -> Distro {
self.image_os_release().get_distro()
let distro = self.image_os_release().get_distro();
match distro {
Distro::Other => self.host_os_release.get_distro(),
d => d,
}
Comment thread
Britel marked this conversation as resolved.
}
}

Expand Down
Loading