From ff5d20f4f9295e7f8caa8e18f67a6357014bfd0e Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Tue, 11 Apr 2023 01:49:06 +0200 Subject: [PATCH] Implement grubby support --- internal/configs/config_bootloaders.go | 24 ++++++++++++++++++++---- internal/ui_main_functions.go | 8 ++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/internal/configs/config_bootloaders.go b/internal/configs/config_bootloaders.go index 7d20d41..651f34a 100644 --- a/internal/configs/config_bootloaders.go +++ b/internal/configs/config_bootloaders.go @@ -15,7 +15,7 @@ import ( func getBootloader(config *Config) { // Check what bootloader handler we are using // Check for grub-mkconfig - _, err := command.Run("which", "grub-mkconfig") + _, err := command.Run("which", "grub2-mkconfig") if err == nil { // Mark bootloader as grub2 config.Bootloader = "grub2" @@ -25,7 +25,7 @@ func getBootloader(config *Config) { _, err = command.Run("which", "grubby") if err == nil { // Mark it as unknown as i do not support it yet - config.Bootloader = "unknown" + config.Bootloader = "grubby" } // Check for kernelstub (used by pop os) @@ -60,9 +60,10 @@ func Set_Cmdline(gpu_IDs []string) { fileio.AppendContent(fmt.Sprintf(" vfio_pci.ids=%s", strings.Join(gpu_IDs, ",")), config.Path.CMDLINE) } -// TODO: write functions to configure kernelstub and grub -// TODO2: look into grubby +// TODO: write functions to configure grub // TODO3: if unknown bootloader, tell user what to add a kernel arguments + +// Configures systemd-boot using kernelstub func Set_KernelStub() { // Get the config config := GetConfig() @@ -76,3 +77,18 @@ func Set_KernelStub() { // Run the command command.Run("sudo", "kernelstub", "-a", kernel_args) } + +// Configures grub2 or systemd-boot using grubby +func Set_Grubby() { + // Get the config + config := GetConfig() + + // Get the kernel args + kernel_args := fileio.ReadFile(config.Path.CMDLINE) + + // Write to logger + logger.Printf("Running command:\nsudo grubby --update-kernel=ALL --args=\"%s\"", kernel_args) + + // Run the command + command.Run("sudo", "grubby", "--update-kernel=ALL", fmt.Sprintf("--args=%s", kernel_args)) +} diff --git a/internal/ui_main_functions.go b/internal/ui_main_functions.go index 930ca83..b0efdc5 100644 --- a/internal/ui_main_functions.go +++ b/internal/ui_main_functions.go @@ -163,6 +163,14 @@ func (m *model) install(auth string) { // Configure kernelstub configs.Set_KernelStub() + + } else if config.Bootloader == "grubby" { + // Write to logger + logger.Printf("Configuring bootloader using grubby") + + // Configure kernelstub + configs.Set_Grubby() + } else if config.Bootloader == "unknown" { kernel_args := fileio.ReadFile(config.Path.CMDLINE) fmt.Printf("Unsupported bootloader, please add the below line to your bootloaders kernel arguments\n%s", kernel_args)