@@ -542,15 +542,9 @@ pub(crate) fn print_configuration() -> Result<()> {
542
542
}
543
543
544
544
#[ context( "Creating ostree deployment" ) ]
545
- async fn initialize_ostree_root_from_self (
546
- state : & State ,
547
- root_setup : & RootSetup ,
548
- ) -> Result < InstallAleph > {
545
+ async fn initialize_ostree_root ( state : & State , root_setup : & RootSetup ) -> Result < ostree:: Sysroot > {
549
546
let sepolicy = state. load_policy ( ) ?;
550
547
let sepolicy = sepolicy. as_ref ( ) ;
551
-
552
- let container_rootfs = & Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
553
-
554
548
// Load a fd for the mounted target physical root
555
549
let rootfs_dir = & root_setup. rootfs_fd ;
556
550
let rootfs = root_setup. rootfs . as_path ( ) ;
@@ -607,6 +601,20 @@ async fn initialize_ostree_root_from_self(
607
601
608
602
let sysroot = ostree:: Sysroot :: new ( Some ( & gio:: File :: for_path ( rootfs) ) ) ;
609
603
sysroot. load ( cancellable) ?;
604
+ Ok ( sysroot)
605
+ }
606
+
607
+ #[ context( "Creating ostree deployment" ) ]
608
+ async fn install_container (
609
+ state : & State ,
610
+ root_setup : & RootSetup ,
611
+ sysroot : & ostree:: Sysroot ,
612
+ ) -> Result < ( ostree:: Deployment , InstallAleph ) > {
613
+ let sepolicy = state. load_policy ( ) ?;
614
+ let sepolicy = sepolicy. as_ref ( ) ;
615
+ let stateroot = STATEROOT_DEFAULT ;
616
+
617
+ let container_rootfs = & Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
610
618
611
619
let ( src_imageref, proxy_cfg) = if !state. source . in_host_mountns {
612
620
( state. source . imageref . clone ( ) , None )
@@ -692,15 +700,15 @@ async fn initialize_ostree_root_from_self(
692
700
)
693
701
. await ?;
694
702
695
- sysroot. load ( cancellable) ?;
696
703
let deployment = sysroot
697
704
. deployments ( )
698
705
. into_iter ( )
699
706
. next ( )
700
707
. ok_or_else ( || anyhow:: anyhow!( "Failed to find deployment" ) ) ?;
701
708
// SAFETY: There must be a path
702
709
let path = sysroot. deployment_dirpath ( & deployment) ;
703
- let root = rootfs_dir
710
+ let root = root_setup
711
+ . rootfs_fd
704
712
. open_dir ( path. as_str ( ) )
705
713
. context ( "Opening deployment dir" ) ?;
706
714
@@ -713,7 +721,7 @@ async fn initialize_ostree_root_from_self(
713
721
for d in [ "ostree" , "boot" ] {
714
722
let mut pathbuf = Utf8PathBuf :: from ( d) ;
715
723
crate :: lsm:: ensure_dir_labeled_recurse (
716
- rootfs_dir ,
724
+ & root_setup . rootfs_fd ,
717
725
& mut pathbuf,
718
726
policy,
719
727
Some ( deployment_root_devino) ,
@@ -758,7 +766,7 @@ async fn initialize_ostree_root_from_self(
758
766
selinux : state. selinux_state . to_aleph ( ) . to_string ( ) ,
759
767
} ;
760
768
761
- Ok ( aleph)
769
+ Ok ( ( deployment , aleph) )
762
770
}
763
771
764
772
/// Run a command in the host mount namespace
@@ -1223,17 +1231,19 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
1223
1231
. ok_or_else ( || anyhow ! ( "No uuid for boot/root" ) ) ?;
1224
1232
tracing:: debug!( "boot uuid={boot_uuid}" ) ;
1225
1233
1234
+ // Initialize the ostree sysroot (repo, stateroot, etc.)
1235
+ let sysroot = initialize_ostree_root ( state, rootfs) . await ?;
1236
+ // And actually set up the container in that root, returning a deployment and
1237
+ // the aleph state (see below).
1238
+ let ( deployment, aleph) = install_container ( state, rootfs, & sysroot) . await ?;
1226
1239
// Write the aleph data that captures the system state at the time of provisioning for aid in future debugging.
1227
- {
1228
- let aleph = initialize_ostree_root_from_self ( state, rootfs) . await ?;
1229
- rootfs
1230
- . rootfs_fd
1231
- . atomic_replace_with ( BOOTC_ALEPH_PATH , |f| {
1232
- serde_json:: to_writer ( f, & aleph) ?;
1233
- anyhow:: Ok ( ( ) )
1234
- } )
1235
- . context ( "Writing aleph version" ) ?;
1236
- }
1240
+ rootfs
1241
+ . rootfs_fd
1242
+ . atomic_replace_with ( BOOTC_ALEPH_PATH , |f| {
1243
+ serde_json:: to_writer ( f, & aleph) ?;
1244
+ anyhow:: Ok ( ( ) )
1245
+ } )
1246
+ . context ( "Writing aleph version" ) ?;
1237
1247
if cfg ! ( target_arch = "s390x" ) {
1238
1248
// TODO: Integrate s390x support into install_via_bootupd
1239
1249
crate :: bootloader:: install_via_zipl ( & rootfs. device_info , boot_uuid) ?;
@@ -1245,6 +1255,10 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
1245
1255
) ?;
1246
1256
}
1247
1257
1258
+ // After this point, we need to drop all open references to the filesystem
1259
+ drop ( deployment) ;
1260
+ drop ( sysroot) ;
1261
+
1248
1262
tracing:: debug!( "Installed bootloader" ) ;
1249
1263
1250
1264
// Finalize mounted filesystems
0 commit comments