Skip to content

Commit

Permalink
fix running out of space issue
Browse files Browse the repository at this point in the history
  • Loading branch information
taukakao committed Feb 13, 2025
1 parent 0499699 commit 616cb11
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 65 deletions.
37 changes: 0 additions & 37 deletions core/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ package core

import (
"errors"
"fmt"
"os"
"path"
"path/filepath"
"strings"

"github.com/hashicorp/go-version"
)
Expand Down Expand Up @@ -58,36 +54,3 @@ func getKernelVersion(bootPath string) string {

return ""
}

// cleanupOldKernels removes kernels not used by future root from the
// init partition.
//
// NOTE: this only works with LVM Think Provisioning turned on in ABRoot. Also
// note that this function explicitly removes all kernels except the
// one passed as argument, we can't just remove older versions because
// the kernel versioning is not guaranteed to be incremental, e.g. an
// update could introduce an older kernel version.
func cleanupOldKernels(newKernelVer string, initMountpoint string, partFuture string) (err error) {
fmt.Println(path.Join(initMountpoint, partFuture))
files, err := os.ReadDir(path.Join(initMountpoint, partFuture))
if err != nil {
return
}

for _, file := range files {
if strings.HasPrefix(file.Name(), "vmlinuz-") && file.Name() != "vmlinuz-"+newKernelVer {
err = os.Remove(path.Join(initMountpoint, partFuture, file.Name()))
if err != nil {
return
}
}
if strings.HasPrefix(file.Name(), "initrd.img-") && file.Name() != "initrd.img-"+newKernelVer {
err = os.Remove(path.Join(initMountpoint, partFuture, file.Name()))
if err != nil {
return
}
}
}

return nil
}
41 changes: 13 additions & 28 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,17 +552,28 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
return initPartition.Unmount()
}, nil, 80, &goodies.NoErrorHandler{}, false)

futureInitDir := filepath.Join(initMountpoint, partFuture.Label)

err = os.RemoveAll(futureInitDir)
if err != nil {
PrintVerboseWarn("ABSystem.RunOperation", 7.44)
}
err = os.MkdirAll(futureInitDir, 0o755)
if err != nil {
PrintVerboseWarn("ABSystem.RunOperation", 7.47, err)
}

err = CopyFile(
filepath.Join(systemNew, "boot", "vmlinuz-"+newKernelVer),
filepath.Join(initMountpoint, partFuture.Label, "vmlinuz-"+newKernelVer),
filepath.Join(futureInitDir, "vmlinuz-"+newKernelVer),
)
if err != nil {
PrintVerboseErr("ABSystem.RunOperation", 7.5, err)
return err
}
err = CopyFile(
filepath.Join(systemNew, "boot", "initrd.img-"+newKernelVer),
filepath.Join(initMountpoint, partFuture.Label, "initrd.img-"+newKernelVer),
filepath.Join(futureInitDir, "initrd.img-"+newKernelVer),
)
if err != nil {
PrintVerboseErr("ABSystem.RunOperation", 7.6, err)
Expand Down Expand Up @@ -736,32 +747,6 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
}
}

// Stage 11: Cleanup old kernel images
// ------------------------------------------------
// If Thin-Provisioning set, we have to remove the old kernel images
// from the init partition since it is too small to hold multiple kernels.
// This step runs as the last one to ensure the whole transaction is
// successful before removing the old kernels.
if settings.Cnf.ThinProvisioning {
switch operation {
case DRY_RUN_UPGRADE, DRY_RUN_APPLY, DRY_RUN_INITRAMFS:
default:
PrintVerboseSimple("[Stage 11] -------- ABSystemRunOperation")

// since we did the swap, the init partition is now mounted in
// .system instead of .system.new, so we need to update the path
// before proceeding
systemNew := filepath.Join(partFuture.Partition.MountPoint, ".system")
initMountpoint = filepath.Join(systemNew, "boot", "init")

err = cleanupOldKernels(newKernelVer, initMountpoint, partFuture.Label)
if err != nil {
PrintVerboseErr("ABSystem.RunOperation", 12, err)
return err
}
}
}

PrintVerboseInfo("ABSystem.RunOperation", "upgrade completed")
return nil
}
Expand Down

0 comments on commit 616cb11

Please sign in to comment.