mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-06-03 01:44:53 +00:00
Mount efi partition if not mounted for bootentries (#250)
This commit is contained in:
parent
5803280679
commit
0c06b1b183
@ -2,6 +2,8 @@ package action
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
cnst "github.com/kairos-io/kairos-agent/v2/pkg/constants"
|
||||
"github.com/kairos-io/kairos-agent/v2/pkg/elemental"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@ -229,11 +231,28 @@ func bootNameToSystemdConf(name string) (string, error) {
|
||||
// and prompts the user to select one
|
||||
// then calls the underlying SelectBootEntry function to mange the entry writing and validation
|
||||
func listBootEntriesSystemd(cfg *config.Config) error {
|
||||
var err error
|
||||
e := elemental.NewElemental(cfg)
|
||||
cleanup := utils.NewCleanStack()
|
||||
defer func() { err = cleanup.Cleanup(err) }()
|
||||
// Get EFI partition
|
||||
efiPartition, err := partitions.GetEfiPartition()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// mount if not mounted
|
||||
if mounted, err := utils.IsMounted(cfg, efiPartition); !mounted && err == nil {
|
||||
if efiPartition.MountPoint == "" {
|
||||
efiPartition.MountPoint = cnst.EfiDir
|
||||
}
|
||||
err = e.MountPartition(efiPartition)
|
||||
if err != nil {
|
||||
cfg.Logger.Errorf("could not mount EFI partition: %s", err)
|
||||
return err
|
||||
}
|
||||
cleanup.Push(func() error { return e.UnmountPartition(efiPartition) })
|
||||
}
|
||||
|
||||
// Get default entry from loader.conf
|
||||
loaderConf, err := utils.SystemdBootConfReader(cfg.Fs, filepath.Join(efiPartition.MountPoint, "loader/loader.conf"))
|
||||
if err != nil {
|
||||
@ -298,6 +317,7 @@ func listGrubEntries(cfg *config.Config) ([]string, error) {
|
||||
// /run/initramfs/cos-state/grub2/grub.cfg
|
||||
// /etc/kairos/branding/grubmenu.cfg
|
||||
// And grep the entries by checking the --id\s([A-z0-9]*)\s{ pattern
|
||||
// TODO: Check how to run this from livecd as it requires mounting state and grub?
|
||||
var entries []string
|
||||
for _, file := range []string{"/etc/cos/grub.cfg", "/run/initramfs/cos-state/grub/grub.cfg", "/etc/kairos/branding/grubmenu.cfg", "/run/initramfs/cos-state/grub2/grub.cfg"} {
|
||||
f, err := cfg.Fs.ReadFile(file)
|
||||
|
@ -2,6 +2,7 @@ package uki
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kairos-io/kairos-agent/v2/pkg/action"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@ -159,6 +160,12 @@ func (i *InstallAction) Run() (err error) {
|
||||
return fmt.Errorf("removing artifact set with role %s: %w", UnassignedArtifactRole, err)
|
||||
}
|
||||
|
||||
// SelectBootEntry sets the default boot entry to the selected entry
|
||||
err = action.SelectBootEntry(i.cfg, "active")
|
||||
if err != nil {
|
||||
i.cfg.Logger.Warnf("selecting active boot entry: %s", err.Error())
|
||||
}
|
||||
|
||||
err = hook.Run(*i.cfg, i.spec, hook.UKIEncryptionHooks...)
|
||||
if err != nil {
|
||||
i.cfg.Logger.Errorf("running uki encryption hooks: %s", err.Error())
|
||||
|
Loading…
Reference in New Issue
Block a user