From 3be47bac3e184d3335f03203b53ab92ca5991ee9 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 13 Jul 2024 16:57:49 +0000 Subject: [PATCH] install: Gather blockdev info early in filesystem phase The bootloader logic in general is going to need to query the block layout. But especially for ppc64le and s390x we'll need this data. Gather it early on as global state so it's accessible to the entire `install to-filesystem` phase. Note that we shouldn't be mutating the blockdev setup in `to-filesystem`. Signed-off-by: Colin Walters --- lib/src/bootloader.rs | 6 ++++-- lib/src/install.rs | 11 ++++++++--- lib/src/install/baseline.rs | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/src/bootloader.rs b/lib/src/bootloader.rs index ed24dbd3..810a2eb0 100644 --- a/lib/src/bootloader.rs +++ b/lib/src/bootloader.rs @@ -2,6 +2,7 @@ use anyhow::Result; use camino::Utf8Path; use fn_error_context::context; +use crate::blockdev::Device; use crate::task::Task; /// The name of the mountpoint for efi (as a subdirectory of /boot, or at the toplevel) @@ -9,18 +10,19 @@ pub(crate) const EFI_DIR: &str = "efi"; #[context("Installing bootloader")] pub(crate) fn install_via_bootupd( - device: &Utf8Path, + device: &Device, rootfs: &Utf8Path, configopts: &crate::install::InstallConfigOpts, ) -> Result<()> { let verbose = std::env::var_os("BOOTC_BOOTLOADER_DEBUG").map(|_| "-vvvv"); // bootc defaults to only targeting the platform boot method. let bootupd_opts = (!configopts.generic_image).then_some(["--update-firmware", "--auto"]); + let devpath = device.path(); let args = ["backend", "install", "--write-uuid"] .into_iter() .chain(verbose) .chain(bootupd_opts.iter().copied().flatten()) - .chain(["--device", device.as_str(), rootfs.as_str()]); + .chain(["--device", devpath.as_str(), rootfs.as_str()]); Task::new("Running bootupctl to install bootloader", "bootupctl") .args(args) .verbose() diff --git a/lib/src/install.rs b/lib/src/install.rs index b9d6a653..424daec7 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -812,7 +812,7 @@ fn require_skopeo_with_containers_storage() -> Result<()> { pub(crate) struct RootSetup { luks_device: Option, - device: Utf8PathBuf, + device_info: crate::blockdev::Device, rootfs: Utf8PathBuf, rootfs_fd: Dir, rootfs_uuid: Option, @@ -1229,7 +1229,11 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re .context("Writing aleph version")?; } - crate::bootloader::install_via_bootupd(&rootfs.device, &rootfs.rootfs, &state.config_opts)?; + crate::bootloader::install_via_bootupd( + &rootfs.device_info, + &rootfs.rootfs, + &state.config_opts, + )?; tracing::debug!("Installed bootloader"); // Finalize mounted filesystems @@ -1583,6 +1587,7 @@ pub(crate) async fn install_to_filesystem( dev }; tracing::debug!("Backing device: {backing_device}"); + let device_info = crate::blockdev::list_dev(Utf8Path::new(&backing_device))?; let rootarg = format!("root={}", root_info.mount_spec); let mut boot = if let Some(spec) = fsopts.boot_mount_spec { @@ -1611,7 +1616,7 @@ pub(crate) async fn install_to_filesystem( matches!(fsopts.replace, Some(ReplaceMode::Alongside)) || fsopts.skip_finalize; let mut rootfs = RootSetup { luks_device: None, - device: backing_device.into(), + device_info, rootfs: fsopts.root_path, rootfs_fd, rootfs_uuid: inspect.uuid.clone(), diff --git a/lib/src/install/baseline.rs b/lib/src/install/baseline.rs index 0a9b85a5..31abbe6a 100644 --- a/lib/src/install/baseline.rs +++ b/lib/src/install/baseline.rs @@ -439,9 +439,10 @@ pub(crate) fn install_create_rootfs( BlockSetup::Direct => None, BlockSetup::Tpm2Luks => Some(luks_name.to_string()), }; + let device_info = crate::blockdev::list_dev(&devpath)?; Ok(RootSetup { luks_device, - device: devpath, + device_info, rootfs, rootfs_fd, rootfs_uuid: Some(root_uuid.to_string()),