-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: support kexec from uki
Support kexec from UKI for non-secureboot by extracting kernel, initramfs and cmdline from UKI Fixes: #10189 Signed-off-by: Noel Georgi <[email protected]>
Showing
6 changed files
with
215 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
internal/app/machined/pkg/runtime/v1alpha1/bootloader/kexec/kexec.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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 kexec call unix.KexecFileLoad with error handling. | ||
package kexec | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
goruntime "runtime" | ||
|
||
"golang.org/x/sys/unix" | ||
|
||
"github.com/siderolabs/talos/internal/app/machined/pkg/runtime" | ||
"github.com/siderolabs/talos/internal/pkg/zboot" | ||
) | ||
|
||
// Load handles zboot for arm64 and calls unix.KexecFileLoad with error handling and sets the machine state to kexec prepared. | ||
func Load(r runtime.Runtime, kernel *os.File, initrdFD int, cmdline string) error { | ||
kernelFD := int(kernel.Fd()) | ||
|
||
// on arm64 we need to extract the kernel from the zboot image if it's compressed | ||
if goruntime.GOARCH == "arm64" { | ||
var ( | ||
fileCloser io.Closer | ||
extractErr error | ||
) | ||
|
||
kernelFD, fileCloser, extractErr = zboot.Extract(kernel) | ||
if extractErr != nil { | ||
return fmt.Errorf("failed to extract kernel from zboot: %w", extractErr) | ||
} | ||
|
||
defer func() { | ||
if fileCloser != nil { | ||
fileCloser.Close() //nolint:errcheck | ||
} | ||
}() | ||
} | ||
|
||
if err := unix.KexecFileLoad(kernelFD, initrdFD, cmdline, 0); err != nil { | ||
switch { | ||
case errors.Is(err, unix.ENOSYS): | ||
log.Printf("kexec support is disabled in the kernel") | ||
|
||
return nil | ||
case errors.Is(err, unix.EPERM): | ||
log.Printf("kexec support is disabled via sysctl") | ||
|
||
return nil | ||
case errors.Is(err, unix.EBUSY): | ||
log.Printf("kexec is busy") | ||
|
||
return nil | ||
default: | ||
return fmt.Errorf("error loading kernel for kexec: %w", err) | ||
} | ||
} | ||
|
||
r.State().Machine().KexecPrepared(true) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.