Skip to content
Merged
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: 17 additions & 15 deletions crates/lib/src/bootloader.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::process::Command;

use anyhow::{anyhow, bail, Context, Result};
use bootc_utils::CommandRunExt;
use camino::Utf8Path;
use fn_error_context::context;

use crate::task::Task;
use bootc_blockdev::PartitionTable;
use bootc_mount as mount;

Expand All @@ -22,16 +24,15 @@ pub(crate) fn install_via_bootupd(

let srcroot = rootfs.join(deployment_path);
let devpath = device.path();
let args = ["backend", "install", "--write-uuid"]
.into_iter()
.chain(verbose)
.chain(bootupd_opts.iter().copied().flatten())
.chain(["--src-root", srcroot.as_str()])
.chain(["--device", devpath.as_str(), rootfs.as_str()]);
Task::new("Running bootupctl to install bootloader", "bootupctl")
.args(args)
.verbose()
.run()
println!("Installing bootloader via bootupd");
Command::new("bootupctl")
.args(["backend", "install", "--write-uuid"])
.args(verbose)
.args(bootupd_opts.iter().copied().flatten())
.args(["--src-root", srcroot.as_str()])
.args(["--device", devpath.as_str(), rootfs.as_str()])
.log_debug()
.run_inherited_with_cmd_context()
}

#[context("Installing bootloader using zipl")]
Expand Down Expand Up @@ -97,8 +98,8 @@ pub(crate) fn install_via_zipl(device: &PartitionTable, boot_uuid: &str) -> Resu
let ramdisk = boot_dir.join(initrd).canonicalize_utf8()?;

// Execute the zipl command to install bootloader
let zipl_desc = format!("running zipl to install bootloader on {device_path}");
let zipl_task = Task::new(&zipl_desc, "zipl")
println!("Running zipl on {device_path}");
Command::new("zipl")
.args(["--target", boot_dir.as_str()])
.args(["--image", image.as_str()])
.args(["--ramdisk", ramdisk.as_str()])
Expand All @@ -107,6 +108,7 @@ pub(crate) fn install_via_zipl(device: &PartitionTable, boot_uuid: &str) -> Resu
.args(["--targettype", "SCSI"])
.args(["--targetblocksize", "512"])
.args(["--targetoffset", &boot_part_offset.to_string()])
.args(["--add-files", "--verbose"]);
zipl_task.verbose().run().context(zipl_desc)
.args(["--add-files", "--verbose"])
.log_debug()
.run_inherited_with_cmd_context()
}
22 changes: 9 additions & 13 deletions crates/lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,10 +587,9 @@ impl SourceInfo {
fn have_selinux_from_repo(root: &Dir) -> Result<bool> {
let cancellable = ostree::gio::Cancellable::NONE;

let commit = Task::new("Reading ostree commit", "ostree")
let commit = Command::new("ostree")
.args(["--repo=/ostree/repo", "rev-parse", "--single"])
.quiet()
.read()?;
.run_get_string()?;
let repo = ostree::Repo::open_at_dir(root.as_fd(), "ostree/repo")?;
let root = repo
.read_commit(commit.trim(), cancellable)
Expand Down Expand Up @@ -1071,11 +1070,10 @@ pub(crate) fn finalize_filesystem(
.run()?;
// Finally, freezing (and thawing) the filesystem will flush the journal, which means the next boot is clean.
for a in ["-f", "-u"] {
Task::new("Flushing filesystem journal", "fsfreeze")
.quiet()
.cwd(root)?
Command::new("fsfreeze")
.cwd_dir(root.try_clone()?)
.args([a, path.as_str()])
.run()?;
.run_capture_stderr()?;
}
Ok(())
}
Expand Down Expand Up @@ -1115,10 +1113,9 @@ pub(crate) fn setup_tmp_mount() -> Result<()> {
} else {
// Note we explicitly also don't want a "nosuid" tmp, because that
// suppresses our install_t transition
Task::new("Mounting tmpfs /tmp", "mount")
Command::new("mount")
.args(["tmpfs", "-t", "tmpfs", "/tmp"])
.quiet()
.run()?;
.run_capture_stderr()?;
}
Ok(())
}
Expand Down Expand Up @@ -1147,10 +1144,9 @@ pub(crate) fn setup_sys_mount(fstype: &str, fspath: &str) -> Result<()> {
}

// This means the host has this mounted, so we should mount it too
Task::new(format!("Mounting {fstype} {fspath}"), "mount")
Command::new("mount")
.args(["-t", fstype, fstype, fspath])
.quiet()
.run()?;
.run_capture_stderr()?;

Ok(())
}
Expand Down
12 changes: 6 additions & 6 deletions crates/lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use std::borrow::Cow;
use std::fmt::Display;
use std::fmt::Write as _;
use std::io::Write;
use std::process::Command;
use std::process::Stdio;

use anyhow::Ok;
use anyhow::{Context, Result};
use bootc_utils::CommandRunExt;
use camino::Utf8Path;
use camino::Utf8PathBuf;
use cap_std::fs::Dir;
Expand Down Expand Up @@ -136,13 +138,11 @@ fn mkfs<'a>(
Ok(u)
}

#[context("Failed to wipe {dev}")]
pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The #[context("Failed to wipe {dev}")] attribute was removed. This attribute provides valuable context to error messages when the wipefs command fails. Without it, the error message will be less specific, making debugging harder. It would be beneficial to restore this attribute to improve error diagnostics.

Suggested change
pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
#[context("Failed to wipe {dev}")]
pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {

Task::new_and_run(
format!("Wiping device {dev}"),
"wipefs",
["-a", dev.as_str()],
)
println!("Wiping device {dev}");
Command::new("wipefs")
.args(["-a", dev.as_str()])
.run_inherited_with_cmd_context()
}

pub(crate) fn udev_settle() -> Result<()> {
Expand Down