@@ -15,6 +15,7 @@ mod osbuild;
15
15
pub ( crate ) mod osconfig;
16
16
17
17
use std:: collections:: HashMap ;
18
+ use std:: ffi:: OsStr ;
18
19
use std:: fs:: create_dir_all;
19
20
use std:: io:: Write ;
20
21
use std:: os:: fd:: { AsFd , AsRawFd } ;
@@ -43,6 +44,7 @@ use cap_std_ext::cmdext::CapStdExtCommandExt;
43
44
use cap_std_ext:: prelude:: CapStdExtDirExt ;
44
45
use clap:: ValueEnum ;
45
46
use composefs:: fs:: read_file;
47
+ use composefs:: tree:: FileSystem ;
46
48
use fn_error_context:: context;
47
49
use ostree:: gio;
48
50
use ostree_ext:: composefs:: {
@@ -52,7 +54,8 @@ use ostree_ext::composefs::{
52
54
} ;
53
55
use ostree_ext:: composefs_boot:: bootloader:: UsrLibModulesVmlinuz ;
54
56
use ostree_ext:: composefs_boot:: {
55
- bootloader:: BootEntry as ComposefsBootEntry , cmdline:: get_cmdline_composefs, uki, BootOps ,
57
+ bootloader:: BootEntry as ComposefsBootEntry , cmdline:: get_cmdline_composefs,
58
+ os_release:: OsReleaseInfo , uki, BootOps ,
56
59
} ;
57
60
use ostree_ext:: composefs_oci:: {
58
61
image:: create_filesystem as create_composefs_filesystem, pull as composefs_oci_pull,
@@ -1575,9 +1578,9 @@ fn get_booted_bls() -> Result<BLSConfig> {
1575
1578
1576
1579
pub ( crate ) enum BootSetupType < ' a > {
1577
1580
/// For initial setup, i.e. install to-disk
1578
- Setup ( ( & ' a RootSetup , & ' a State ) ) ,
1581
+ Setup ( ( & ' a RootSetup , & ' a State , & ' a FileSystem < Sha256HashValue > ) ) ,
1579
1582
/// For `bootc upgrade`
1580
- Upgrade ,
1583
+ Upgrade ( & ' a FileSystem < Sha256HashValue > ) ,
1581
1584
}
1582
1585
1583
1586
/// Compute SHA256Sum of VMlinuz + Initrd
@@ -1717,8 +1720,8 @@ pub(crate) fn setup_composefs_bls_boot(
1717
1720
) -> Result < String > {
1718
1721
let id_hex = id. to_hex ( ) ;
1719
1722
1720
- let ( esp_device, cmdline_refs) = match setup_type {
1721
- BootSetupType :: Setup ( ( root_setup, state) ) => {
1723
+ let ( esp_device, cmdline_refs, fs ) = match setup_type {
1724
+ BootSetupType :: Setup ( ( root_setup, state, fs ) ) => {
1722
1725
// root_setup.kargs has [root=UUID=<UUID>, "rw"]
1723
1726
let mut cmdline_options = String :: from ( root_setup. kargs . join ( " " ) ) ;
1724
1727
@@ -1739,10 +1742,10 @@ pub(crate) fn setup_composefs_bls_boot(
1739
1742
. find ( |p| p. parttype . as_str ( ) == ESP_GUID )
1740
1743
. ok_or_else ( || anyhow:: anyhow!( "ESP partition not found" ) ) ?;
1741
1744
1742
- ( esp_part. node . clone ( ) , cmdline_options)
1745
+ ( esp_part. node . clone ( ) , cmdline_options, fs )
1743
1746
}
1744
1747
1745
- BootSetupType :: Upgrade => {
1748
+ BootSetupType :: Upgrade ( fs ) => {
1746
1749
let sysroot = Utf8PathBuf :: from ( "/sysroot" ) ;
1747
1750
1748
1751
let fsinfo = inspect_filesystem ( & sysroot) ?;
@@ -1760,6 +1763,7 @@ pub(crate) fn setup_composefs_bls_boot(
1760
1763
format!( "{COMPOSEFS_CMDLINE}={id_hex}" ) ,
1761
1764
]
1762
1765
. join ( " " ) ,
1766
+ fs,
1763
1767
)
1764
1768
}
1765
1769
} ;
@@ -1774,10 +1778,11 @@ pub(crate) fn setup_composefs_bls_boot(
1774
1778
. run_inherited_with_cmd_context ( )
1775
1779
. context ( "Mounting EFI" ) ?;
1776
1780
1777
- let is_upgrade = matches ! ( setup_type, BootSetupType :: Upgrade ) ;
1781
+ let is_upgrade = matches ! ( setup_type, BootSetupType :: Upgrade ( .. ) ) ;
1778
1782
1779
1783
let efi_dir = Utf8PathBuf :: from_path_buf ( mounted_efi. join ( EFI_LINUX ) )
1780
1784
. map_err ( |_| anyhow:: anyhow!( "EFI dir is not valid UTF-8" ) ) ?;
1785
+
1781
1786
let ( bls_config, boot_digest) = match & entry {
1782
1787
ComposefsBootEntry :: Type1 ( ..) => unimplemented ! ( ) ,
1783
1788
ComposefsBootEntry :: Type2 ( ..) => unimplemented ! ( ) ,
@@ -1787,14 +1792,47 @@ pub(crate) fn setup_composefs_bls_boot(
1787
1792
let boot_digest = compute_boot_digest ( usr_lib_modules_vmlinuz, & repo)
1788
1793
. context ( "Computing boot digest" ) ?;
1789
1794
1795
+ // Every update should have its own /usr/lib/os-release
1796
+ let ( dir, fname) = fs
1797
+ . root
1798
+ . split ( OsStr :: new ( "/usr/lib/os-release" ) )
1799
+ . context ( "Getting /usr/lib/os-release" ) ?;
1800
+
1801
+ let os_release = dir
1802
+ . get_file_opt ( fname)
1803
+ . context ( "Getting /usr/lib/os-release" ) ?;
1804
+
1805
+ let version = os_release. and_then ( |os_rel_file| {
1806
+ let file_contents = match read_file ( os_rel_file, & repo) {
1807
+ Ok ( c) => c,
1808
+ Err ( e) => {
1809
+ tracing:: warn!( "Could not read /usr/lib/os-release: {e:?}" ) ;
1810
+ return None ;
1811
+ }
1812
+ } ;
1813
+
1814
+ let file_contents = match std:: str:: from_utf8 ( & file_contents) {
1815
+ Ok ( c) => c,
1816
+ Err ( ..) => {
1817
+ tracing:: warn!( "/usr/lib/os-release did not have valid UTF-8" ) ;
1818
+ return None ;
1819
+ }
1820
+ } ;
1821
+
1822
+ OsReleaseInfo :: parse ( file_contents) . get_version ( )
1823
+ } ) ;
1824
+
1825
+ let default_sort_key = "1" ;
1826
+
1790
1827
let mut bls_config = BLSConfig :: default ( ) ;
1791
- bls_config. title = Some ( id_hex. clone ( ) ) ;
1792
- bls_config. sort_key = Some ( "1" . into ( ) ) ;
1793
- bls_config. machine_id = None ;
1794
- bls_config. linux = format ! ( "/{EFI_LINUX}/{id_hex}/vmlinuz" ) ;
1795
- bls_config. initrd = vec ! [ format!( "/{EFI_LINUX}/{id_hex}/initrd" ) ] ;
1796
- bls_config. options = Some ( cmdline_refs) ;
1797
- bls_config. extra = HashMap :: new ( ) ;
1828
+
1829
+ bls_config
1830
+ . with_title ( id_hex. clone ( ) )
1831
+ . with_sort_key ( default_sort_key. into ( ) )
1832
+ . with_version ( version. unwrap_or ( default_sort_key. into ( ) ) )
1833
+ . with_linux ( format ! ( "/{EFI_LINUX}/{id_hex}/vmlinuz" ) )
1834
+ . with_initrd ( vec ! [ format!( "/{EFI_LINUX}/{id_hex}/initrd" ) ] )
1835
+ . with_options ( cmdline_refs) ;
1798
1836
1799
1837
if let Some ( symlink_to) = find_vmlinuz_initrd_duplicates ( & boot_digest) ? {
1800
1838
bls_config. linux = format ! ( "/{EFI_LINUX}/{symlink_to}/vmlinuz" ) ;
@@ -1901,7 +1939,7 @@ pub(crate) fn setup_composefs_uki_boot(
1901
1939
entry : ComposefsBootEntry < Sha256HashValue > ,
1902
1940
) -> Result < ( ) > {
1903
1941
let ( root_path, esp_device, is_insecure_from_opts) = match setup_type {
1904
- BootSetupType :: Setup ( ( root_setup, state) ) => {
1942
+ BootSetupType :: Setup ( ( root_setup, state, .. ) ) => {
1905
1943
if let Some ( v) = & state. config_opts . karg {
1906
1944
if v. len ( ) > 0 {
1907
1945
tracing:: warn!( "kargs passed for UKI will be ignored" ) ;
@@ -1922,7 +1960,7 @@ pub(crate) fn setup_composefs_uki_boot(
1922
1960
)
1923
1961
}
1924
1962
1925
- BootSetupType :: Upgrade => {
1963
+ BootSetupType :: Upgrade ( .. ) => {
1926
1964
let sysroot = Utf8PathBuf :: from ( "/sysroot" ) ;
1927
1965
1928
1966
let fsinfo = inspect_filesystem ( & sysroot) ?;
@@ -2014,7 +2052,7 @@ pub(crate) fn setup_composefs_uki_boot(
2014
2052
let boot_dir = root_path. join ( "boot" ) ;
2015
2053
create_dir_all ( & boot_dir) . context ( "Failed to create boot dir" ) ?;
2016
2054
2017
- let is_upgrade = matches ! ( setup_type, BootSetupType :: Upgrade ) ;
2055
+ let is_upgrade = matches ! ( setup_type, BootSetupType :: Upgrade ( .. ) ) ;
2018
2056
2019
2057
let efi_uuid_source = get_efi_uuid_source ( ) ;
2020
2058
@@ -2102,6 +2140,7 @@ pub(crate) async fn pull_composefs_repo(
2102
2140
ComposefsRepository < Sha256HashValue > ,
2103
2141
Vec < ComposefsBootEntry < Sha256HashValue > > ,
2104
2142
Sha256HashValue ,
2143
+ FileSystem < Sha256HashValue > ,
2105
2144
) > {
2106
2145
let rootfs_dir = cap_std:: fs:: Dir :: open_ambient_dir ( "/sysroot" , cap_std:: ambient_authority ( ) ) ?;
2107
2146
@@ -2125,7 +2164,7 @@ pub(crate) async fn pull_composefs_repo(
2125
2164
let entries = fs. transform_for_boot ( & repo) ?;
2126
2165
let id = fs. commit_image ( & repo, None ) ?;
2127
2166
2128
- Ok ( ( repo, entries, id) )
2167
+ Ok ( ( repo, entries, id, fs ) )
2129
2168
}
2130
2169
2131
2170
#[ context( "Setting up composefs boot" ) ]
@@ -2164,7 +2203,7 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
2164
2203
match boot_type {
2165
2204
BootType :: Bls => {
2166
2205
let digest = setup_composefs_bls_boot (
2167
- BootSetupType :: Setup ( ( & root_setup, & state) ) ,
2206
+ BootSetupType :: Setup ( ( & root_setup, & state, & fs ) ) ,
2168
2207
repo,
2169
2208
& id,
2170
2209
entry,
@@ -2173,7 +2212,7 @@ fn setup_composefs_boot(root_setup: &RootSetup, state: &State, image_id: &str) -
2173
2212
boot_digest = Some ( digest) ;
2174
2213
}
2175
2214
BootType :: Uki => setup_composefs_uki_boot (
2176
- BootSetupType :: Setup ( ( & root_setup, & state) ) ,
2215
+ BootSetupType :: Setup ( ( & root_setup, & state, & fs ) ) ,
2177
2216
repo,
2178
2217
& id,
2179
2218
entry,
@@ -2309,7 +2348,7 @@ async fn install_to_filesystem_impl(
2309
2348
// Load a fd for the mounted target physical root
2310
2349
let ( id, verity) = initialize_composefs_repository ( state, rootfs) . await ?;
2311
2350
2312
- tracing:: warn !(
2351
+ tracing:: info !(
2313
2352
"id = {id}, verity = {verity}" ,
2314
2353
id = hex:: encode( id) ,
2315
2354
verity = verity. to_hex( )
0 commit comments