Skip to content

Commit e9af43a

Browse files
committed
blockdev: Use /sysroot as fallback in get_devices() if
`/boot` is not mounted Get pointer from coreos#855 (comment) If `/boot` is not mounted, the parent devices of `/sysroot` will be used as a fallback.
1 parent 5ac2788 commit e9af43a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/blockdev.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,29 @@ use anyhow::{bail, Context, Result};
55
use bootc_blockdev::PartitionTable;
66
use fn_error_context::context;
77

8-
#[context("get parent devices from mount point boot")]
8+
#[context("get parent devices from mount point boot or sysroot")]
99
pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
1010
let target_root = target_root.as_ref();
1111
let bootdir = target_root.join("boot");
1212
if !bootdir.exists() {
1313
bail!("{} does not exist", bootdir.display());
1414
}
1515
let bootdir = openat::Dir::open(&bootdir)?;
16-
// Run findmnt to get the source path of mount point boot
17-
let fsinfo = crate::filesystem::inspect_filesystem(&bootdir, ".")?;
16+
// Attempt to get the source path of the /boot mount point using findmnt
17+
// Fallback to /sysroot if the command fails
18+
let source = if let Ok(fsinfo) = crate::filesystem::inspect_filesystem(&bootdir, ".") {
19+
fsinfo.source
20+
} else {
21+
let sysroot = target_root.join("sysroot");
22+
let sysrootdir = openat::Dir::open(&sysroot)
23+
.with_context(|| format!("Opening sysroot {}", sysroot.display()))?;
24+
let fsinfo = crate::filesystem::inspect_filesystem(&sysrootdir, ".")?;
25+
fsinfo.source
26+
};
1827
// Find the parent devices of the source path
19-
let parent_devices = bootc_blockdev::find_parent_devices(&fsinfo.source)
20-
.with_context(|| format!("while looking for backing devices of {}", fsinfo.source))?;
21-
log::debug!("Find parent devices: {parent_devices:?}");
28+
let parent_devices = bootc_blockdev::find_parent_devices(&source)
29+
.with_context(|| format!("While looking for backing devices of {}", source))?;
30+
log::debug!("Found parent devices: {parent_devices:?}");
2231
Ok(parent_devices)
2332
}
2433

0 commit comments

Comments
 (0)