Skip to content
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

install: print warning when system may have more than one boot/root partition #642

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 36 additions & 0 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::io::{copy, Read, Seek, SeekFrom, Write};
use std::num::NonZeroU32;
use std::os::unix::fs::{FileTypeExt, PermissionsExt};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};

use crate::blockdev::*;
use crate::cmdline::*;
Expand Down Expand Up @@ -241,6 +242,10 @@ pub fn install(config: &InstallConfig) -> Result<()> {
bail!("install failed");
}

// warn if we have more than 1 partition with boot/root label
check_single_partition("boot", &config.device)?;
check_single_partition("root", &config.device)?;

eprintln!("Install complete.");
Ok(())
}
Expand Down Expand Up @@ -401,6 +406,37 @@ fn write_disk(
Ok(())
}

fn check_single_partition(label: &str, disk: &str) -> Result<()> {
let label = format!("{} ", label);
let cmd = Command::new("lsblk")
.arg("-o")
.arg("LABEL,NAME")
.arg("--noheadings")
.arg("--list")
.arg("--paths")
.stderr(Stdio::inherit())
.output()
.context("reading partitions' labels")?;
if !cmd.status.success() {
bail!("lsblk failed");
}

let pts = std::str::from_utf8(&cmd.stdout)
.context("decoding lsblk output")?
.trim()
.lines()
.filter(|&s| s.starts_with(&label))
.filter_map(|s| s.split_whitespace().last())
.collect::<Vec<_>>();
if pts.len() > 1 {
eprintln!(
"System may have several partitions with '{}' label: {:?}.\nYou could `wipefs` all disks except: {}.",
label, pts, disk
);
}
Ok(())
}

/// Write the Ignition config.
fn write_ignition(
mountpoint: &Path,
Expand Down