77 "bufio"
88 "fmt"
99 "os"
10+ "os/exec"
1011 "os/signal"
1112 "path/filepath"
1213 "regexp"
@@ -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
195251func ejectDisk () (err error ) {
0 commit comments