Skip to content

Commit ca6ebb6

Browse files
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>
1 parent 35b8326 commit ca6ebb6

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)
@@ -236,12 +239,12 @@ fn create_staged_bls_entries(boot_dir: &Dir, entries: &Vec<(String, BLSConfig)>)
236239
fsync(staged_entries.reopen_as_ownedfd()?).context("fsync")
237240
}
238241

239-
fn get_boot_type(storage: &Storage, booted_cfs: &BootedComposefs) -> Result<BootType> {
242+
fn get_boot_type(storage: &Storage, cfs_cmdline: &ComposefsCmdline) -> Result<BootType> {
240243
let mut config = String::new();
241244

242245
let origin_path = Utf8PathBuf::from(STATE_DIR_RELATIVE)
243-
.join(&*booted_cfs.cmdline.digest)
244-
.join(format!("{}.origin", booted_cfs.cmdline.digest));
246+
.join(&*cfs_cmdline.digest)
247+
.join(format!("{}.origin", cfs_cmdline.digest));
245248

246249
storage
247250
.physical_root
@@ -263,13 +266,13 @@ fn get_boot_type(storage: &Storage, booted_cfs: &BootedComposefs) -> Result<Boot
263266

264267
fn handle_bls_conf(
265268
storage: &Storage,
266-
booted_cfs: &BootedComposefs,
269+
cfs_cmdline: &ComposefsCmdline,
267270
boot_dir: &Dir,
268271
is_uki: bool,
269272
) -> Result<()> {
270273
let entries = get_sorted_type1_boot_entries(boot_dir, true)?;
271274
let (rename_transaction, new_bls_entries) =
272-
stage_bls_entry_changes(storage, boot_dir, &entries, booted_cfs)?;
275+
stage_bls_entry_changes(storage, boot_dir, &entries, cfs_cmdline)?;
273276

274277
if rename_transaction.operations.is_empty() {
275278
tracing::debug!("Nothing to do");
@@ -305,15 +308,15 @@ fn handle_bls_conf(
305308
#[context("Prepending custom prefix to EFI and BLS entries")]
306309
pub(crate) async fn prepend_custom_prefix(
307310
storage: &Storage,
308-
booted_cfs: &BootedComposefs,
311+
cfs_cmdline: &ComposefsCmdline,
309312
) -> Result<()> {
310313
let boot_dir = storage.require_boot_dir()?;
311314

312315
let bootloader = get_bootloader()?;
313316

314-
match get_boot_type(storage, booted_cfs)? {
317+
match get_boot_type(storage, cfs_cmdline)? {
315318
BootType::Bls => {
316-
handle_bls_conf(storage, booted_cfs, boot_dir, false)?;
319+
handle_bls_conf(storage, cfs_cmdline, boot_dir, false)?;
317320
}
318321

319322
BootType::Uki => match bootloader {
@@ -378,7 +381,7 @@ pub(crate) async fn prepend_custom_prefix(
378381
}
379382

380383
Bootloader::Systemd => {
381-
handle_bls_conf(storage, booted_cfs, boot_dir, true)?;
384+
handle_bls_conf(storage, cfs_cmdline, boot_dir, true)?;
382385
}
383386

384387
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
@@ -39,6 +39,7 @@ use rustix::fs::Mode;
3939
use cfsctl::composefs;
4040
use composefs::fsverity::Sha512HashValue;
4141

42+
use crate::bootc_composefs::backwards_compat::bcompat_boot::prepend_custom_prefix;
4243
use crate::bootc_composefs::boot::{EFI_LINUX, mount_esp};
4344
use crate::bootc_composefs::status::{ComposefsCmdline, composefs_booted, get_bootloader};
4445
use crate::lsm;
@@ -210,17 +211,27 @@ impl BootedStorage {
210211
Bootloader::None => unreachable!("Checked at install time"),
211212
};
212213

214+
let meta_json = physical_root
215+
.open_dir(COMPOSEFS)?
216+
.open_optional("meta.json")?;
217+
213218
let storage = Storage {
214219
physical_root,
215220
physical_root_path: Utf8PathBuf::from("/sysroot"),
216221
run,
217222
boot_dir: Some(boot_dir),
218223
esp: Some(esp_mount),
219224
ostree: Default::default(),
220-
composefs: OnceCell::from(composefs),
225+
composefs: OnceCell::from(composefs.clone()),
221226
imgstore: Default::default(),
222227
};
223228

229+
if meta_json.is_none() {
230+
let cmdline = composefs_booted()?
231+
.ok_or_else(|| anyhow::anyhow!("Could not get booted composefs cmdline"))?;
232+
prepend_custom_prefix(&storage, &cmdline).await?;
233+
}
234+
224235
Some(Self { storage })
225236
}
226237
Environment::OstreeBooted => {

0 commit comments

Comments
 (0)