@@ -5,20 +5,29 @@ 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" ) ;
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