Merge branch 'ivan/efi_size' into 'master'

add option for variable size of EFI system partition

See merge request redox-os/installer!26
This commit is contained in:
Jeremy Soller
2023-12-07 15:34:54 +00:00
3 changed files with 31 additions and 10 deletions
+8 -2
View File
@@ -11,7 +11,7 @@ extern crate toml;
use pkgar::{PackageHead, ext::EntryExt};
use pkgar_core::PackageSrc;
use pkgar_keys::PublicKeyFile;
use redox_installer::{Config, with_whole_disk};
use redox_installer::{Config, with_whole_disk, DiskOption};
use std::{
ffi::OsStr,
fs,
@@ -302,7 +302,13 @@ fn main() {
}
};
let res = with_whole_disk(&disk_path, &bootloader_bios, &bootloader_efi, password_opt.as_ref().map(|x| x.as_bytes()), |mount_path| -> Result<(), failure::Error> {
let disk_option = DiskOption {
bootloader_bios: &bootloader_bios,
bootloader_efi: &bootloader_efi,
password_opt: password_opt.as_ref().map(|x| x.as_bytes()),
efi_partition_size: None,
};
let res = with_whole_disk(&disk_path, &disk_option, |mount_path| -> Result<(), failure::Error> {
let mut config: Config = {
let path = root_path.join("filesystem.toml");
match fs::read_to_string(&path) {
+1
View File
@@ -3,4 +3,5 @@ pub struct GeneralConfig {
pub prompt: bool,
// Allow config to specify cookbook recipe or binary package as default
pub repo_binary: Option<bool>,
pub efi_partition_size: Option<u32>, //MiB
}
+22 -8
View File
@@ -38,6 +38,13 @@ use std::{
pub(crate) type Result<T> = std::result::Result<T, Error>;
pub struct DiskOption<'a> {
pub bootloader_bios: &'a [u8],
pub bootloader_efi: &'a [u8],
pub password_opt: Option<&'a [u8]>,
pub efi_partition_size: Option<u32>, //MiB
}
const REMOTE: &'static str = "https://static.redox-os.org/pkg";
fn get_target() -> String {
@@ -353,7 +360,7 @@ pub fn fetch_bootloaders<S: AsRef<str>>(config: &Config, cookbook: Option<S>, li
}
//TODO: make bootloaders use Option, dynamically create BIOS and EFI partitions
pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader_efi: &[u8], password_opt: Option<&[u8]>, callback: F)
pub fn with_whole_disk<P, F, T>(disk_path: P, disk_option: &DiskOption, callback: F)
-> Result<T> where
P: AsRef<Path>,
F: FnOnce(&Path) -> Result<T>
@@ -393,7 +400,8 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
// Second megabyte of the disk is reserved for EFI partition
let efi_start = bios_end + 1;
let efi_end = efi_start + (mibi / block_size) - 1;
let efi_size = if let Some(size) = disk_option.efi_partition_size { size as u64 } else { 1 };
let efi_end = efi_start + (efi_size * mibi / block_size) - 1;
// The rest of the disk is RedoxFS, reserving the GPT table mirror at the end of disk
let redoxfs_start = efi_end + 1;
@@ -402,9 +410,9 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
// Format and install BIOS partition
{
// Write BIOS bootloader to disk
eprintln!("Write bootloader with size {:#x}", bootloader_bios.len());
eprintln!("Write bootloader with size {:#x}", disk_option.bootloader_bios.len());
disk_file.seek(SeekFrom::Start(0))?;
disk_file.write_all(&bootloader_bios)?;
disk_file.write_all(&disk_option.bootloader_bios)?;
// Replace MBR tables with protective MBR
let mbr_blocks = ((disk_size + block_size - 1) / block_size) - 1;
@@ -487,11 +495,11 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
let efi_dir = root_dir.open_dir("EFI")?;
efi_dir.create_dir("BOOT")?;
eprintln!("Writing EFI/BOOT/{} file with size {:#x}", bootloader_efi_name, bootloader_efi.len());
eprintln!("Writing EFI/BOOT/{} file with size {:#x}", bootloader_efi_name, disk_option.bootloader_efi.len());
let boot_dir = efi_dir.open_dir("BOOT")?;
let mut file = boot_dir.create_file(bootloader_efi_name)?;
file.truncate()?;
file.write_all(&bootloader_efi)?;
file.write_all(&disk_option.bootloader_efi)?;
}
// Format and install RedoxFS partition
@@ -503,7 +511,7 @@ pub fn with_whole_disk<P, F, T>(disk_path: P, bootloader_bios: &[u8], bootloader
)?);
with_redoxfs(
disk_redoxfs,
password_opt,
disk_option.password_opt,
callback
)
}
@@ -519,7 +527,13 @@ pub fn install<P, S>(config: Config, output: P, cookbook: Option<S>, live: bool)
install_dir(config, output, cookbook)
} else {
let (bootloader_bios, bootloader_efi) = fetch_bootloaders(&config, cookbook.as_ref(), live)?;
with_whole_disk(output, &bootloader_bios, &bootloader_efi, None,
let disk_option = DiskOption {
bootloader_bios: &bootloader_bios,
bootloader_efi: &bootloader_efi,
password_opt: None,
efi_partition_size: config.general.efi_partition_size,
};
with_whole_disk(output, &disk_option,
move |mount_path| {
install_dir(config, mount_path, cookbook)
}