Skip to content

Commit

Permalink
Merge pull request #232 from kairos-io/2051-uki-reset
Browse files Browse the repository at this point in the history
Move "recovery" to "active" on reset
  • Loading branch information
jimmykarily authored Feb 21, 2024
2 parents 8c353a9 + ca84f82 commit cce4321
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/config/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,27 @@ func NewUkiResetSpec(cfg *Config) (spec *v1.ResetUkiSpec, err error) {
spec.Partitions.Persistent = partitions.GetPartitionViaDM(cfg.Fs, constants.PersistentLabel)
spec.Partitions.OEM = partitions.GetPartitionViaDM(cfg.Fs, constants.OEMLabel)

// Get EFI partition
parts, err := partitions.GetAllPartitions()
if err != nil {
return spec, fmt.Errorf("could not read host partitions")
}
for _, p := range parts {
if p.FilesystemLabel == constants.EfiLabel {
spec.Partitions.EFI = p
break
}
}

if spec.Partitions.Persistent == nil {
return spec, fmt.Errorf("persistent partition not found")
}
if spec.Partitions.OEM == nil {
return spec, fmt.Errorf("oem partition not found")
}
if spec.Partitions.EFI == nil {
return spec, fmt.Errorf("efi partition not found")
}

// Fill oem partition
err = unmarshallFullSpec(cfg, "reset", spec)
Expand Down
16 changes: 16 additions & 0 deletions pkg/uki/reset.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package uki

import (
"fmt"

"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"
elementalUtils "github.com/kairos-io/kairos-agent/v2/pkg/utils"
Expand Down Expand Up @@ -55,6 +58,19 @@ func (r *ResetAction) Run() (err error) {
}
}

// REMOUNT /efi as RW (its RO by default)
umount, err := e.MountRWPartition(r.spec.Partitions.EFI)
if err != nil {
return err
}
cleanup.Push(umount)

// Copy "recovery" to "active"
err = overwriteArtifactSetRole(r.cfg.Fs, constants.UkiEfiDir, "recovery", "active", r.cfg.Logger)
if err != nil {
return fmt.Errorf("copying recovery to active: %w", err)
}

_ = elementalUtils.RunStage(r.cfg, "kairos-uki-reset.after")
_ = events.RunHookScript("/usr/bin/kairos-agent.uki.reset.after.hook") //nolint:errcheck

Expand Down

0 comments on commit cce4321

Please sign in to comment.