Skip to content

Commit 55f54c8

Browse files
bootloader: Add GrubCC bootloader
Add GrubCC (Grub ConfidentialClusters) as a new bootloader option. This is a minimal version of grub that's supposed to work exactly like systemd-boot Fixes: #2212 Signed-off-by: Johan-Liebert1 <pragyanpoudyal41999@gmail.com>
1 parent 14b8d6a commit 55f54c8

13 files changed

Lines changed: 84 additions & 17 deletions

File tree

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ COPY --from=target-base /target-rootfs/ /
5959
ARG SKIP_CONFIGS
6060
ARG boot_type
6161
ARG seal_state
62+
ARG bootloader
6263
# All network-fetching operations: package installs from distro repos, Copr, Koji.
6364
# Separated so `just build-fetch --target=fetch` can be retried independently on
6465
# transient network failures without re-running the configuration phase.
@@ -89,6 +90,20 @@ RUN --mount=type=tmpfs,target=/run --mount=type=tmpfs,target=/tmp \
8990
if [[ ${#pkgs_to_install[@]} -gt 0 ]]; then
9091
dnf install -y "${pkgs_to_install[@]}"
9192
fi
93+
94+
if [[ "$bootloader" == "grub-cc" ]]; then
95+
# We have this until we get grub-cc support in bootupd
96+
arch=$(uname -m)
97+
curl -L -o /var/grub-cc.rpm "https://kojipkgs.fedoraproject.org/packages/grub2/2.12/59.eln156/x86_64/grub2-efi-x64-cc-2.12-59.eln156.${arch}.rpm"
98+
mkdir /var/grub-cc
99+
rpm2archive /var/grub-cc.rpm | tar -xvz -C /var/grub-cc
100+
file=$(find /var/grub-cc -name '*.efi')
101+
mkdir /usr/lib/grub-cc
102+
cp $file /usr/lib/grub-cc
103+
rm -rvf /var/grub-cc
104+
rm -rvf /var/grub-cc.rpm
105+
fi
106+
92107
EOF
93108

94109
# Note we don't do any customization here yet

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub(crate) async fn prepend_custom_prefix(
384384
rename_exchange_user_cfg(&grub_dir)?;
385385
}
386386

387-
Bootloader::Systemd => {
387+
Bootloader::Systemd | Bootloader::GrubCC => {
388388
handle_bls_conf(storage, cfs_cmdline, boot_dir, true)?;
389389
}
390390

crates/lib/src/bootc_composefs/boot.rs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ pub(crate) fn setup_composefs_bls_boot(
607607
)
608608
}
609609

610-
Bootloader::Systemd => {
610+
Bootloader::Systemd | Bootloader::GrubCC => {
611611
let efi_mount = mount_esp(&esp_device).context("Mounting ESP")?;
612612

613613
let mounted_efi = Utf8PathBuf::from(efi_mount.dir.path().as_str()?);
@@ -1169,7 +1169,9 @@ pub(crate) fn setup_composefs_uki_boot(
11691169
write_grub_uki_menuentry(root_path, &setup_type, uki_info.boot_label, id, &esp_device)?
11701170
}
11711171

1172-
Bootloader::Systemd => write_systemd_uki_config(&esp_mount.fd, &setup_type, uki_info, id)?,
1172+
Bootloader::Systemd | Bootloader::GrubCC => {
1173+
write_systemd_uki_config(&esp_mount.fd, &setup_type, uki_info, id)?
1174+
}
11731175

11741176
Bootloader::None => unreachable!("Checked at install time"),
11751177
};
@@ -1369,13 +1371,48 @@ pub(crate) async fn setup_composefs_boot(
13691371
&root_setup.device_info.require_single_root()?,
13701372
boot_uuid,
13711373
)?;
1372-
} else if postfetch.detected_bootloader == Bootloader::Grub {
1374+
} else if matches!(
1375+
postfetch.detected_bootloader,
1376+
Bootloader::Grub | Bootloader::GrubCC
1377+
) {
13731378
crate::bootloader::install_via_bootupd(
13741379
&root_setup.device_info,
13751380
&root_setup.physical_root_path,
13761381
&state.config_opts,
13771382
None,
13781383
)?;
1384+
1385+
// FIXME: Remove this hack once we have support in bootupd
1386+
if matches!(postfetch.detected_bootloader, Bootloader::GrubCC) {
1387+
root_setup
1388+
.physical_root
1389+
.remove_dir_all("boot/grub2")
1390+
.context("removing grub2")?;
1391+
1392+
let (os_id, ..) = parse_os_release(mounted_root.dir())?
1393+
.ok_or_else(|| anyhow::anyhow!("Failed to parse os-release"))?;
1394+
1395+
let dir = format!("EFI/{os_id}");
1396+
1397+
// Files are in EFI/<os-name>/
1398+
let efis_dir = mounted_root
1399+
.open_esp_dir()
1400+
.context("opening esp")?
1401+
.open_dir(&dir)
1402+
.with_context(|| format!("Opening {dir}"))?;
1403+
1404+
efis_dir
1405+
.remove_file_optional("bootuuid.cfg")
1406+
.context("Removing bootuuid.cfg")?;
1407+
efis_dir
1408+
.remove_file_optional("grub.cfg")
1409+
.context("Removing grub.cfg")?;
1410+
1411+
mounted_root
1412+
.dir()
1413+
.copy("usr/lib/grub-cc/grubx64-cc.efi", &efis_dir, "grubx64.efi")
1414+
.context("Copying grub-cc binary")?;
1415+
}
13791416
} else {
13801417
crate::bootloader::install_systemd_boot(
13811418
&mounted_root,

crates/lib/src/bootc_composefs/delete.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn delete_depl_boot_entries(
153153
}
154154
},
155155

156-
Bootloader::Systemd => {
156+
Bootloader::Systemd | Bootloader::GrubCC => {
157157
// For Systemd UKI as well, we use .conf files
158158
delete_type1_conf_file(deployment, boot_dir, deleting_staged)
159159
}

crates/lib/src/bootc_composefs/finalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub(crate) async fn composefs_backend_finalize(
140140
BootType::Uki => finalize_staged_grub_uki(boot_dir)?,
141141
},
142142

143-
Bootloader::Systemd => {
143+
Bootloader::Systemd | Bootloader::GrubCC => {
144144
let entries_dir = boot_dir.open_dir("loader")?;
145145
rename_exchange_bls_entries(&entries_dir)?;
146146
}

crates/lib/src/bootc_composefs/rollback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub(crate) async fn composefs_rollback(
234234
}
235235
},
236236

237-
Bootloader::Systemd => {
237+
Bootloader::Systemd | Bootloader::GrubCC => {
238238
// We use BLS entries for systemd UKI as well
239239
rollback_composefs_entries(boot_dir, rollback_entry.bootloader.clone())?;
240240
}

crates/lib/src/bootc_composefs/status.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub(crate) fn list_bootloader_entries(storage: &Storage) -> Result<Vec<Bootloade
368368
}
369369
}
370370

371-
Bootloader::Systemd => list_type1_entries(boot_dir)?,
371+
Bootloader::Systemd | Bootloader::GrubCC => list_type1_entries(boot_dir)?,
372372

373373
Bootloader::None => unreachable!("Checked at install time"),
374374
};
@@ -414,10 +414,14 @@ pub(crate) fn get_bootloader() -> Result<Bootloader> {
414414
let bootloader = match read_uefi_var(EFI_LOADER_INFO) {
415415
Ok(loader) => {
416416
if loader.to_lowercase().contains("systemd-boot") {
417-
Bootloader::Systemd
418-
} else {
419-
Bootloader::Grub
417+
return Ok(Bootloader::Systemd);
418+
}
419+
420+
if loader.to_lowercase().contains("grub cc") {
421+
return Ok(Bootloader::GrubCC);
420422
}
423+
424+
return Ok(Bootloader::Grub);
421425
}
422426

423427
Err(efi_error) => match efi_error {
@@ -911,7 +915,7 @@ async fn composefs_deployment_status_from(
911915
},
912916

913917
// We will have BLS stuff and the UKI stuff in the same DIR
914-
Bootloader::Systemd => {
918+
Bootloader::Systemd | Bootloader::GrubCC => {
915919
let bls_configs = get_sorted_type1_boot_entries(boot_dir, true)?;
916920
let bls_config = bls_configs
917921
.first()

crates/lib/src/bootc_composefs/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub(crate) fn validate_update(
184184
}
185185
},
186186

187-
Bootloader::Systemd => rm_staged_type1_ent(boot_dir)?,
187+
Bootloader::Systemd | Bootloader::GrubCC => rm_staged_type1_ent(boot_dir)?,
188188

189189
Bootloader::None => unreachable!("Checked at install time"),
190190
}

crates/lib/src/install.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ pub(crate) fn exec_in_host_mountns(args: &[std::ffi::OsString]) -> Result<()> {
12911291
Err(Command::new(cmd).args(args).arg0(bootc_utils::NAME).exec()).context("exec")?
12921292
}
12931293

1294+
#[derive(Debug)]
12941295
pub(crate) struct RootSetup {
12951296
#[cfg(feature = "install-to-disk")]
12961297
luks_device: Option<String>,
@@ -1874,7 +1875,7 @@ async fn install_with_sysroot(
18741875
Some(&deployment_path.as_str()),
18751876
)?;
18761877
}
1877-
Bootloader::Systemd => {
1878+
Bootloader::Systemd | Bootloader::GrubCC => {
18781879
anyhow::bail!("bootupd is required for ostree-based installs");
18791880
}
18801881
Bootloader::None => {

crates/lib/src/install/baseline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn use_discoverable_partitions(state: &State) -> bool {
5555
// systemd-boot always supports BLI
5656
matches!(
5757
state.config_opts.bootloader,
58-
Some(crate::spec::Bootloader::Systemd)
58+
Some(crate::spec::Bootloader::Systemd) | Some(crate::spec::Bootloader::GrubCC)
5959
)
6060
}
6161

0 commit comments

Comments
 (0)