Update installer patch for GRUB bootloader and ext4 filesystem support
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -163,9 +163,18 @@ index 2739983..0d2d6f3 100644
|
|||||||
let res = with_whole_disk(&disk_path, &disk_option, |mut fs| {
|
let res = with_whole_disk(&disk_path, &disk_option, |mut fs| {
|
||||||
// Fast install method via filesystem clone
|
// Fast install method via filesystem clone
|
||||||
diff --git a/src/config/general.rs b/src/config/general.rs
|
diff --git a/src/config/general.rs b/src/config/general.rs
|
||||||
index 417ff2d..4ad2202 100644
|
index 417ff2d..fab677c 100644
|
||||||
--- a/src/config/general.rs
|
--- a/src/config/general.rs
|
||||||
+++ b/src/config/general.rs
|
+++ b/src/config/general.rs
|
||||||
|
@@ -6,7 +6,7 @@ pub struct GeneralConfig {
|
||||||
|
pub prompt: Option<bool>,
|
||||||
|
/// Total filesystem size in MB
|
||||||
|
pub filesystem_size: Option<u32>,
|
||||||
|
- /// EFI partition size in MB, default to 2MB
|
||||||
|
+ /// EFI partition size in MiB, defaults to 1 MiB when not set
|
||||||
|
pub efi_partition_size: Option<u32>,
|
||||||
|
/// Skip disk partitioning, assume whole disk is a partition
|
||||||
|
pub skip_partitions: Option<bool>,
|
||||||
@@ -19,6 +19,11 @@ pub struct GeneralConfig {
|
@@ -19,6 +19,11 @@ pub struct GeneralConfig {
|
||||||
/// Use AR to write files instead of FUSE-based mount
|
/// Use AR to write files instead of FUSE-based mount
|
||||||
/// (bypasses FUSE, but slower and requires namespaced context such as "podman unshare")
|
/// (bypasses FUSE, but slower and requires namespaced context such as "podman unshare")
|
||||||
@@ -191,7 +200,7 @@ index 417ff2d..4ad2202 100644
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
diff --git a/src/installer.rs b/src/installer.rs
|
diff --git a/src/installer.rs b/src/installer.rs
|
||||||
index 4e077a9..654f6fb 100644
|
index 4e077a9..ba3f9dd 100644
|
||||||
--- a/src/installer.rs
|
--- a/src/installer.rs
|
||||||
+++ b/src/installer.rs
|
+++ b/src/installer.rs
|
||||||
@@ -3,6 +3,13 @@ use anyhow::{bail, Result};
|
@@ -3,6 +3,13 @@ use anyhow::{bail, Result};
|
||||||
@@ -478,7 +487,7 @@ index 4e077a9..654f6fb 100644
|
|||||||
let bootloader_dir =
|
let bootloader_dir =
|
||||||
PathBuf::from(format!("/tmp/redox_installer_bootloader_{}", process::id()));
|
PathBuf::from(format!("/tmp/redox_installer_bootloader_{}", process::id()));
|
||||||
|
|
||||||
@@ -491,36 +739,75 @@ pub fn fetch_bootloaders(
|
@@ -491,39 +739,78 @@ pub fn fetch_bootloaders(
|
||||||
|
|
||||||
fs::create_dir(&bootloader_dir)?;
|
fs::create_dir(&bootloader_dir)?;
|
||||||
|
|
||||||
@@ -579,7 +588,20 @@ index 4e077a9..654f6fb 100644
|
|||||||
+ result
|
+ result
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: make bootloaders use Option, dynamically create BIOS and EFI partitions
|
-//TODO: make bootloaders use Option, dynamically create BIOS and EFI partitions
|
||||||
|
+//TODO: dynamically create BIOS and EFI partitions instead of always creating both
|
||||||
|
pub fn with_whole_disk<P, F, T>(disk_path: P, disk_option: &DiskOption, callback: F) -> Result<T>
|
||||||
|
where
|
||||||
|
P: AsRef<Path>,
|
||||||
|
@@ -570,7 +857,7 @@ where
|
||||||
|
let gpt_reserved = 34 * 512; // GPT always reserves 34 512-byte sectors
|
||||||
|
let mibi = 1024 * 1024;
|
||||||
|
|
||||||
|
- // First megabyte of the disk is reserved for BIOS partition, wich includes GPT tables
|
||||||
|
+ // First megabyte of the disk is reserved for BIOS partition, which includes GPT tables
|
||||||
|
let bios_start = gpt_reserved / block_size;
|
||||||
|
let bios_end = (mibi / block_size) - 1;
|
||||||
|
|
||||||
@@ -672,10 +959,13 @@ where
|
@@ -672,10 +959,13 @@ where
|
||||||
fscommon::StreamSlice::new(&mut disk_file, disk_efi_start, disk_efi_end)?;
|
fscommon::StreamSlice::new(&mut disk_file, disk_efi_start, disk_efi_end)?;
|
||||||
|
|
||||||
@@ -893,7 +915,7 @@ index 4e077a9..654f6fb 100644
|
|||||||
#[cfg(not(target_os = "redox"))]
|
#[cfg(not(target_os = "redox"))]
|
||||||
pub fn try_fast_install<D: redoxfs::Disk, F: FnMut(u64, u64)>(
|
pub fn try_fast_install<D: redoxfs::Disk, F: FnMut(u64, u64)>(
|
||||||
_fs: &mut redoxfs::FileSystem<D>,
|
_fs: &mut redoxfs::FileSystem<D>,
|
||||||
@@ -801,6 +1348,24 @@ pub fn try_fast_install<D: redoxfs::Disk, F: FnMut(u64, u64)>(
|
@@ -801,6 +1348,27 @@ pub fn try_fast_install<D: redoxfs::Disk, F: FnMut(u64, u64)>(
|
||||||
|
|
||||||
fn install_inner(config: Config, output: &Path) -> Result<()> {
|
fn install_inner(config: Config, output: &Path) -> Result<()> {
|
||||||
println!("Installing to {}:\n{}", output.display(), config);
|
println!("Installing to {}:\n{}", output.display(), config);
|
||||||
@@ -912,13 +934,16 @@ index 4e077a9..654f6fb 100644
|
|||||||
+ if efi_size < 8 {
|
+ if efi_size < 8 {
|
||||||
+ bail!("GRUB bootloader requires efi_partition_size >= 8 MiB (got {} MiB). Add efi_partition_size = 16 to your config.", efi_size);
|
+ bail!("GRUB bootloader requires efi_partition_size >= 8 MiB (got {} MiB). Add efi_partition_size = 16 to your config.", efi_size);
|
||||||
+ }
|
+ }
|
||||||
|
+ if config.general.skip_partitions.unwrap_or(false) {
|
||||||
|
+ bail!("GRUB bootloader is incompatible with skip_partitions = true. GRUB requires GPT partition layout with ESP for chainloading.");
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
let cookbook = config.general.cookbook.clone();
|
let cookbook = config.general.cookbook.clone();
|
||||||
let cookbook = cookbook.as_ref().map(|p| p.as_str());
|
let cookbook = cookbook.as_ref().map(|p| p.as_str());
|
||||||
if output.is_dir() {
|
if output.is_dir() {
|
||||||
@@ -823,28 +1388,42 @@ fn install_inner(config: Config, output: &Path) -> Result<()> {
|
@@ -823,28 +1391,45 @@ fn install_inner(config: Config, output: &Path) -> Result<()> {
|
||||||
let live = config.general.live_disk.unwrap_or(false);
|
let live = config.general.live_disk.unwrap_or(false);
|
||||||
let password_opt = config.general.encrypt_disk.clone();
|
let password_opt = config.general.encrypt_disk.clone();
|
||||||
let password_opt = password_opt.as_ref().map(|p| p.as_bytes());
|
let password_opt = password_opt.as_ref().map(|p| p.as_bytes());
|
||||||
@@ -928,6 +953,9 @@ index 4e077a9..654f6fb 100644
|
|||||||
if let Some(write_bootloader) = &config.general.write_bootloader {
|
if let Some(write_bootloader) = &config.general.write_bootloader {
|
||||||
- std::fs::write(write_bootloader, &bootloader_efi)?;
|
- std::fs::write(write_bootloader, &bootloader_efi)?;
|
||||||
+ let primary_efi = grub_efi.as_deref().unwrap_or(&bootloader_efi);
|
+ let primary_efi = grub_efi.as_deref().unwrap_or(&bootloader_efi);
|
||||||
|
+ if primary_efi.is_empty() {
|
||||||
|
+ bail!("Cannot write bootloader to {:?}: EFI binary is empty (0 bytes). The recipe may have failed to produce a valid image.", write_bootloader);
|
||||||
|
+ }
|
||||||
+ std::fs::write(write_bootloader, primary_efi)?;
|
+ std::fs::write(write_bootloader, primary_efi)?;
|
||||||
}
|
}
|
||||||
+ let filesystem_type = match config.general.filesystem.as_deref() {
|
+ let filesystem_type = match config.general.filesystem.as_deref() {
|
||||||
|
|||||||
Reference in New Issue
Block a user