@@ -5,7 +5,7 @@ use anyhow::{bail, Context, Result};
55use bootc_blockdev:: PartitionTable ;
66use 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 " ) ]
99pub 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" ) ;
@@ -14,10 +14,18 @@ pub fn get_devices<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
1414 }
1515 let bootdir = openat:: Dir :: open ( & bootdir) ?;
1616 // Run findmnt to get the source path of mount point boot
17- let fsinfo = crate :: filesystem:: inspect_filesystem ( & bootdir, "." ) ?;
17+ // If failed, change to sysroot
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+ let fsinfo = crate :: filesystem:: inspect_filesystem ( & sysrootdir, "." ) ?;
24+ fsinfo. source
25+ } ;
1826 // 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) ) ?;
27+ let parent_devices = bootc_blockdev:: find_parent_devices ( & source)
28+ . with_context ( || format ! ( "while looking for backing devices of {}" , source) ) ?;
2129 log:: debug!( "Find parent devices: {parent_devices:?}" ) ;
2230 Ok ( parent_devices)
2331}
0 commit comments