@@ -14,6 +14,7 @@ mod osbuild;
14
14
pub ( crate ) mod osconfig;
15
15
16
16
use std:: collections:: HashMap ;
17
+ use std:: fs:: create_dir_all;
17
18
use std:: io:: Write ;
18
19
use std:: os:: fd:: { AsFd , AsRawFd } ;
19
20
use std:: os:: unix:: process:: CommandExt ;
@@ -40,9 +41,11 @@ use fn_error_context::context;
40
41
use ostree:: gio;
41
42
use ostree_ext:: composefs:: {
42
43
fsverity:: { FsVerityHashValue , Sha256HashValue } ,
44
+ oci:: image:: create_filesystem as create_composefs_filesystem,
43
45
oci:: pull as composefs_oci_pull,
44
46
repository:: Repository as ComposefsRepository ,
45
47
util:: Sha256Digest ,
48
+ write_boot:: write_boot_simple as composefs_write_boot_simple,
46
49
} ;
47
50
use ostree_ext:: oci_spec;
48
51
use ostree_ext:: ostree;
@@ -1437,6 +1440,11 @@ impl BoundImages {
1437
1440
}
1438
1441
}
1439
1442
1443
+ fn open_composefs_repo ( rootfs_dir : & Dir ) -> Result < ComposefsRepository < Sha256HashValue > > {
1444
+ ComposefsRepository :: open_path ( rootfs_dir, "composefs" )
1445
+ . context ( "Failed to open composefs repository" )
1446
+ }
1447
+
1440
1448
async fn initialize_composefs_repository (
1441
1449
state : & State ,
1442
1450
root_setup : & RootSetup ,
@@ -1449,15 +1457,80 @@ async fn initialize_composefs_repository(
1449
1457
1450
1458
tracing:: warn!( "STATE: {state:#?}" ) ;
1451
1459
1452
- let repo: ComposefsRepository < Sha256HashValue > =
1453
- ComposefsRepository :: open_path ( rootfs_dir, "composefs" ) . expect ( "failed to open_path" ) ;
1460
+ let repo = open_composefs_repo ( rootfs_dir) ?;
1454
1461
1455
1462
let OstreeExtImgRef { transport, name } = & state. target_imgref . imgref ;
1456
1463
1457
1464
// transport's display is already of type "<transport_type>:"
1458
1465
composefs_oci_pull ( & Arc :: new ( repo) , & format ! ( "{transport}{name}" , ) , None ) . await
1459
1466
}
1460
1467
1468
+ #[ context( "Setting up composefs boot" ) ]
1469
+ fn setup_composefs_boot ( root_setup : & RootSetup , state : & State , image_id : & str ) -> Result < ( ) > {
1470
+ let boot_uuid = root_setup
1471
+ . get_boot_uuid ( ) ?
1472
+ . or ( root_setup. rootfs_uuid . as_deref ( ) )
1473
+ . ok_or_else ( || anyhow ! ( "No uuid for boot/root" ) ) ?;
1474
+
1475
+ if cfg ! ( target_arch = "s390x" ) {
1476
+ // TODO: Integrate s390x support into install_via_bootupd
1477
+ crate :: bootloader:: install_via_zipl ( & root_setup. device_info , boot_uuid) ?;
1478
+ } else {
1479
+ crate :: bootloader:: install_via_bootupd (
1480
+ & root_setup. device_info ,
1481
+ & root_setup. physical_root_path ,
1482
+ & state. config_opts ,
1483
+ ) ?;
1484
+ }
1485
+
1486
+ let repo = open_composefs_repo ( & root_setup. physical_root ) ?;
1487
+
1488
+ let mut fs = create_composefs_filesystem ( & repo, image_id, None ) ?;
1489
+
1490
+ let entries = fs. transform_for_boot ( & repo) ?;
1491
+ let id = fs. commit_image ( & repo, None ) ?;
1492
+
1493
+ println ! ( "{entries:#?}" ) ;
1494
+
1495
+ let Some ( entry) = entries. into_iter ( ) . next ( ) else {
1496
+ anyhow:: bail!( "No boot entries!" ) ;
1497
+ } ;
1498
+
1499
+ let rootfs_uuid = match & root_setup. rootfs_uuid {
1500
+ Some ( u) => u,
1501
+ None => anyhow:: bail!( "Expected rootfs to have a UUID by now" ) ,
1502
+ } ;
1503
+
1504
+ let cmdline_refs = [
1505
+ "console=ttyS0,115200" ,
1506
+ & format ! ( "root=UUID={rootfs_uuid}" ) ,
1507
+ "rw" ,
1508
+ ] ;
1509
+
1510
+ let boot_dir = root_setup. physical_root_path . join ( "boot" ) ;
1511
+ create_dir_all ( & boot_dir) . context ( "Failed to create boot dir" ) ?;
1512
+
1513
+ composefs_write_boot_simple (
1514
+ & repo,
1515
+ entry,
1516
+ & id,
1517
+ boot_dir. as_std_path ( ) ,
1518
+ Some ( & format ! ( "{}" , id. to_hex( ) ) ) ,
1519
+ Some ( "/boot" ) ,
1520
+ & cmdline_refs,
1521
+ ) ?;
1522
+
1523
+ let state_path = root_setup
1524
+ . physical_root_path
1525
+ . join ( format ! ( "state/{}" , id. to_hex( ) ) ) ;
1526
+
1527
+ create_dir_all ( state_path. join ( "var" ) ) ?;
1528
+ create_dir_all ( state_path. join ( "etc/upper" ) ) ?;
1529
+ create_dir_all ( state_path. join ( "etc/work" ) ) ?;
1530
+
1531
+ Ok ( ( ) )
1532
+ }
1533
+
1461
1534
async fn install_to_filesystem_impl (
1462
1535
state : & State ,
1463
1536
rootfs : & mut RootSetup ,
@@ -1500,6 +1573,8 @@ async fn install_to_filesystem_impl(
1500
1573
id = hex:: encode( id) ,
1501
1574
verity = verity. to_hex( )
1502
1575
) ;
1576
+
1577
+ setup_composefs_boot ( rootfs, state, & hex:: encode ( id) ) ?;
1503
1578
} else {
1504
1579
// Initialize the ostree sysroot (repo, stateroot, etc.)
1505
1580
0 commit comments