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