Skip to content

Commit

Permalink
install: Gather blockdev info early in filesystem phase
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cgwalters committed Jul 13, 2024
1 parent b9dcd45 commit 3be47ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/src/bootloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@ 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)
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()
Expand Down
11 changes: 8 additions & 3 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ fn require_skopeo_with_containers_storage() -> Result<()> {

pub(crate) struct RootSetup {
luks_device: Option<String>,
device: Utf8PathBuf,
device_info: crate::blockdev::Device,
rootfs: Utf8PathBuf,
rootfs_fd: Dir,
rootfs_uuid: Option<String>,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 3be47ba

Please sign in to comment.