Skip to content

Commit

Permalink
install: print warning when system may have more than one boot/root p…
Browse files Browse the repository at this point in the history
…artition

Inspired by: coreos/fedora-coreos-tracker#976

Signed-off-by: Nikita Dubrovskii <[email protected]>
  • Loading branch information
nikita-dubrovskii committed Sep 30, 2021
1 parent 31c5adf commit b3a8cbb
Showing 1 changed file with 36 additions and 0 deletions.
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

0 comments on commit b3a8cbb

Please sign in to comment.