From 53c3064b73a49899b156dda7ee50759f66189651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnegren?= Date: Wed, 21 Feb 2024 15:24:50 +0100 Subject: [PATCH] Use backup legacy grub.cfg location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the new /etc/elemental/grub.cfg config is not found, revert to using /etc/cos/grub.cfg for backwards compatibility. Signed-off-by: Fredrik Lönnegren --- pkg/bootloader/grub.go | 37 ++++++++++++++++++++++--------------- pkg/constants/constants.go | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pkg/bootloader/grub.go b/pkg/bootloader/grub.go index d8e2a3c8dce..ace910acff8 100644 --- a/pkg/bootloader/grub.go +++ b/pkg/bootloader/grub.go @@ -57,12 +57,13 @@ type Grub struct { grubEfiImg string mokMngr string - grubPrefixes []string - configFile string - elementalCfg string - disableBootEntry bool - clearBootEntry bool - secureBoot bool + grubPrefixes []string + configFile string + elementalCfg string + legacyElementalCfg string + disableBootEntry bool + clearBootEntry bool + secureBoot bool } var _ v1.Bootloader = (*Grub)(nil) @@ -76,15 +77,16 @@ func NewGrub(cfg *v1.Config, opts ...GrubOptions) *Grub { secureBoot = false } g := &Grub{ - fs: cfg.Fs, - logger: cfg.Logger, - runner: cfg.Runner, - platform: cfg.Platform, - configFile: grubCfgFile, - grubPrefixes: defaultGrubPrefixes, - elementalCfg: filepath.Join(constants.GrubCfgPath, constants.GrubCfg), - clearBootEntry: true, - secureBoot: secureBoot, + fs: cfg.Fs, + logger: cfg.Logger, + runner: cfg.Runner, + platform: cfg.Platform, + configFile: grubCfgFile, + grubPrefixes: defaultGrubPrefixes, + elementalCfg: filepath.Join(constants.GrubCfgPath, constants.GrubCfg), + legacyElementalCfg: filepath.Join(constants.LegacyGrubCfgPath, constants.GrubCfg), + clearBootEntry: true, + secureBoot: secureBoot, } for _, o := range opts { @@ -413,6 +415,11 @@ func (g *Grub) Install(rootDir, bootDir string) (err error) { func (g Grub) InstallConfig(rootDir, bootDir string) error { for _, path := range g.grubPrefixes { grubFile := filepath.Join(rootDir, g.elementalCfg) + if exists, _ := utils.Exists(g.fs, grubFile); !exists { + grubFile = filepath.Join(rootDir, g.legacyElementalCfg) + g.logger.Warnf("Grub config not found, using legacy config: %s", grubFile) + } + dstGrubFile := filepath.Join(bootDir, path, g.configFile) g.logger.Infof("Using grub config file %s", grubFile) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 29cadfac95d..79ddc93edaf 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -182,6 +182,7 @@ const ( LegacyPassivePath = LegacyImagesPath + "/passive.img" LegacyActivePath = LegacyImagesPath + "/active.img" LegacyStateDir = "/run/initramfs/cos-state" + LegacyGrubCfgPath = "/etc/cos" ) // GetDefaultSystemEcludes returns a list of transient paths