Andrey Smirnov 0a30ef7845
fix: imager should support different Talos versions
Add some quirks to make images generated with newer Talos compatible
with images generated by older Talos.

Specifically, reset options were adding in Talos 1.4, so we shouldn't
add them for older versions.

Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
2023-12-22 16:13:34 +04:00

76 lines
2.0 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Package bootloader provides bootloader implementation.
package bootloader
import (
"context"
"os"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/grub"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/options"
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime/v1alpha1/bootloader/sdboot"
"github.com/siderolabs/talos/pkg/imager/quirks"
)
// Bootloader describes a bootloader.
type Bootloader interface {
// Install installs the bootloader
Install(options options.InstallOptions) error
// Revert reverts the bootloader entry to the previous state.
Revert(ctx context.Context) error
// PreviousLabel returns the previous bootloader label.
PreviousLabel() string
// UEFIBoot returns true if the bootloader is UEFI-only.
UEFIBoot() bool
}
// Probe checks if any supported bootloaders are installed.
//
// If 'disk' is empty, it will probe all disks.
// Returns nil if it cannot detect any supported bootloader.
func Probe(ctx context.Context, disk string) (Bootloader, error) {
grubBootloader, err := grub.Probe(ctx, disk)
if err != nil {
return nil, err
}
if grubBootloader != nil {
return grubBootloader, nil
}
sdbootBootloader, err := sdboot.Probe(ctx, disk)
if err != nil {
return nil, err
}
if sdbootBootloader != nil {
return sdbootBootloader, nil
}
return nil, os.ErrNotExist
}
// NewAuto returns a new bootloader based on auto-detection.
func NewAuto() Bootloader {
if sdboot.IsBootedUsingSDBoot() {
return sdboot.New()
}
return grub.NewConfig()
}
// New returns a new bootloader based on the secureboot flag.
func New(secureboot bool, talosVersion string) Bootloader {
if secureboot {
return sdboot.New()
}
g := grub.NewConfig()
g.AddResetOption = quirks.New(talosVersion).SupportsResetGRUBOption()
return g
}