@@ -12,7 +12,7 @@ mod osbuild;
12
12
pub ( crate ) mod osconfig;
13
13
14
14
use std:: io:: Write ;
15
- use std:: os:: fd:: AsFd ;
15
+ use std:: os:: fd:: { AsFd , AsRawFd } ;
16
16
use std:: os:: unix:: process:: CommandExt ;
17
17
use std:: path:: Path ;
18
18
use std:: process:: Command ;
@@ -581,18 +581,16 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
581
581
let sepolicy = sepolicy. as_ref ( ) ;
582
582
// Load a fd for the mounted target physical root
583
583
let rootfs_dir = & root_setup. rootfs_fd ;
584
- let rootfs = root_setup. rootfs . as_path ( ) ;
585
584
let cancellable = gio:: Cancellable :: NONE ;
586
585
587
586
let stateroot = state. stateroot ( ) ;
588
587
589
588
let has_ostree = rootfs_dir. try_exists ( "ostree/repo" ) ?;
590
589
if !has_ostree {
591
- Task :: new_and_run (
592
- "Initializing ostree layout" ,
593
- "ostree" ,
594
- [ "admin" , "init-fs" , "--modern" , rootfs. as_str ( ) ] ,
595
- ) ?;
590
+ Task :: new ( "Initializing ostree layout" , "ostree" )
591
+ . args ( [ "admin" , "init-fs" , "--modern" , "." ] )
592
+ . cwd ( rootfs_dir) ?
593
+ . run ( ) ?;
596
594
} else {
597
595
println ! ( "Reusing extant ostree layout" ) ;
598
596
@@ -607,8 +605,7 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
607
605
crate :: lsm:: ensure_dir_labeled ( rootfs_dir, "" , Some ( "/" . into ( ) ) , 0o755 . into ( ) , sepolicy) ?;
608
606
609
607
// And also label /boot AKA xbootldr, if it exists
610
- let bootdir = rootfs. join ( "boot" ) ;
611
- if bootdir. try_exists ( ) ? {
608
+ if rootfs_dir. try_exists ( "boot" ) ? {
612
609
crate :: lsm:: ensure_dir_labeled ( rootfs_dir, "boot" , None , 0o755 . into ( ) , sepolicy) ?;
613
610
}
614
611
@@ -626,7 +623,10 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
626
623
. run ( ) ?;
627
624
}
628
625
629
- let sysroot = ostree:: Sysroot :: new ( Some ( & gio:: File :: for_path ( rootfs) ) ) ;
626
+ let sysroot = {
627
+ let path = format ! ( "/proc/self/fd/{}" , rootfs_dir. as_fd( ) . as_raw_fd( ) ) ;
628
+ ostree:: Sysroot :: new ( Some ( & gio:: File :: for_path ( path) ) )
629
+ } ;
630
630
sysroot. load ( cancellable) ?;
631
631
632
632
let stateroot_exists = rootfs_dir. try_exists ( format ! ( "ostree/deploy/{stateroot}" ) ) ?;
@@ -661,7 +661,6 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result
661
661
) ?;
662
662
}
663
663
664
- let sysroot = ostree:: Sysroot :: new ( Some ( & gio:: File :: for_path ( rootfs) ) ) ;
665
664
sysroot. load ( cancellable) ?;
666
665
let sysroot = SysrootLock :: new_from_sysroot ( & sysroot) . await ?;
667
666
Ok ( ( Storage :: new ( sysroot, & temp_run) ?, has_ostree) )
@@ -999,24 +998,29 @@ pub(crate) fn reexecute_self_for_selinux_if_needed(
999
998
1000
999
/// Trim, flush outstanding writes, and freeze/thaw the target mounted filesystem;
1001
1000
/// these steps prepare the filesystem for its first booted use.
1002
- pub ( crate ) fn finalize_filesystem ( fs : & Utf8Path ) -> Result < ( ) > {
1003
- let fsname = fs. file_name ( ) . unwrap ( ) ;
1001
+ pub ( crate ) fn finalize_filesystem (
1002
+ fsname : & str ,
1003
+ root : & Dir ,
1004
+ path : impl AsRef < Utf8Path > ,
1005
+ ) -> Result < ( ) > {
1006
+ let path = path. as_ref ( ) ;
1004
1007
// fstrim ensures the underlying block device knows about unused space
1005
- Task :: new_and_run (
1006
- format ! ( "Trimming {fsname}" ) ,
1007
- "fstrim" ,
1008
- [ "--quiet-unsupported" , "-v" , fs. as_str ( ) ] ,
1009
- ) ?;
1008
+ Task :: new ( format ! ( "Trimming {fsname}" ) , "fstrim" )
1009
+ . args ( [ "--quiet-unsupported" , "-v" , path. as_str ( ) ] )
1010
+ . cwd ( root) ?
1011
+ . run ( ) ?;
1010
1012
// Remounting readonly will flush outstanding writes and ensure we error out if there were background
1011
1013
// writeback problems.
1012
1014
Task :: new ( format ! ( "Finalizing filesystem {fsname}" ) , "mount" )
1013
- . args ( [ "-o" , "remount,ro" , fs. as_str ( ) ] )
1015
+ . cwd ( root) ?
1016
+ . args ( [ "-o" , "remount,ro" , path. as_str ( ) ] )
1014
1017
. run ( ) ?;
1015
1018
// Finally, freezing (and thawing) the filesystem will flush the journal, which means the next boot is clean.
1016
1019
for a in [ "-f" , "-u" ] {
1017
1020
Task :: new ( "Flushing filesystem journal" , "fsfreeze" )
1018
1021
. quiet ( )
1019
- . args ( [ a, fs. as_str ( ) ] )
1022
+ . cwd ( root) ?
1023
+ . args ( [ a, path. as_str ( ) ] )
1020
1024
. run ( ) ?;
1021
1025
}
1022
1026
Ok ( ( ) )
@@ -1419,10 +1423,9 @@ async fn install_to_filesystem_impl(state: &State, rootfs: &mut RootSetup) -> Re
1419
1423
1420
1424
// Finalize mounted filesystems
1421
1425
if !rootfs. skip_finalize {
1422
- let bootfs = rootfs. boot . as_ref ( ) . map ( |_| rootfs. rootfs . join ( "boot" ) ) ;
1423
- let bootfs = bootfs. as_ref ( ) . map ( |p| p. as_path ( ) ) ;
1424
- for fs in std:: iter:: once ( rootfs. rootfs . as_path ( ) ) . chain ( bootfs) {
1425
- finalize_filesystem ( fs) ?;
1426
+ let bootfs = rootfs. boot . as_ref ( ) . map ( |_| ( "boot" , "boot" ) ) ;
1427
+ for ( fsname, fs) in std:: iter:: once ( ( "root" , "." ) ) . chain ( bootfs) {
1428
+ finalize_filesystem ( fsname, & rootfs. rootfs_fd , fs) ?;
1426
1429
}
1427
1430
}
1428
1431
0 commit comments