Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use backup legacy grub.cfg location #1967

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions pkg/bootloader/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
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
Loading