Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reset #565

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions pkg/action/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,35 @@ func (r ResetAction) Run() (err error) {
cleanup := utils.NewCleanStack()
defer func() { err = cleanup.Cleanup(err) }()

// Unmount partitions if any is already mounted before formatting
// TODO: Is this needed???
err = e.UnmountPartitions(r.spec.Partitions.PartitionsByMountPoint(true, r.spec.Partitions.Recovery))
if err != nil {
return err
}

// Reformat state partition
err = e.FormatPartition(r.spec.Partitions.State)
if err != nil {
return err
}
// We should expose this under a flag, to reformat state before starting
// In case state fs is broken somehow
/*
if r.spec.FormatState {
state := r.spec.Partitions.State
if state != nil {
err = e.UnmountPartition(state)
if err != nil {
return err
}
err = e.FormatPartition(state)
if err != nil {
return err
}
// Mount it back
err = e.MountPartition(state)
if err != nil {
return err
}
}
}
*/

// Reformat persistent partition
if r.spec.FormatPersistent {
persistent := r.spec.Partitions.Persistent
if persistent != nil {
err = e.UnmountPartitions(r.spec.Partitions.PartitionsByMountPoint(true, persistent))
Itxaka marked this conversation as resolved.
Show resolved Hide resolved
err = e.UnmountPartition(persistent)
if err != nil {
return err
}
Expand All @@ -146,30 +157,34 @@ func (r ResetAction) Run() (err error) {
oem := r.spec.Partitions.OEM
if oem != nil {
// Try to umount
err = e.UnmountPartitions(r.spec.Partitions.PartitionsByMountPoint(true, oem))
err = e.UnmountPartition(oem)
if err != nil {
return err
}
err = e.FormatPartition(oem)
if err != nil {
return err
}
// Mount it back, as oem is mounted during recovery, keep everything as is
err = e.MountPartition(oem)
if err != nil {
return err
}
}
}
// Mount configured partitions
err = e.MountPartitions(r.spec.Partitions.PartitionsByMountPoint(false, r.spec.Partitions.Recovery))

// Before reset hook happens once partitions are aready and before deploying the OS image
err = r.resetHook(cnst.BeforeResetHook, false)
jimmykarily marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
cleanup.Push(func() error {
return e.UnmountPartitions(r.spec.Partitions.PartitionsByMountPoint(true, r.spec.Partitions.Recovery))
})

// Before reset hook happens once partitions are aready and before deploying the OS image
err = r.resetHook(cnst.BeforeResetHook, false)
// Mount COS_STATE so we can write the new images
err = e.MountPartition(r.spec.Partitions.State)
if err != nil {
return err
}
cleanup.Push(func() error { return e.UnmountPartition(r.spec.Partitions.State) })

// Deploy active image
meta, err := e.DeployImage(&r.spec.Active, true)
Expand Down
2 changes: 0 additions & 2 deletions pkg/config/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ func NewResetSpec(cfg *Config) (*v1.ResetSpec, error) {
return nil, fmt.Errorf("could not read host partitions")
}
ep := v1.NewElementalPartitionsFromList(parts)

if efiExists {
if ep.EFI == nil {
return nil, fmt.Errorf("EFI partition not found")
Expand Down Expand Up @@ -480,7 +479,6 @@ func NewResetSpec(cfg *Config) (*v1.ResetSpec, error) {
target := ep.State.Disk

// OEM partition is not a hard requirement for reset unless we have the reset oem flag
cfg.Logger.Info(litter.Sdump(ep.OEM))
if ep.OEM == nil {
// We could have oem in lvm which won't appear in ghw list
ep.OEM = partitions.GetPartitionViaDM(cfg.Fs, constants.OEMLabel)
Expand Down
4 changes: 2 additions & 2 deletions pkg/elemental/elemental.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ func (e *Elemental) DeployImage(img *v1.Image, leaveMounted bool) (info interfac
}
}
} else if img.Label != "" && img.FS != cnst.SquashFs {
_, err = e.config.Runner.Run("tune2fs", "-L", img.Label, img.File)
out, err := e.config.Runner.Run("tune2fs", "-L", img.Label, img.File)
if err != nil {
e.config.Logger.Errorf("Failed to apply label %s to %s", img.Label, img.File)
e.config.Logger.Errorf("Failed to apply label %s to %s: %s", img.Label, img.File, string(out))
_ = e.config.Fs.Remove(img.File)
return nil, err
}
Expand Down
Loading