fix(mount): check if path is mounted and create /run/initramfs/live if doesn't exist

This commit is contained in:
mudler 2024-02-09 09:54:56 +01:00
parent 175b163159
commit b8388782b0

View File

@ -1,6 +1,7 @@
package uki package uki
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -35,8 +36,13 @@ func (i *InstallAction) Run() (err error) {
// immucore mounts CDROM under this path // immucore mounts CDROM under this path
_, err = i.cfg.Fs.Stat(constants.UkiCdromSource) _, err = i.cfg.Fs.Stat(constants.UkiCdromSource)
if err != nil { if errors.Is(err, os.ErrNotExist) {
i.cfg.Logger.Errorf("Error checking if %s exists: %s", constants.UkiCdromSource, err) // The directory is under /run, so we can create it if not present
if err := fsutils.MkdirAll(i.cfg.Fs, constants.UkiCdromSource, os.ModeDir|os.ModePerm); err != nil {
i.cfg.Logger.Errorf("Error creating %s: %s", constants.UkiCdromSource, err)
}
} else if err != nil {
i.cfg.Logger.Errorf("stat error for '%s'. error: %s", constants.UkiCdromSource, err)
return err return err
} }
// Get source (from spec?) // Get source (from spec?)
@ -50,10 +56,14 @@ func (i *InstallAction) Run() (err error) {
MountPoint: constants.UkiSource, MountPoint: constants.UkiSource,
} }
err = e.MountImage(image) mounted, err := i.cfg.Mounter.IsMountPoint(constants.UkiCdromSource)
if err != nil { if !mounted || err != nil {
return err err = e.MountImage(image)
if err != nil {
return err
}
} }
cleanup.Push(func() error { cleanup.Push(func() error {
return e.UnmountImage(image) return e.UnmountImage(image)
}) })