Skip to content

Commit

Permalink
[uki] Fix spec partitions and do the system copy
Browse files Browse the repository at this point in the history
Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Sep 19, 2023
1 parent 6a0827f commit 47a2b87
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pkg/config/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,12 @@ func NewUkiInstallSpec(cfg *Config) *v1.InstallUkiSpec {
}

// Calculate the partitions afterwards so they use the image sizes for the final partition sizes
spec.Partitions.BIOS = &v1.Partition{
spec.Partitions.EFI = &v1.Partition{
FilesystemLabel: constants.EfiLabel,
Size: constants.ImgSize, // TODO: Fix this and set proper size based on the source size
Name: constants.EfiPartName,
FS: constants.EfiFs,
MountPoint: constants.EfiDir,
}
spec.Partitions.OEM = &v1.Partition{
FilesystemLabel: constants.OEMLabel,
Expand Down
56 changes: 49 additions & 7 deletions pkg/uki/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package uki
import (
hook "github.com/kairos-io/kairos-agent/v2/internal/agent/hooks"
"github.com/kairos-io/kairos-agent/v2/pkg/config"
"github.com/kairos-io/kairos-agent/v2/pkg/constants"
"github.com/kairos-io/kairos-agent/v2/pkg/elemental"
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1"
"github.com/kairos-io/kairos-agent/v2/pkg/utils"
fsutils "github.com/kairos-io/kairos-agent/v2/pkg/utils/fs"
events "github.com/kairos-io/kairos-sdk/bus"
"os"
"syscall"
"path/filepath"
)

type InstallAction struct {
Expand All @@ -33,10 +34,38 @@ func (i *InstallAction) Run() (err error) {
// If source is empty then we need to find the media we booted from....to get the efi files...
// cdrom is kind fo easy...
// we set the label EFI_ISO_BOOT so we look for that and then mount the image inside...
fsutils.MkdirAll(i.cfg.Fs, "/run/cdrom", os.ModeDir|os.ModePerm)
fsutils.MkdirAll(i.cfg.Fs, "/run/efi", os.ModeDir|os.ModePerm)
syscall.Mount("/dev/disk/by-label/EFI_ISO_BOOT", "/run/cdrom", "iso9660", 0, "")
syscall.Mount("/run/cdrom/efiboot.img", "/run/efi", "loop", 0, "")
// TODO: Extract this to a different functions or something. Maybe PrepareUKISource or something
_ = fsutils.MkdirAll(i.cfg.Fs, "/run/install/cdrom", os.ModeDir|os.ModePerm)
_ = fsutils.MkdirAll(i.cfg.Fs, "/run/install/uki", os.ModeDir|os.ModePerm)

cdRom := &v1.Partition{
FilesystemLabel: "EFI_ISO_BOOT",
FS: "iso9660",
Path: "/dev/disk/by-label/EFI_ISO_BOOT",
MountPoint: "/run/install/cdrom",
}
err = e.MountPartition(cdRom)

if err != nil {
return err
}
cleanup.Push(func() error {
return e.UnmountPartition(cdRom)
})

image := &v1.Image{
File: "/run/install/cdrom/efiboot.img",
Label: "UKI_SOURCE",
MountPoint: "/run/install/uki",
}

err = e.MountImage(image)
if err != nil {
return err
}
cleanup.Push(func() error {
return e.UnmountImage(image)
})

// Create EFI partition (fat32), we already create the efi partition on normal efi install,we can reuse that?
// Create COS_OEM/COS_PERSISTANT if set (optional)
Expand Down Expand Up @@ -72,13 +101,26 @@ func (i *InstallAction) Run() (err error) {
// Create dir structure
// - /EFI/Kairos/ -> Store our efi images
// - /EFI/BOOT/ -> Default fallback dir (efi search for bootaa64.efi or bootx64.efi if no entries in the boot manager)
// NOTE: Maybe softlink fallback to kairos? Not sure if that will work

err = fsutils.MkdirAll(i.cfg.Fs, filepath.Join(constants.EfiDir, "EFI", "Kairos"), constants.DirPerm)
if err != nil {
return err
}
err = fsutils.MkdirAll(i.cfg.Fs, filepath.Join(constants.EfiDir, "EFI", "BOOT"), constants.DirPerm)
if err != nil {
return err
}

// Copy the efi file into the proper dir
source := v1.NewDirSrc("/run/install/uki")
_, err = e.DumpSource(i.spec.Partitions.EFI.MountPoint, source)
if err != nil {
return err
}
// Remove all boot manager entries?
// Create boot manager entry
// Set default entry to the one we just created
// Probably copy efi utils, like the Mokmanager and even the shim or grub efi to help with troubleshooting?

_ = utils.RunStage(i.cfg, "kairos-uki-install.after")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.install.after.hook") //nolint:errcheck

Expand Down

0 comments on commit 47a2b87

Please sign in to comment.