Skip to content

Commit

Permalink
feat: add --extra-uefi-search-paths option
Browse files Browse the repository at this point in the history
This allows specifying additional paths to look for UEFI firmware.

Signed-off-by: Florian Klink <[email protected]>
Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
flokli authored and smira committed Jan 27, 2022
1 parent 7ffeb6c commit 4245f72
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmd/talosctl/cmd/mgmt/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
applyConfigEnabled bool
bootloaderEnabled bool
uefiEnabled bool
extraUEFISearchPaths []string
configDebug bool
networkCIDR string
networkMTU int
Expand Down Expand Up @@ -264,6 +265,7 @@ func create(ctx context.Context) (err error) {
provision.WithDockerPortsHostIP(dockerHostIP),
provision.WithBootlader(bootloaderEnabled),
provision.WithUEFI(uefiEnabled),
provision.WithExtraUEFISearchPaths(extraUEFISearchPaths),
provision.WithTargetArch(targetArch),
}
configBundleOpts := []bundle.Option{}
Expand Down Expand Up @@ -814,6 +816,7 @@ func init() {
createCmd.Flags().BoolVar(&applyConfigEnabled, "with-apply-config", false, "enable apply config when the VM is starting in maintenance mode")
createCmd.Flags().BoolVar(&bootloaderEnabled, "with-bootloader", true, "enable bootloader to load kernel and initramfs from disk image after install")
createCmd.Flags().BoolVar(&uefiEnabled, "with-uefi", false, "enable UEFI on x86_64 architecture (always enabled for arm64)")
createCmd.Flags().StringSliceVar(&extraUEFISearchPaths, "extra-uefi-search-paths", []string{}, "additional search paths for UEFI firmware (only applies when UEFI is enabled)")
createCmd.Flags().StringSliceVar(&registryMirrors, "registry-mirror", []string{}, "list of registry mirrors to use in format: <registry host>=<mirror URL>")
createCmd.Flags().StringSliceVar(&registryInsecure, "registry-insecure-skip-verify", []string{}, "list of registry hostnames to skip TLS verification for")
createCmd.Flags().BoolVar(&configDebug, "with-debug", false, "enable debug in Talos config to send service logs to the console")
Expand Down
11 changes: 11 additions & 0 deletions pkg/provision/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func WithUEFI(enabled bool) Option {
}
}

// WithExtraUEFISearchPaths configures additional search paths to look for UEFI firmware.
func WithExtraUEFISearchPaths(extraUEFISearchPaths []string) Option {
return func(o *Options) error {
o.ExtraUEFISearchPaths = extraUEFISearchPaths

return nil
}
}

// WithTargetArch specifies target architecture for the cluster.
func WithTargetArch(arch string) Option {
return func(o *Options) error {
Expand Down Expand Up @@ -110,6 +119,8 @@ type Options struct {

// Enable UEFI (for amd64), arm64 can only boot UEFI
UEFIEnabled bool
// Configure additional search paths to look for UEFI firmware.
ExtraUEFISearchPaths []string

// Expose ports to worker machines in docker provisioner
DockerPorts []string
Expand Down
21 changes: 17 additions & 4 deletions pkg/provision/providers/qemu/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package qemu

import "fmt"
import (
"fmt"
"path/filepath"
)

// Arch abstracts away differences between different architectures.
type Arch string
Expand Down Expand Up @@ -68,13 +71,18 @@ type PFlash struct {
}

// PFlash returns settings for parallel flash.
func (arch Arch) PFlash(uefiEnabled bool) []PFlash {
func (arch Arch) PFlash(uefiEnabled bool, extraUEFISearchPaths []string) []PFlash {
switch arch {
case ArchArm64:
uefiSourcePaths := []string{"/usr/share/qemu-efi-aarch64/QEMU_EFI.fd", "/usr/share/OVMF/QEMU_EFI.fd"}
for _, p := range extraUEFISearchPaths {
uefiSourcePaths = append(uefiSourcePaths, filepath.Join(p, "QEMU_EFI.fd"))
}

return []PFlash{
{
Size: 64 * 1024 * 1024,
SourcePaths: []string{"/usr/share/qemu-efi-aarch64/QEMU_EFI.fd", "/usr/share/OVMF/QEMU_EFI.fd"},
SourcePaths: uefiSourcePaths,
},
{
Size: 64 * 1024 * 1024,
Expand All @@ -85,10 +93,15 @@ func (arch Arch) PFlash(uefiEnabled bool) []PFlash {
return nil
}

uefiSourcePaths := []string{"/usr/share/ovmf/OVMF.fd", "/usr/share/OVMF/OVMF.fd"}
for _, p := range extraUEFISearchPaths {
uefiSourcePaths = append(uefiSourcePaths, filepath.Join(p, "OVMF.fd"))
}

return []PFlash{
{
Size: 0,
SourcePaths: []string{"/usr/share/ovmf/OVMF.fd", "/usr/share/OVMF/OVMF.fd"},
SourcePaths: uefiSourcePaths,
},
}
default:
Expand Down
2 changes: 1 addition & 1 deletion pkg/provision/providers/qemu/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *provisioner) createNode(state *vm.State, clusterReq provision.ClusterRe

var pflashImages []string

if pflashSpec := arch.PFlash(opts.UEFIEnabled); pflashSpec != nil {
if pflashSpec := arch.PFlash(opts.UEFIEnabled, opts.ExtraUEFISearchPaths); pflashSpec != nil {
var err error

if pflashImages, err = p.createPFlashImages(state, nodeReq.Name, pflashSpec); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/provision/providers/qemu/preflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (check *preflightCheckContext) qemuExecutable(ctx context.Context) error {
}

func (check *preflightCheckContext) checkFlashImages(ctx context.Context) error {
for _, flashImage := range check.arch.PFlash(check.options.UEFIEnabled) {
for _, flashImage := range check.arch.PFlash(check.options.UEFIEnabled, check.options.ExtraUEFISearchPaths) {
if len(flashImage.SourcePaths) == 0 {
continue
}
Expand All @@ -93,7 +93,8 @@ func (check *preflightCheckContext) checkFlashImages(ctx context.Context) error
}

if !found {
return fmt.Errorf("the required flash image was not found in any of the expected paths for (%q), please install it with the package manager", flashImage.SourcePaths)
return fmt.Errorf("the required flash image was not found in any of the expected paths for (%q), "+
"please install it with the package manager or specify --extra-uefi-search-paths", flashImage.SourcePaths)
}
}

Expand Down
1 change: 1 addition & 0 deletions website/content/docs/v0.15/Reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ talosctl cluster create [flags]
--extra-boot-kernel-args string add extra kernel args to the initial boot from vmlinuz and initramfs (QEMU only)
--extra-disks int number of extra disks to create for each worker VM
--extra-disks-size int default limit on disk size in MB (each VM) (default 5120)
--extra-uefi-search-paths strings additional search paths for UEFI firmware (only applies when UEFI is enabled)
-h, --help help for create
--image string the image to use (default "ghcr.io/talos-systems/talos:latest")
--init-node-as-endpoint use init node as endpoint instead of any load balancer endpoint
Expand Down

0 comments on commit 4245f72

Please sign in to comment.