@@ -14,6 +14,7 @@ mod osbuild;
1414pub ( crate ) mod osconfig;
1515
1616use std:: collections:: HashMap ;
17+ use std:: fs:: create_dir_all;
1718use std:: io:: Write ;
1819use std:: os:: fd:: { AsFd , AsRawFd } ;
1920use std:: os:: unix:: process:: CommandExt ;
@@ -40,9 +41,11 @@ use fn_error_context::context;
4041use ostree:: gio;
4142use ostree_ext:: composefs:: {
4243 fsverity:: { FsVerityHashValue , Sha256HashValue } ,
44+ oci:: image:: create_filesystem as create_composefs_filesystem,
4345 oci:: pull as composefs_oci_pull,
4446 repository:: Repository as ComposefsRepository ,
4547 util:: Sha256Digest ,
48+ write_boot:: write_boot_simple as composefs_write_boot_simple,
4649} ;
4750use ostree_ext:: oci_spec;
4851use ostree_ext:: ostree;
@@ -1437,6 +1440,11 @@ impl BoundImages {
14371440 }
14381441}
14391442
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+
14401448async fn initialize_composefs_repository (
14411449 state : & State ,
14421450 root_setup : & RootSetup ,
@@ -1449,15 +1457,80 @@ async fn initialize_composefs_repository(
14491457
14501458 tracing:: warn!( "STATE: {state:#?}" ) ;
14511459
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) ?;
14541461
14551462 let OstreeExtImgRef { transport, name } = & state. target_imgref . imgref ;
14561463
14571464 // transport's display is already of type "<transport_type>:"
14581465 composefs_oci_pull ( & Arc :: new ( repo) , & format ! ( "{transport}{name}" , ) , None ) . await
14591466}
14601467
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+
14611534async fn install_to_filesystem_impl (
14621535 state : & State ,
14631536 rootfs : & mut RootSetup ,
@@ -1500,6 +1573,8 @@ async fn install_to_filesystem_impl(
15001573 id = hex:: encode( id) ,
15011574 verity = verity. to_hex( )
15021575 ) ;
1576+
1577+ setup_composefs_boot ( rootfs, state, & hex:: encode ( id) ) ?;
15031578 } else {
15041579 // Initialize the ostree sysroot (repo, stateroot, etc.)
15051580
0 commit comments