Skip to content

Commit

Permalink
fix:[close #27] Use correct disk for updating EFI
Browse files Browse the repository at this point in the history
  • Loading branch information
matbme committed Oct 15, 2023
1 parent 87b1f63 commit 5168f71
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions RECIPE.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Install GRUB to the specified partition.
- *BootDirectory* (`string`): The path for the boot dir (usually `/boot`).
- *InstallDevice* (`string`): The disk where the boot partition is located.
- *Target* (`string`): The target firmware. Either `bios` for legacy systems or `efi` for UEFI systems.
- *EFIDevice* (optional `string`): Only required for EFI installations. The partition where the EFI is located.

### grub-default-config

Expand Down
24 changes: 15 additions & 9 deletions core/grub.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package albius

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -95,7 +96,7 @@ func RemoveGrubScript(targetRoot, scriptName string) error {
return nil
}

func RunGrubInstall(targetRoot, bootDirectory, diskPath string, target FirmwareType) error {
func RunGrubInstall(targetRoot, bootDirectory, diskPath string, target FirmwareType, efiDevice ...string) error {
// Mount necessary targets for chroot
if targetRoot != "" {
requiredBinds := []string{"/dev", "/dev/pts", "/proc", "/sys", "/run"}
Expand Down Expand Up @@ -126,14 +127,19 @@ func RunGrubInstall(targetRoot, bootDirectory, diskPath string, target FirmwareT

// FIXME: This is needed on Vanilla due to some recent GRUB change. If you're using Debian sid as
// base, consider keeping it.
efibootmgrCmd := "efibootmgr --create --disk=%s --part=%s --label=vanilla --loader=\"\\EFI\\debian\\shimx64.efi\""
diskExpr := regexp.MustCompile("^/dev/[a-zA-Z]+([0-9]+[a-z][0-9]+)?")
partExpr := regexp.MustCompile("[0-9]+$")
diskName := diskExpr.FindString(diskPath)
part := partExpr.FindString(diskPath)
err = RunCommand(fmt.Sprintf(efibootmgrCmd, diskName, part))
if err != nil {
return fmt.Errorf("Failed to run grub-install: %s", err)
if target == EFI {
efibootmgrCmd := "efibootmgr --create --disk=%s --part=%s --label=vanilla --loader=\"\\EFI\\debian\\shimx64.efi\""
diskExpr := regexp.MustCompile("^/dev/[a-zA-Z]+([0-9]+[a-z][0-9]+)?")
partExpr := regexp.MustCompile("[0-9]+$")
if len(efiDevice) == 0 || efiDevice[0] == "" {
return errors.New("EFI device was not specified")
}
diskName := diskExpr.FindString(efiDevice[0])
part := partExpr.FindString(efiDevice[0])
err = RunCommand(fmt.Sprintf(efibootmgrCmd, diskName, part))
if err != nil {
return fmt.Errorf("Failed to run grub-install: %s", err)
}
}

return nil
Expand Down
7 changes: 6 additions & 1 deletion core/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,16 @@ func runPostInstallOperation(chroot bool, operation string, args []interface{})
* - *BootDirectory* (`string`): The path for the boot dir (usually `/boot`).
* - *InstallDevice* (`string`): The disk where the boot partition is located.
* - *Target* (`string`): The target firmware. Either `bios` for legacy systems or `efi` for UEFI systems.
* - *EFIDevice* (optional `string`): Only required for EFI installations. The partition where the EFI is located.
*/
case "grub-install":
bootDirectory := args[0].(string)
installDevice := args[1].(string)
target := args[2].(string)
efiDevice := ""
if len(args) > 3 {
efiDevice = args[3].(string)
}
var grubTarget FirmwareType
switch target {
case "bios":
Expand All @@ -478,7 +483,7 @@ func runPostInstallOperation(chroot bool, operation string, args []interface{})
default:
return fmt.Errorf("Failed to execute operation: %s: Unrecognized firmware type: '%s')", operation, target)
}
err := RunGrubInstall(targetRoot, bootDirectory, installDevice, grubTarget)
err := RunGrubInstall(targetRoot, bootDirectory, installDevice, grubTarget, efiDevice)
if err != nil {
return err
}
Expand Down

0 comments on commit 5168f71

Please sign in to comment.