From 4766458bcaca12252fd58271b2cfd438b200a67a Mon Sep 17 00:00:00 2001 From: axtlos Date: Wed, 27 Apr 2022 18:58:02 +0200 Subject: [PATCH] fix grub efi boot path issue --- src/functions/base.rs | 9 +++++---- src/functions/partition.rs | 3 ++- src/internal/config.rs | 2 +- src/main.rs | 3 ++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/functions/base.rs b/src/functions/base.rs index 3b69317..689213b 100755 --- a/src/functions/base.rs +++ b/src/functions/base.rs @@ -39,16 +39,17 @@ pub fn genfstab() { pub fn install_bootloader_efi(efidir: PathBuf) { install::install(vec!["grub", "efibootmgr", "grub-btrfs"]); - if !efidir.exists() { + let efidir = std::path::Path::new("/mnt").join(efidir); + let efi_str = efidir.to_str().unwrap(); + if !std::path::Path::new(&format!("/mnt{efi_str}")).exists() { crash(format!("The efidir {efidir:?} doesn't exist"), 1); } - let efidir = efidir.to_string_lossy().to_string(); exec_eval( exec_chroot( "grub-install", vec![ String::from("--target=x86_64-efi"), - format!("--efi-directory={}", efidir), + format!("--efi-directory={}" , efi_str), String::from("--bootloader-id=crystal"), String::from("--removable"), ], @@ -60,7 +61,7 @@ pub fn install_bootloader_efi(efidir: PathBuf) { "grub-install", vec![ String::from("--target=x86_64-efi"), - format!("--efi-directory={}", efidir), + format!("--efi-directory={}", efi_str), String::from("--bootloader-id=crystal"), ], ), diff --git a/src/functions/partition.rs b/src/functions/partition.rs index a708863..f657aa4 100755 --- a/src/functions/partition.rs +++ b/src/functions/partition.rs @@ -158,7 +158,7 @@ pub fn fmt_mount(mountpoint: &String, filesystem: &String, blockdevice: &String) mount(&blockdevice, &mountpoint, ""); } -pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: Vec) { +pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: &mut Vec) { println!("{:?}", mode); match mode { @@ -180,6 +180,7 @@ pub fn partition(device: PathBuf, mode: PartitionMode, efi: bool, partitions: Ve } PartitionMode::Manual => { log::debug!("Manual partitioning"); + partitions.sort_by(|a, b| a.mountpoint.len().cmp(&b.mountpoint.len())); for i in 0..partitions.len() { println!("{:?}", partitions); println!("{}", partitions.len()); diff --git a/src/internal/config.rs b/src/internal/config.rs index eb5a207..137e101 100755 --- a/src/internal/config.rs +++ b/src/internal/config.rs @@ -91,7 +91,7 @@ pub fn read_config(configpath: PathBuf) { PathBuf::from("/dev/").join(config.partition.device), config.partition.mode, config.partition.efi, - partitions, + &mut partitions, ); base::install_base_packages(); base::genfstab(); diff --git a/src/main.rs b/src/main.rs index 997c2dc..5fbd4c4 100755 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,8 @@ fn main() { logging::init(opt.verbose); match opt.command { Command::Partition(args) => { - partition::partition(args.device, args.mode, args.efi, args.partitions); + let mut partitions = args.partitions; + partition::partition(args.device, args.mode, args.efi, &mut partitions); } Command::InstallBase => { base::install_base_packages();