Skip to content

Commit dab2af1

Browse files
Johan-Liebert1cgwalters
authored andcommitted
composefs: Check for meta.json
Check if the repo has meta.json file and if not apply our fix of prepending custom prefix to our bootloader entries and boot binaries Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com> Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 6ea8d5b commit dab2af1

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

crates/lib/src/bootc_composefs/backwards_compat/bcompat_boot.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ use crate::{
77
get_efi_uuid_source, get_uki_name, parse_os_release, type1_entry_conf_file_name,
88
},
99
rollback::{rename_exchange_bls_entries, rename_exchange_user_cfg},
10-
status::{get_bootloader, get_sorted_grub_uki_boot_entries, get_sorted_type1_boot_entries},
10+
status::{
11+
ComposefsCmdline, get_bootloader, get_sorted_grub_uki_boot_entries,
12+
get_sorted_type1_boot_entries,
13+
},
1114
},
1215
composefs_consts::{
1316
ORIGIN_KEY_BOOT, ORIGIN_KEY_BOOT_TYPE, STATE_DIR_RELATIVE, TYPE1_BOOT_DIR_PREFIX,
1417
TYPE1_ENT_PATH_STAGED, UKI_NAME_PREFIX, USER_CFG_STAGED,
1518
},
1619
parsers::bls_config::{BLSConfig, BLSConfigType},
1720
spec::Bootloader,
18-
store::{BootedComposefs, Storage},
21+
store::Storage,
1922
};
2023
use anyhow::{Context, Result};
2124
use camino::Utf8PathBuf;
@@ -159,7 +162,7 @@ fn stage_bls_entry_changes(
159162
storage: &Storage,
160163
boot_dir: &Dir,
161164
entries: &Vec<BLSConfig>,
162-
booted_cfs: &BootedComposefs,
165+
cfs_cmdline: &ComposefsCmdline,
163166
) -> Result<(RenameTransaction, Vec<(String, BLSConfig)>)> {
164167
let mut rename_transaction = RenameTransaction::new();
165168

@@ -186,7 +189,7 @@ fn stage_bls_entry_changes(
186189

187190
let mut new_entry = entry.clone();
188191

189-
let conf_filename = if *booted_cfs.cmdline.digest == digest {
192+
let conf_filename = if *cfs_cmdline.digest == digest {
190193
type1_entry_conf_file_name(os_id, new_entry.version(), FILENAME_PRIORITY_PRIMARY)
191194
} else {
192195
type1_entry_conf_file_name(os_id, new_entry.version(), FILENAME_PRIORITY_SECONDARY)
@@ -240,12 +243,12 @@ fn create_staged_bls_entries(boot_dir: &Dir, entries: &Vec<(String, BLSConfig)>)
240243
fsync(staged_entries.reopen_as_ownedfd()?).context("fsync")
241244
}
242245

243-
fn get_boot_type(storage: &Storage, booted_cfs: &BootedComposefs) -> Result<BootType> {
246+
fn get_boot_type(storage: &Storage, cfs_cmdline: &ComposefsCmdline) -> Result<BootType> {
244247
let mut config = String::new();
245248

246249
let origin_path = Utf8PathBuf::from(STATE_DIR_RELATIVE)
247-
.join(&*booted_cfs.cmdline.digest)
248-
.join(format!("{}.origin", booted_cfs.cmdline.digest));
250+
.join(&*cfs_cmdline.digest)
251+
.join(format!("{}.origin", cfs_cmdline.digest));
249252

250253
storage
251254
.physical_root
@@ -267,13 +270,13 @@ fn get_boot_type(storage: &Storage, booted_cfs: &BootedComposefs) -> Result<Boot
267270

268271
fn handle_bls_conf(
269272
storage: &Storage,
270-
booted_cfs: &BootedComposefs,
273+
cfs_cmdline: &ComposefsCmdline,
271274
boot_dir: &Dir,
272275
is_uki: bool,
273276
) -> Result<()> {
274277
let entries = get_sorted_type1_boot_entries(boot_dir, true)?;
275278
let (rename_transaction, new_bls_entries) =
276-
stage_bls_entry_changes(storage, boot_dir, &entries, booted_cfs)?;
279+
stage_bls_entry_changes(storage, boot_dir, &entries, cfs_cmdline)?;
277280

278281
if rename_transaction.operations.is_empty() {
279282
tracing::debug!("Nothing to do");
@@ -309,15 +312,15 @@ fn handle_bls_conf(
309312
#[context("Prepending custom prefix to EFI and BLS entries")]
310313
pub(crate) async fn prepend_custom_prefix(
311314
storage: &Storage,
312-
booted_cfs: &BootedComposefs,
315+
cfs_cmdline: &ComposefsCmdline,
313316
) -> Result<()> {
314317
let boot_dir = storage.require_boot_dir()?;
315318

316319
let bootloader = get_bootloader()?;
317320

318-
match get_boot_type(storage, booted_cfs)? {
321+
match get_boot_type(storage, cfs_cmdline)? {
319322
BootType::Bls => {
320-
handle_bls_conf(storage, booted_cfs, boot_dir, false)?;
323+
handle_bls_conf(storage, cfs_cmdline, boot_dir, false)?;
321324
}
322325

323326
BootType::Uki => match bootloader {
@@ -382,7 +385,7 @@ pub(crate) async fn prepend_custom_prefix(
382385
}
383386

384387
Bootloader::Systemd => {
385-
handle_bls_conf(storage, booted_cfs, boot_dir, true)?;
388+
handle_bls_conf(storage, cfs_cmdline, boot_dir, true)?;
386389
}
387390

388391
Bootloader::None => unreachable!("Checked at install time"),

crates/lib/src/store/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustix::fs::Mode;
4141
use cfsctl::composefs;
4242
use composefs::fsverity::Sha512HashValue;
4343

44+
use crate::bootc_composefs::backwards_compat::bcompat_boot::prepend_custom_prefix;
4445
use crate::bootc_composefs::boot::{EFI_LINUX, mount_esp};
4546
use crate::bootc_composefs::status::{ComposefsCmdline, composefs_booted, get_bootloader};
4647
use crate::lsm;
@@ -266,17 +267,27 @@ impl BootedStorage {
266267
Bootloader::None => unreachable!("Checked at install time"),
267268
};
268269

270+
let meta_json = physical_root
271+
.open_dir(COMPOSEFS)?
272+
.open_optional("meta.json")?;
273+
269274
let storage = Storage {
270275
physical_root,
271276
physical_root_path: Utf8PathBuf::from("/sysroot"),
272277
run,
273278
boot_dir: Some(boot_dir),
274279
esp: Some(esp_mount),
275280
ostree: Default::default(),
276-
composefs: OnceCell::from(composefs),
281+
composefs: OnceCell::from(composefs.clone()),
277282
imgstore: Default::default(),
278283
};
279284

285+
if meta_json.is_none() {
286+
let cmdline = composefs_booted()?
287+
.ok_or_else(|| anyhow::anyhow!("Could not get booted composefs cmdline"))?;
288+
prepend_custom_prefix(&storage, &cmdline).await?;
289+
}
290+
280291
Some(Self { storage })
281292
}
282293
Environment::OstreeBooted => {

0 commit comments

Comments
 (0)