Skip to content

reinstall: Only add --cleanup when bootc version >= 1.1.8 #1313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
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
2 changes: 1 addition & 1 deletion system-reinstall-bootc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn run() -> Result<()> {
prompt::get_ssh_keys(ssh_key_file_path)?;

let mut reinstall_podman_command =
podman::reinstall_command(&config.bootc_image, ssh_key_file_path);
podman::reinstall_command(&config.bootc_image, ssh_key_file_path)?;

println!();
println!("Going to run command:");
Expand Down
31 changes: 26 additions & 5 deletions system-reinstall-bootc/src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@ use bootc_utils::CommandRunExt;
use std::process::Command;
use which::which;

pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
fn bootc_has_clean(image: &str) -> Result<bool> {
let output = Command::new("podman")
.args([
"run",
"--rm",
image,
"bootc",
"install",
"to-existing-root",
"--help",
])
.output()?;
let stdout_str = String::from_utf8_lossy(&output.stdout);
Ok(stdout_str.contains("--cleanup"))
}

pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Result<Command> {
let mut podman_command_and_args = [
// We use podman to run the bootc container. This might change in the future to remove the
// podman dependency.
Expand Down Expand Up @@ -49,13 +65,18 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
// The image is always pulled first, so let's avoid requiring the credentials to be baked
// in the image for this check.
"--skip-fetch-check",
// Always enable the systemd service to cleanup the previous install after booting into the
// bootc system for the first time
"--cleanup",
]
.map(String::from)
.to_vec();

// Enable the systemd service to cleanup the previous install after booting into the
// bootc system for the first time.
// This only happens if the bootc version in the image >= 1.1.8 (this is when the cleanup
// feature was introduced)
if bootc_has_clean(image)? {
bootc_command_and_args.push("--cleanup".to_string());
}

podman_command_and_args.push("-v".to_string());
podman_command_and_args.push(format!("{ssh_key_file}:{ROOT_KEY_MOUNT_POINT}"));

Expand All @@ -72,7 +93,7 @@ pub(crate) fn reinstall_command(image: &str, ssh_key_file: &str) -> Command {
let mut command = Command::new(&all_args[0]);
command.args(&all_args[1..]);

command
Ok(command)
}

pub(crate) fn pull_image_command(image: &str) -> Command {
Expand Down