Skip to content

Commit f12d037

Browse files
committed
wip: pass in xbootldr to grub2 postinstall
1 parent 36a9ecc commit f12d037

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

src/backend/custom.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ pub fn install_custom(
156156
let efi = (mounttags.0.iter())
157157
.find(|part| part.mountpoint == std::path::Path::new("/boot/efi"))
158158
.and_then(|part| part.partition.to_str().map(ToOwned::to_owned));
159+
let xbootldr = (mounttags.0.iter())
160+
.find(|part| part.mountpoint == std::path::Path::new("/boot"))
161+
.and_then(|part| part.partition.to_str().map(ToOwned::to_owned))
162+
.ok_or_else(|| color_eyre::eyre::eyre!("cannot find xbootldr partition"))?;
159163

160-
container.run(|| state._inner_sys_setup(fstab, efi))??;
164+
container.run(|| state._inner_sys_setup(fstab, efi, &xbootldr))??;
161165

162166
Ok(())
163167
}

src/backend/install.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use color_eyre::eyre::bail;
22
use color_eyre::eyre::eyre;
33
use color_eyre::eyre::Context;
4+
use color_eyre::eyre::ContextCompat;
45
use color_eyre::{Result, Section};
56
use ipc_channel::ipc::IpcError;
67
use ipc_channel::ipc::IpcOneShotServer;
@@ -224,20 +225,22 @@ impl InstallationState {
224225

225226
// todo: Also handle custom installs? Needs more information
226227
let esp_node = check_uefi().then(|| output.get_esp_partition()).flatten();
228+
let xbootldr_node = output.get_xbootldr_partition().context("No xbootldr partition found")?;
227229

228-
container.run(|| self._inner_sys_setup(fstab, esp_node))??;
230+
container.run(|| self._inner_sys_setup(fstab, esp_node, &xbootldr_node))??;
229231

230232
Ok(())
231233
}
232234

233235
#[allow(clippy::unwrap_in_result)]
234236
#[tracing::instrument]
235-
pub fn _inner_sys_setup(&self, fstab: String, esp_node: Option<String>) -> Result<()> {
237+
pub fn _inner_sys_setup(&self, fstab: String, esp_node: Option<String>, xbootldr_node: &str) -> Result<()> {
236238
// We will run the specified postinstall modules now
237239
let context = crate::backend::postinstall::Context {
238240
destination_disk: self.destination_disk.as_ref().unwrap().devpath.clone(),
239241
uefi: util::sys::check_uefi(),
240242
esp_partition: esp_node,
243+
xbootldr_partition: xbootldr_node.to_owned(),
241244
lang: self.langlocale.clone().unwrap_or_else(|| "C.UTF-8".into()),
242245
};
243246

src/backend/postinstall/grub2.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,19 @@ impl PostInstallModule for GRUB2 {
145145

146146
stage!("Generating stage 1 grub.cfg in ESP..." {
147147
let mut grub_cfg = std::fs::File::create("/boot/efi/EFI/fedora/grub.cfg")?;
148-
// let's search for an xbootldr label
149-
// because we never know what the device will be
150-
// see the compile time included config file
148+
let xbootldr_disk = &context.xbootldr_partition;
149+
150+
let mut template_str = include_str!("../../../templates/fedora-grub.cfg");
151+
// We used to blindly search for a partition labeled `xbootldr` here, but now that's not scalable.
152+
// now that we are starting to support custom partitioning.
153+
// So, now let's get the UUID of the xbootldr partition!
154+
155+
156+
// todo: merge https://github.com/FyraLabs/lsblk-rs/pull/16
157+
let xbootldr_uuid: &str = todo!();
158+
159+
template_str.replace("$UUID$", xbootldr_uuid);
160+
151161
grub_cfg.write_all(include_bytes!("../../../templates/fedora-grub.cfg"))?;
152162
});
153163

src/backend/postinstall/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct Context {
2626
pub destination_disk: PathBuf,
2727
pub uefi: bool,
2828
pub esp_partition: Option<String>,
29+
// Installs should always have an xbootldr partition
30+
pub xbootldr_partition: String,
2931
pub lang: String,
3032
}
3133

src/backend/repart_output.rs

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ impl RepartOutput {
8181
.find(|part| part.part_type == "esp")
8282
.map(|part| part.node.clone())
8383
}
84+
85+
pub fn get_xbootldr_partition(&self) -> std::option::Option<String> {
86+
self.partitions
87+
.iter()
88+
.find(|part| part.part_type == "xbootldr")
89+
.map(|part| part.node.clone())
90+
}
8491

8592
/// Create `tiffin::Container` from the repartitioning output with the mountpoints
8693
/// from the DDI partition types

templates/fedora-grub.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
search --no-floppy --label --set=dev xbootldr
1+
search --no-floppy --fs-uuid --set=dev $UUID$
22
set prefix=($dev)/grub2
33

44
export $prefix
5-
configfile $prefix/grub.cfg
5+
configfile $prefix/grub.cfg

0 commit comments

Comments
 (0)