1
1
use std:: fmt:: Display ;
2
+ use std:: io:: BufWriter ;
3
+ use std:: io:: Write ;
2
4
use std:: process:: Command ;
3
5
use std:: process:: Stdio ;
4
6
use std:: sync:: Arc ;
@@ -245,9 +247,10 @@ fn bind_mount_from_host(src: impl AsRef<Utf8Path>, dest: impl AsRef<Utf8Path>) -
245
247
async fn initialize_ostree_root_from_self (
246
248
state : & State ,
247
249
containerstate : & ContainerExecutionInfo ,
248
- rootfs : & Utf8Path ,
250
+ root_setup : & RootSetup ,
249
251
kargs : & [ & str ] ,
250
252
) -> Result < InstallAleph > {
253
+ let rootfs = root_setup. rootfs . as_path ( ) ;
251
254
let opts = & state. opts ;
252
255
let cancellable = gio:: Cancellable :: NONE ;
253
256
@@ -306,11 +309,10 @@ async fn initialize_ostree_root_from_self(
306
309
307
310
let repopath = & rootfs. join ( "ostree/repo" ) ;
308
311
for ( k, v) in [ ( "sysroot.bootloader" , "none" ) , ( "sysroot.readonly" , "true" ) ] {
309
- Task :: new_and_run (
310
- "Configuring ostree repo" ,
311
- "ostree" ,
312
- [ "config" , "--repo" , repopath. as_str ( ) , "set" , k, v] ,
313
- ) ?;
312
+ Task :: new ( "Configuring ostree repo" , "ostree" )
313
+ . args ( [ "config" , "--repo" , repopath. as_str ( ) , "set" , k, v] )
314
+ . quiet ( )
315
+ . run ( ) ?;
314
316
}
315
317
Task :: new_and_run (
316
318
"Initializing sysroot" ,
@@ -359,6 +361,32 @@ async fn initialize_ostree_root_from_self(
359
361
360
362
drop ( temporary_dir) ;
361
363
364
+ // Write the entry for /boot to /etc/fstab. TODO: Encourage OSes to use the karg?
365
+ // Or better bind this with the grub data.
366
+ sysroot. load ( cancellable) ?;
367
+ let deployment = sysroot
368
+ . deployments ( )
369
+ . into_iter ( )
370
+ . next ( )
371
+ . ok_or_else ( || anyhow:: anyhow!( "Failed to find deployment" ) ) ?;
372
+ // SAFETY: There must be a path
373
+ let path = sysroot. deployment_dirpath ( & deployment) . unwrap ( ) ;
374
+ let sysroot_dir = cap_std:: fs:: Dir :: open_ambient_dir ( rootfs, cap_std:: ambient_authority ( ) )
375
+ . context ( "Opening rootfs" ) ?;
376
+ let root = sysroot_dir
377
+ . open_dir ( path. as_str ( ) )
378
+ . context ( "Opening deployment dir" ) ?;
379
+ let mut f = {
380
+ let mut opts = cap_std:: fs:: OpenOptions :: new ( ) ;
381
+ root. open_with ( "etc/fstab" , opts. append ( true ) . write ( true ) . create ( true ) )
382
+ . context ( "Opening etc/fstab" )
383
+ . map ( BufWriter :: new) ?
384
+ } ;
385
+ let boot_uuid = & root_setup. boot_uuid ;
386
+ let bootfs_type_str = root_setup. bootfs_type . to_string ( ) ;
387
+ writeln ! ( f, "UUID={boot_uuid} /boot {bootfs_type_str} defaults 1 2" ) ?;
388
+ f. flush ( ) ?;
389
+
362
390
let uname = cap_std_ext:: rustix:: process:: uname ( ) ;
363
391
364
392
let aleph = InstallAleph {
@@ -423,6 +451,7 @@ fn skopeo_supports_containers_storage() -> Result<bool> {
423
451
struct RootSetup {
424
452
device : Utf8PathBuf ,
425
453
rootfs : Utf8PathBuf ,
454
+ bootfs_type : Filesystem ,
426
455
boot_uuid : uuid:: Uuid ,
427
456
kargs : Vec < String > ,
428
457
}
@@ -551,10 +580,12 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
551
580
BlockSetup :: Tpm2Luks => anyhow:: bail!( "tpm2-luks is not implemented yet" ) ,
552
581
}
553
582
583
+ // TODO: make this configurable
584
+ let bootfs_type = Filesystem :: Ext4 ;
585
+
554
586
// Initialize the /boot filesystem
555
587
let bootdev = & format ! ( "{device}{BOOTPN}" ) ;
556
- let boot_uuid =
557
- mkfs ( bootdev, Filesystem :: Ext4 , Some ( "boot" ) , [ ] ) . context ( "Initializing /boot" ) ?;
588
+ let boot_uuid = mkfs ( bootdev, bootfs_type, Some ( "boot" ) , [ ] ) . context ( "Initializing /boot" ) ?;
558
589
559
590
// Initialize rootfs
560
591
let rootdev = & format ! ( "{device}{ROOTPN}" ) ;
@@ -575,11 +606,10 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
575
606
576
607
// Create the EFI system partition, if applicable
577
608
if let Some ( espdev) = espdev {
578
- Task :: new_and_run (
579
- "Creating ESP filesystem" ,
580
- "mkfs.fat" ,
581
- [ espdev. as_str ( ) , "-n" , "EFI-SYSTEM" ] ,
582
- ) ?;
609
+ Task :: new ( "Creating ESP filesystem" , "mkfs.fat" )
610
+ . args ( [ espdev. as_str ( ) , "-n" , "EFI-SYSTEM" ] )
611
+ . quiet_output ( )
612
+ . run ( ) ?;
583
613
let efifs_path = bootfs. join ( "efi" ) ;
584
614
std:: fs:: create_dir ( & efifs_path) . context ( "Creating efi dir" ) ?;
585
615
mount ( & espdev, & efifs_path) ?;
@@ -588,6 +618,7 @@ fn install_create_rootfs(state: &State) -> Result<RootSetup> {
588
618
Ok ( RootSetup {
589
619
device,
590
620
rootfs,
621
+ bootfs_type,
591
622
boot_uuid,
592
623
kargs,
593
624
} )
@@ -715,13 +746,9 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
715
746
kargs. push ( crate :: bootloader:: IGNITION_VARIABLE ) ;
716
747
}
717
748
718
- let aleph = initialize_ostree_root_from_self (
719
- & state,
720
- & container_state,
721
- & rootfs. rootfs ,
722
- kargs. as_slice ( ) ,
723
- )
724
- . await ?;
749
+ let aleph =
750
+ initialize_ostree_root_from_self ( & state, & container_state, & rootfs, kargs. as_slice ( ) )
751
+ . await ?;
725
752
726
753
let aleph = serde_json:: to_string ( & aleph) ?;
727
754
std:: fs:: write ( rootfs. rootfs . join ( BOOTC_ALEPH_PATH ) , aleph) . context ( "Writing aleph version" ) ?;
0 commit comments