Adapt uki install to new rootfsbase (#228)

This commit is contained in:
Itxaka
2024-02-12 10:35:36 +01:00
committed by GitHub
parent bd15303f33
commit 5f6bb7884f
3 changed files with 36 additions and 52 deletions

View File

@@ -565,8 +565,27 @@ func ReadUkiResetSpecFromConfig(c *Config) (*v1.ResetUkiSpec, error) {
} }
func NewUkiInstallSpec(cfg *Config) (*v1.InstallUkiSpec, 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{ spec := &v1.InstallUkiSpec{
Target: cfg.Install.Device, Target: cfg.Install.Device,
Active: activeImg,
} }
// Calculate the partitions afterwards so they use the image sizes for the final partition sizes // 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{}, Flags: []string{},
} }
err := unmarshallFullSpec(cfg, "install", spec) // Get the actual source size to calculate the image size and partitions size
// TODO: Get the actual source size to calculate the image size and partitions size for at least 3 UKI images 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 // Add default values for the skip partitions for our default entries
spec.SkipEntries = append(spec.SkipEntries, constants.UkiDefaultSkipEntries()...) spec.SkipEntries = append(spec.SkipEntries, constants.UkiDefaultSkipEntries()...)
return spec, err return spec, err

View File

@@ -504,6 +504,7 @@ type DockerImageMeta struct {
} }
type InstallUkiSpec struct { type InstallUkiSpec struct {
Active Image `yaml:"system,omitempty" mapstructure:"system"`
Target string `yaml:"device,omitempty" mapstructure:"device"` Target string `yaml:"device,omitempty" mapstructure:"device"`
Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"` Reboot bool `yaml:"reboot,omitempty" mapstructure:"reboot"`
PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"` PowerOff bool `yaml:"poweroff,omitempty" mapstructure:"poweroff"`

View File

@@ -33,55 +33,6 @@ func (i *InstallAction) Run() (err error) {
_ = utils.RunStage(i.cfg, "kairos-uki-install.pre") _ = utils.RunStage(i.cfg, "kairos-uki-install.pre")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.install.pre.hook") _ = 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 // Deactivate any active volume on target
err = e.DeactivateDevices() err = e.DeactivateDevices()
if err != nil { if err != nil {
@@ -123,7 +74,7 @@ func (i *InstallAction) Run() (err error) {
} }
// Copy the efi file into the proper dir // 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 { if err != nil {
return err return err
} }