Fix uki mode detection (#198)

This commit is contained in:
Itxaka
2024-01-10 10:38:31 +01:00
committed by GitHub
parent 174d69c3ea
commit 53f49169b1
3 changed files with 21 additions and 5 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/kairos-io/kairos-sdk/machine" "github.com/kairos-io/kairos-sdk/machine"
"github.com/kairos-io/kairos-sdk/utils" "github.com/kairos-io/kairos-sdk/utils"
kcrypt "github.com/kairos-io/kcrypt/pkg/lib" kcrypt "github.com/kairos-io/kcrypt/pkg/lib"
"os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -41,6 +42,15 @@ func (k KcryptUKI) Run(c config.Config, _ v1.Spec) error {
return nil return nil
} }
// Check for a TPM 2.0 device as its needed to encrypt
// Exposed by the kernel to userspace as /dev/tpmrm0 since kernel 4.12
// https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=fdc915f7f71939ad5a3dda3389b8d2d7a7c5ee66
_, err = os.Stat("/dev/tpmrm0")
if err != nil {
c.Logger.Warnf("Skipping partition encryption, could not find TPM 2.0 device at /dev/tpmrm0")
return nil
}
// We always encrypt OEM and PERSISTENT under UKI // We always encrypt OEM and PERSISTENT under UKI
// If mounted, unmount it // If mounted, unmount it
_ = machine.Umount(constants.OEMDir) //nolint:errcheck _ = machine.Umount(constants.OEMDir) //nolint:errcheck

View File

@@ -218,8 +218,13 @@ func RunInstall(c *config.Config) error {
// UKI path. Check if we are on UKI AND if we are running off a cd, otherwise it makes no sense to run the install // UKI path. Check if we are on UKI AND if we are running off a cd, otherwise it makes no sense to run the install
// From the installed system // From the installed system
if internalutils.UkiBootMode() == internalutils.UkiRemovableMedia { if internalutils.IsUki() {
return runInstallUki(c) c.Logger.Debugf("UKI mode: %s\n", internalutils.UkiBootMode())
if internalutils.UkiBootMode() == internalutils.UkiRemovableMedia {
return runInstallUki(c)
}
c.Logger.Warnf("UKI boot mode is not removable media, skipping install")
return nil
} else { // Non-uki path } else { // Non-uki path
return runInstall(c) return runInstall(c)
} }
@@ -289,8 +294,9 @@ func dumpCCStringToFile(c *config.Config) (string, error) {
c.Logger.Error("Error creating temporary file for install config: %s\n", err.Error()) c.Logger.Error("Error creating temporary file for install config: %s\n", err.Error())
return "", err return "", err
} }
defer os.RemoveAll(f.Name()) defer func(f *os.File) {
_ = f.Close()
}(f)
ccstring, err := c.String() ccstring, err := c.String()
if err != nil { if err != nil {
return "", err return "", err

View File

@@ -520,7 +520,7 @@ const (
func UkiBootMode() state.Boot { func UkiBootMode() state.Boot {
if IsUki() { if IsUki() {
_, err := os.Stat("/run/cos/uki_boot_mode") _, err := os.Stat("/run/cos/uki_boot_mode")
if err != nil { if err == nil {
return UkiHDD return UkiHDD
} }
return UkiRemovableMedia return UkiRemovableMedia