@@ -1084,6 +1084,8 @@ pub(crate) struct RootSetup {
10841084 pub ( crate ) physical_root_path : Utf8PathBuf ,
10851085 /// Directory file descriptor for the above physical root.
10861086 pub ( crate ) physical_root : Dir ,
1087+ /// Target root path like /target.
1088+ pub ( crate ) target_root_path : Option < Utf8PathBuf > ,
10871089 pub ( crate ) rootfs_uuid : Option < String > ,
10881090 /// True if we should skip finalizing
10891091 skip_finalize : bool ,
@@ -1538,7 +1540,10 @@ async fn install_with_sysroot(
15381540 Bootloader :: Grub => {
15391541 crate :: bootloader:: install_via_bootupd (
15401542 & rootfs. device_info ,
1541- & rootfs. physical_root_path ,
1543+ & rootfs
1544+ . target_root_path
1545+ . clone ( )
1546+ . unwrap_or ( rootfs. physical_root_path . clone ( ) ) ,
15421547 & state. config_opts ,
15431548 Some ( & deployment_path. as_str ( ) ) ,
15441549 ) ?;
@@ -2011,6 +2016,20 @@ pub(crate) async fn install_to_filesystem(
20112016 . context ( "Mounting host / to {ALONGSIDE_ROOT_MOUNT}" ) ?;
20122017 }
20132018
2019+ let target_root_path = & fsopts. root_path . clone ( ) ;
2020+ // Get a file descriptor for the root path /target
2021+ let target_rootfs_fd = {
2022+ let rootfs_fd = Dir :: open_ambient_dir ( & target_root_path, cap_std:: ambient_authority ( ) )
2023+ . with_context ( || format ! ( "Opening target root directory {target_root_path}" ) ) ?;
2024+
2025+ tracing:: debug!( "Root filesystem: {target_root_path}" ) ;
2026+
2027+ if let Some ( false ) = rootfs_fd. is_mountpoint ( "." ) ? {
2028+ anyhow:: bail!( "Not a mountpoint: {target_root_path}" ) ;
2029+ }
2030+ rootfs_fd
2031+ } ;
2032+
20142033 // Check that the target is a directory
20152034 {
20162035 let root_path = & fsopts. root_path ;
@@ -2043,7 +2062,7 @@ pub(crate) async fn install_to_filesystem(
20432062 } ;
20442063
20452064 // Get a file descriptor for the root path
2046- let rootfs_fd = {
2065+ let rootfs_fd = if fsopts . root_path . ends_with ( "sysroot" ) {
20472066 let root_path = & fsopts. root_path ;
20482067 let rootfs_fd = Dir :: open_ambient_dir ( & fsopts. root_path , cap_std:: ambient_authority ( ) )
20492068 . with_context ( || format ! ( "Opening target root directory {root_path}" ) ) ?;
@@ -2054,6 +2073,8 @@ pub(crate) async fn install_to_filesystem(
20542073 anyhow:: bail!( "Not a mountpoint: {root_path}" ) ;
20552074 }
20562075 rootfs_fd
2076+ } else {
2077+ target_rootfs_fd. try_clone ( ) ?
20572078 } ;
20582079
20592080 match fsopts. replace {
@@ -2063,7 +2084,9 @@ pub(crate) async fn install_to_filesystem(
20632084 tokio:: task:: spawn_blocking ( move || remove_all_in_dir_no_xdev ( & rootfs_fd, true ) )
20642085 . await ??;
20652086 }
2066- Some ( ReplaceMode :: Alongside ) => clean_boot_directories ( & rootfs_fd, is_already_ostree) ?,
2087+ Some ( ReplaceMode :: Alongside ) => {
2088+ clean_boot_directories ( & target_rootfs_fd, is_already_ostree) ?
2089+ }
20672090 None => require_empty_rootdir ( & rootfs_fd) ?,
20682091 }
20692092
@@ -2108,7 +2131,7 @@ pub(crate) async fn install_to_filesystem(
21082131
21092132 let boot_is_mount = {
21102133 let root_dev = rootfs_fd. dir_metadata ( ) ?. dev ( ) ;
2111- let boot_dev = rootfs_fd
2134+ let boot_dev = target_rootfs_fd
21122135 . symlink_metadata_optional ( BOOT ) ?
21132136 . ok_or_else ( || {
21142137 anyhow ! ( "No /{BOOT} directory found in root; this is is currently required" )
@@ -2119,9 +2142,10 @@ pub(crate) async fn install_to_filesystem(
21192142 } ;
21202143 // Find the UUID of /boot because we need it for GRUB.
21212144 let boot_uuid = if boot_is_mount {
2122- let boot_path = fsopts. root_path . join ( BOOT ) ;
2145+ let boot_path = target_root_path. join ( BOOT ) ;
2146+ tracing:: debug!( "boot_path={boot_path}" ) ;
21232147 let u = bootc_mount:: inspect_filesystem ( & boot_path)
2124- . context ( "Inspecting /{BOOT}" ) ?
2148+ . with_context ( || format ! ( "Inspecting /{BOOT}" ) ) ?
21252149 . uuid
21262150 . ok_or_else ( || anyhow ! ( "No UUID found for /{BOOT}" ) ) ?;
21272151 Some ( u)
@@ -2202,6 +2226,7 @@ pub(crate) async fn install_to_filesystem(
22022226 device_info,
22032227 physical_root_path : fsopts. root_path ,
22042228 physical_root : rootfs_fd,
2229+ target_root_path : Some ( target_root_path. clone ( ) ) ,
22052230 rootfs_uuid : inspect. uuid . clone ( ) ,
22062231 boot,
22072232 kargs,
0 commit comments