Skip to content

Commit

Permalink
Merge branch 'main' of github.com:FyraLabs/readymade
Browse files Browse the repository at this point in the history
  • Loading branch information
madonuko committed Dec 31, 2024
2 parents 4b4b868 + 8bb1c5c commit e0afa8e
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/backend/postinstall/grub2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use std::io::Write;
use std::path::Path;
use std::process::Command;
use tracing::{info, warn};
use tracing::{debug, info, warn};

use crate::stage;

Expand Down Expand Up @@ -82,8 +82,10 @@ GRUB_ENABLE_BLSCFG={enable_blsconfig}
/// # Arguments
///
/// * `disk` - The path to the disk to install GRUB2 on.
fn grub2_install_bios<P: AsRef<Path>>(disk: P) -> std::io::Result<()> {
fn grub2_install_bios<P: AsRef<Path>>(disk: P) -> Result<()> {
info!("Generating GRUB2 configuration...");
let _disk = disk.as_ref().to_str();
debug!(?_disk);
// this should probably be run inside a chroot... but we'll see
if let Err(e) = Command::new("grub2-mkconfig")
.arg("-o")
Expand All @@ -94,16 +96,26 @@ fn grub2_install_bios<P: AsRef<Path>>(disk: P) -> std::io::Result<()> {

// Check if the file still exists
if !Path::new("/boot/grub/grub.cfg").exists() {
return Err(e);
return Err(e).map_err(Into::into);
}
}
info!("Blessing the disk with GRUB2...");
Command::new("grub2-install")
let status = Command::new("grub2-install")
.arg("--target=i386-pc")
.arg("--recheck")
.arg("--boot-directory=/boot")
// We are going to force the installation, because for some reason
// grub-install just couldn't find our xbootldr partition
// even though it exists.
//
// --force is a last resort, but in our layout it's kind of necessary :P
.arg("--force")
.arg(disk.as_ref())
.status()?;

if !status.success() {
bail!("Failed to install GRUB2 on disk {_disk:?}")
}

Ok(())
}
Expand Down

0 comments on commit e0afa8e

Please sign in to comment.