diff --git a/pkg/config/spec.go b/pkg/config/spec.go index 05ef4c7..f954fcc 100644 --- a/pkg/config/spec.go +++ b/pkg/config/spec.go @@ -565,8 +565,27 @@ func ReadUkiResetSpecFromConfig(c *Config) (*v1.ResetUkiSpec, error) { } func NewUkiInstallSpec(cfg *Config) (*v1.InstallUkiSpec, error) { + var activeImg v1.Image + + isoRootExists, _ := fsutils.Exists(cfg.Fs, constants.IsoBaseTree) + + // First try to use the install media source + if isoRootExists { + activeImg.Source = v1.NewDirSrc(constants.IsoBaseTree) + } + // Then any user provided source + if cfg.Install.Source != "" { + activeImg.Source, _ = v1.NewSrcFromURI(cfg.Install.Source) + } + // If we dont have any just an empty source so the sanitation fails + // TODO: Should we directly fail here if we got no source instead of waiting for the Sanitize() to fail? + if !isoRootExists && cfg.Install.Source == "" { + activeImg.Source = v1.NewEmptySrc() + } + spec := &v1.InstallUkiSpec{ Target: cfg.Install.Device, + Active: activeImg, } // Calculate the partitions afterwards so they use the image sizes for the final partition sizes @@ -595,8 +614,21 @@ func NewUkiInstallSpec(cfg *Config) (*v1.InstallUkiSpec, error) { Flags: []string{}, } - err := unmarshallFullSpec(cfg, "install", spec) - // TODO: Get the actual source size to calculate the image size and partitions size for at least 3 UKI images + // Get the actual source size to calculate the image size and partitions size + size, err := GetSourceSize(cfg, spec.Active.Source) + if err != nil { + cfg.Logger.Warnf("Failed to infer size for images, leaving it as default size (%sMb): %s", spec.Partitions.EFI.Size, err.Error()) + } else { + // Only override if the calculated size is bigger than the default size, otherwise stay with 15Gb minimum + if uint(size*3) > spec.Partitions.EFI.Size { + spec.Partitions.EFI.Size = uint(size * 3) + } + } + + cfg.Logger.Infof("Setting image size to %dMb", spec.Partitions.EFI.Size) + + err = unmarshallFullSpec(cfg, "install", spec) + // Add default values for the skip partitions for our default entries spec.SkipEntries = append(spec.SkipEntries, constants.UkiDefaultSkipEntries()...) return spec, err diff --git a/pkg/types/v1/config.go b/pkg/types/v1/config.go index ecbf2a1..7e29666 100644 --- a/pkg/types/v1/config.go +++ b/pkg/types/v1/config.go @@ -504,6 +504,7 @@ type DockerImageMeta struct { } type InstallUkiSpec struct { + Active Image `yaml:"system,omitempty" mapstructure:"system"` Target string `yaml:"device,omitempty" mapstructure:"device"` Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"` PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"` diff --git a/pkg/uki/install.go b/pkg/uki/install.go index 5eb098f..89071b2 100644 --- a/pkg/uki/install.go +++ b/pkg/uki/install.go @@ -33,55 +33,6 @@ func (i *InstallAction) Run() (err error) { _ = utils.RunStage(i.cfg, "kairos-uki-install.pre") _ = events.RunHookScript("/usr/bin/kairos-agent.uki.install.pre.hook") - // immucore mounts CDROM under this path - _, err = i.cfg.Fs.Stat(constants.UkiCdromSource) - if err != nil { - i.cfg.Logger.Errorf("mountpoint '%s' not ready. error: %s", constants.UkiCdromSource, err) - return err - } - // Get source (from spec?) - // If source is empty then we need to find the media we booted from....to get the efi files... - // cdrom is kind fo easy... - _ = fsutils.MkdirAll(i.cfg.Fs, constants.UkiSource, os.ModeDir|os.ModePerm) - - image := &v1.Image{ - File: filepath.Join(constants.UkiCdromSource, "efiboot.img"), - Label: "UKI_SOURCE", // Made up, only for logging - MountPoint: constants.UkiSource, - } - - mounted, err := i.cfg.Mounter.IsMountPoint(constants.UkiCdromSource) - if !mounted || err != nil { - err = e.MountImage(image) - if err != nil { - return err - } - } - - cleanup.Push(func() error { - return e.UnmountImage(image) - }) - - source := v1.NewDirSrc(constants.UkiSource) - - // Get the actual source size to calculate the image size and partitions size - size, err := config.GetSourceSize(i.cfg, source) - if err != nil { - i.cfg.Logger.Warnf("Failed to infer size for images, leaving it as default size (%sMb): %s", i.spec.Partitions.EFI.Size, err.Error()) - } else { - // Only override if the calculated size is bigger than the default size, otherwise stay with 15Gb minimum - if uint(size*3) > i.spec.Partitions.EFI.Size { - i.spec.Partitions.EFI.Size = uint(size * 3) - } - } - - i.cfg.Logger.Infof("Setting image size to %dMb", i.spec.Partitions.EFI.Size) - - // 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) - // I guess we need to set sensible default values here for sizes? oem -> 64Mb as usual but if no persistent then EFI max size? - // if persistent then EFI = source size * 2 (or maybe 3 times! so we can upgrade!) and then persistent the rest of the disk? - // Deactivate any active volume on target err = e.DeactivateDevices() if err != nil { @@ -123,7 +74,7 @@ func (i *InstallAction) Run() (err error) { } // Copy the efi file into the proper dir - _, err = e.DumpSource(i.spec.Partitions.EFI.MountPoint, source) + _, err = e.DumpSource(i.spec.Partitions.EFI.MountPoint, i.spec.Active.Source) if err != nil { return err }