diff --git a/src/bin/rdcore/rootmap.rs b/src/bin/rdcore/rootmap.rs index 5036e1f05..c07a4e469 100644 --- a/src/bin/rdcore/rootmap.rs +++ b/src/bin/rdcore/rootmap.rs @@ -85,9 +85,9 @@ pub fn get_boot_mount_from_cmdline_args( if let Some(path) = boot_mount { Ok(Some(Mount::from_existing(path)?)) } else if let Some(devpath) = boot_device { - let devinfo = lsblk_single(Path::new(devpath))?; + let devinfo = blkid_single(Path::new(devpath))?; let fs = devinfo - .get("FSTYPE") + .get("TYPE") .with_context(|| format!("failed to query filesystem for {}", devpath))?; Ok(Some(Mount::try_mount( devpath, @@ -100,10 +100,7 @@ pub fn get_boot_mount_from_cmdline_args( } fn device_to_kargs(root: &Mount, device: PathBuf) -> Result>> { - let blkinfo = lsblk_single(&device)?; - let blktype = blkinfo - .get("TYPE") - .with_context(|| format!("missing TYPE for {}", device.display()))?; + let blktype = get_block_device_type(&device)?; // a `match {}` construct would be nice here, but for RAID it's a prefix match if blktype.starts_with("raid") || blktype == "linear" { Ok(Some(get_raid_kargs(&device)?)) diff --git a/src/blockdev.rs b/src/blockdev.rs index 1e11da3ac..d1597a1ce 100644 --- a/src/blockdev.rs +++ b/src/blockdev.rs @@ -466,7 +466,7 @@ impl Mount { } pub fn get_filesystem_uuid(&self) -> Result { - let devinfo = lsblk_single(Path::new(&self.device))?; + let devinfo = blkid_single(Path::new(&self.device))?; devinfo .get("UUID") .map(String::from) @@ -772,13 +772,16 @@ fn read_sysfs_dev_block_value(maj: u64, min: u64, field: &str) -> Result Ok(read_to_string(&path)?.trim_end().into()) } -pub fn lsblk_single(dev: &Path) -> Result> { +pub fn get_block_device_type(dev: &Path) -> Result { let mut devinfos = lsblk(Path::new(dev), false)?; if devinfos.is_empty() { // this should never happen because `lsblk` itself would've failed bail!("no lsblk results for {}", dev.display()); } - Ok(devinfos.remove(0)) + devinfos + .remove(0) + .remove("TYPE") + .with_context(|| format!("missing TYPE for {}", dev.display())) } /// Returns all available filesystems. @@ -876,6 +879,17 @@ fn blkid() -> Result>> { Ok(result) } +pub fn blkid_single(dev: &Path) -> Result> { + let mut cmd = Command::new("blkid"); + cmd.arg(dev); + let output = cmd_output(&mut cmd)?; + if output.is_empty() { + // this should never happen because `blkid` itself would've failed + bail!("no blkid results for {}", dev.display()); + } + Ok(split_blkid_line(&output)) +} + /// This is a bit fuzzy, but... this function will return every block device in the parent /// hierarchy of `device` capable of containing other partitions. So e.g. parent devices of type /// "part" doesn't match, but "disk" and "mpath" does.