Skip to content

Commit

Permalink
Use backup legacy grub.cfg location
Browse files Browse the repository at this point in the history
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 <fredrik.lonnegren@suse.com>
  • Loading branch information
frelon committed Feb 21, 2024
1 parent 8f802fa commit 1a493f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
40 changes: 25 additions & 15 deletions pkg/bootloader/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package bootloader
import (
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"

Expand Down Expand Up @@ -57,12 +58,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)
Expand All @@ -76,15 +78,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 {
Expand Down Expand Up @@ -413,6 +416,13 @@ 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 _, err := os.Stat(grubFile); err != nil {
if os.IsNotExist(err) {
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)
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a493f9

Please sign in to comment.