Skip to content

Commit 2be6ce5

Browse files
committed
Add efibootmgr and unify EFI boot entry handling
- Added efibootmgr to grub2-mkconfig package list - Enhanced boot entry creation for both attended and Kickstart-based installs - Updated boot label to Edge MicrovisorToolkit - Improved EFI entry cleanup logic for existing boot entries Signed-off-by: kinatli jayanth <jayanthx.kintali@intel.com>
1 parent 10c24b1 commit 2be6ce5

File tree

2 files changed

+70
-13
lines changed

2 files changed

+70
-13
lines changed

toolkit/imageconfigs/packagelists/core-packages-image.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"packages": [
33
"shim",
4+
"efibootmgr",
45
"grub2-efi-binary",
56
"ca-certificates",
67
"cronie-anacron",

toolkit/tools/liveinstaller/liveinstaller.go

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"os"
1010
"os/signal"
11+
"os/exec"
1112
"path/filepath"
1213
"regexp"
1314
"strconv"
@@ -146,7 +147,7 @@ func updateBootOrder(installDetails installationDetails) (err error) {
146147
return
147148
}
148149

149-
err = removeOldAzureLinuxBootTargets()
150+
err = removeOldEdgeMicrovisorToolkitBootTargets()
150151
if err != nil {
151152
return
152153
}
@@ -164,32 +165,87 @@ func runBootEntryCreationCommand(installDetails installationDetails) (err error)
164165
const squashErrors = false
165166
program := "efibootmgr"
166167
cfg := installDetails.finalConfig
168+
169+
if cfg.DefaultSystemConfig.IsKickStartBoot {
170+
logger.Log.Info("Unattended installation: parsing Kickstart file to get disk info")
171+
172+
kickstartPartitionFile := "/tmp/part-include"
173+
disks, _, err := configuration.ParseKickStartPartitionScheme(kickstartPartitionFile)
174+
logger.PanicOnError(err, "Failed to parse partition schema")
175+
// Save disk config settings
176+
if len(disks) == 0 {
177+
return fmt.Errorf("Kickstart parsed disk list is empty")
178+
}
179+
cfg.Disks = disks
180+
}
167181
bootPartIdx, bootPart := cfg.GetBootPartition()
168182
bootDisk := cfg.GetDiskContainingPartition(bootPart)
183+
169184
commandArgs := []string{
170185
"-c", // Create a new bootnum and place it in the beginning of the boot order
171186
"-d", bootDisk.TargetDisk.Value, // Specify which disk the boot file is on
172187
"-p", fmt.Sprintf("%d", bootPartIdx+1), // Specify which partition the boot file is on
173-
"-l", "'\\EFI\\BOOT\\bootx64.efi'", // Specify the path for where the boot file is located on the partition
174-
"-L", "Azure Linux", // Specify what label you would like to give this boot entry
188+
"-l", "\\EFI\\BOOT\\bootx64.efi", // Specify the path for where the boot file is located on the partition
189+
"-L", "Edge Microvisor Toolkit", // Specify what label you would like to give this boot entry
175190
"-v", // Be verbose
176191
}
177192
err = shell.ExecuteLive(squashErrors, program, commandArgs...)
178193
return
179194
}
180195

181-
func removeOldAzureLinuxBootTargets() (err error) {
196+
func removeOldEdgeMicrovisorToolkitBootTargets() (err error) {
182197
const squashErrors = false
183-
logger.Log.Info("Removing pre-existing 'Azure Linux' boot targets from efibootmgr")
184-
program := "efibootmgr" // Default behavior when piped or called without options is to print current boot order in a human-readable format
185-
commandArgs := []string{
186-
"|", "grep", "\"Azure Linux\"", // Filter boot order for Azure Linux boot targets
187-
"|", "sed", "'s/* Azure Linux//g'", // Pruning for just the bootnum
188-
"|", "sed", "'s/Boot*//g'", // Pruning for just the bootnum
189-
"|", "xargs", "-t", "-i", "efibootmgr", "-b", "{}", "-B", // Calling efibootmgr --delete-bootnum (aka `-B`) on each pre-existing bootnum with an Azure Linux label
198+
199+
logger.Log.Info("Removing pre-existing 'Edge Microvisor Toolkit' boot targets from efibootmgr")
200+
201+
//Run the command and capture the EMT grep output from efibootmgr
202+
outputBytes, err := exec.Command("sh", "-c", `efibootmgr | grep "Edge Microvisor Toolkit"`).CombinedOutput()
203+
output := string(outputBytes)
204+
205+
if err != nil {
206+
return fmt.Errorf("error running efibootmgr grep: %v, output: %s", err, output)
190207
}
191-
err = shell.ExecuteLive(squashErrors, program, commandArgs...)
192-
return
208+
209+
if len(output) == 0 {
210+
logger.Log.Info("No 'Edge Microvisor Toolkit' boot entries found.")
211+
return nil
212+
}
213+
logger.Log.Infof("Raw efibootmgr grep output:\n%s", output)
214+
215+
//Parse boot IDs from output
216+
lines := strings.Split(output, "\n")
217+
var bootIDs []string
218+
for _, line := range lines {
219+
fields := strings.Fields(line)
220+
if len(fields) == 0 {
221+
continue
222+
}
223+
id := fields[0]
224+
id = strings.TrimPrefix(id, "Boot")
225+
id = strings.TrimSuffix(id, "*")
226+
if id != "" {
227+
bootIDs = append(bootIDs, id)
228+
}
229+
}
230+
231+
if len(bootIDs) == 0 {
232+
logger.Log.Info("No boot IDs found in output.")
233+
return nil
234+
}
235+
logger.Log.Infof("Parsed boot IDs to delete: %v", bootIDs)
236+
237+
//Delete each EMT boot entry
238+
for _, id := range bootIDs {
239+
delCmd := fmt.Sprintf("efibootmgr -b %s -B", id)
240+
logger.Log.Infof("Deleting boot entry with command: %s", delCmd)
241+
err := shell.ExecuteLive(squashErrors, "sh", "-c", delCmd)
242+
if err != nil {
243+
logger.Log.Errorf("Failed to delete boot entry Boot%s: %v", id, err)
244+
} else {
245+
logger.Log.Infof("Deleted boot entry Boot%s", id)
246+
}
247+
}
248+
return nil
193249
}
194250

195251
func ejectDisk() (err error) {

0 commit comments

Comments
 (0)