@@ -247,7 +247,7 @@ pub(crate) struct InstallConfigOpts {
247
247
pub ( crate ) stateroot : Option < String > ,
248
248
}
249
249
250
- #[ derive( Debug , Clone , clap:: Parser , Serialize , Deserialize , PartialEq , Eq ) ]
250
+ #[ derive( Debug , Default , Clone , clap:: Parser , Serialize , Deserialize , PartialEq , Eq ) ]
251
251
pub ( crate ) struct InstallComposefsOpts {
252
252
#[ clap( long, default_value_t) ]
253
253
#[ serde( default ) ]
@@ -438,6 +438,10 @@ pub(crate) struct State {
438
438
pub ( crate ) container_root : Dir ,
439
439
pub ( crate ) tempdir : TempDir ,
440
440
441
+ /// Set if we have determined that composefs is required
442
+ #[ allow( dead_code) ]
443
+ pub ( crate ) composefs_required : bool ,
444
+
441
445
// If Some, then --composefs_native is passed
442
446
#[ cfg( feature = "composefs-backend" ) ]
443
447
pub ( crate ) composefs_options : Option < InstallComposefsOpts > ,
@@ -793,6 +797,7 @@ async fn install_container(
793
797
let sepolicy = sepolicy. as_ref ( ) ;
794
798
let stateroot = state. stateroot ( ) ;
795
799
800
+ // TODO factor out this
796
801
let ( src_imageref, proxy_cfg) = if !state. source . in_host_mountns {
797
802
( state. source . imageref . clone ( ) , None )
798
803
} else {
@@ -1221,20 +1226,28 @@ async fn verify_target_fetch(
1221
1226
Ok ( ( ) )
1222
1227
}
1223
1228
1229
+ fn root_has_uki ( root : & Dir ) -> Result < bool > {
1230
+ #[ cfg( feature = "composefs-backend" ) ]
1231
+ return crate :: bootc_composefs:: boot:: container_root_has_uki ( root) ;
1232
+
1233
+ #[ cfg( not( feature = "composefs-backend" ) ) ]
1234
+ Ok ( false )
1235
+ }
1236
+
1224
1237
/// Preparation for an install; validates and prepares some (thereafter immutable) global state.
1225
1238
async fn prepare_install (
1226
1239
config_opts : InstallConfigOpts ,
1227
1240
source_opts : InstallSourceOpts ,
1228
1241
target_opts : InstallTargetOpts ,
1229
- _composefs_opts : Option < InstallComposefsOpts > ,
1242
+ composefs_options : Option < InstallComposefsOpts > ,
1230
1243
) -> Result < Arc < State > > {
1231
1244
tracing:: trace!( "Preparing install" ) ;
1232
1245
let rootfs = cap_std:: fs:: Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) )
1233
1246
. context ( "Opening /" ) ?;
1234
1247
1235
1248
let host_is_container = crate :: containerenv:: is_container ( & rootfs) ;
1236
1249
let external_source = source_opts. source_imgref . is_some ( ) ;
1237
- let source = match source_opts. source_imgref {
1250
+ let ( source, target_rootfs ) = match source_opts. source_imgref {
1238
1251
None => {
1239
1252
ensure ! ( host_is_container, "Either --source-imgref must be defined or this command must be executed inside a podman container." ) ;
1240
1253
@@ -1259,11 +1272,13 @@ async fn prepare_install(
1259
1272
} ;
1260
1273
tracing:: trace!( "Read container engine info {:?}" , container_info) ;
1261
1274
1262
- SourceInfo :: from_container ( & rootfs, & container_info) ?
1275
+ let source = SourceInfo :: from_container ( & rootfs, & container_info) ?;
1276
+ ( source, Some ( rootfs. try_clone ( ) ?) )
1263
1277
}
1264
1278
Some ( source) => {
1265
1279
crate :: cli:: require_root ( false ) ?;
1266
- SourceInfo :: from_imageref ( & source, & rootfs) ?
1280
+ let source = SourceInfo :: from_imageref ( & source, & rootfs) ?;
1281
+ ( source, None )
1267
1282
}
1268
1283
} ;
1269
1284
@@ -1291,6 +1306,15 @@ async fn prepare_install(
1291
1306
} ;
1292
1307
tracing:: debug!( "Target image reference: {target_imgref}" ) ;
1293
1308
1309
+ let composefs_required = if let Some ( root) = target_rootfs. as_ref ( ) {
1310
+ root_has_uki ( root) ?
1311
+ } else {
1312
+ false
1313
+ } ;
1314
+ tracing:: debug!( "Composefs required: {composefs_required}" ) ;
1315
+ let composefs_options =
1316
+ composefs_options. or_else ( || composefs_required. then_some ( InstallComposefsOpts :: default ( ) ) ) ;
1317
+
1294
1318
// We need to access devices that are set up by the host udev
1295
1319
bootc_mount:: ensure_mirrored_host_mount ( "/dev" ) ?;
1296
1320
// We need to read our own container image (and any logically bound images)
@@ -1371,8 +1395,9 @@ async fn prepare_install(
1371
1395
container_root : rootfs,
1372
1396
tempdir,
1373
1397
host_is_container,
1398
+ composefs_required,
1374
1399
#[ cfg( feature = "composefs-backend" ) ]
1375
- composefs_options : _composefs_opts ,
1400
+ composefs_options,
1376
1401
} ) ;
1377
1402
1378
1403
Ok ( state)
0 commit comments