diff --git a/internal/utils/mounts.go b/internal/utils/mounts.go index bf3910b..a13f62e 100644 --- a/internal/utils/mounts.go +++ b/internal/utils/mounts.go @@ -66,7 +66,7 @@ func IsMounted(dev string) bool { func DiskFSType(s string) string { out, e := CommandWithPath(fmt.Sprintf("blkid %s -s TYPE -o value", s)) if e != nil { - Log.Err(e).Msg("blkid") + Log.Debug().Err(e).Msg("blkid") } out = strings.Trim(strings.Trim(out, " "), "\n") Log.Debug().Str("what", s).Str("type", out).Msg("Partition FS type") @@ -123,6 +123,7 @@ func CleanSysrootForFstab(path string) string { if cleaned == "" { cleaned = "/" } + Log.Debug().Str("old", path).Str("new", cleaned).Msg("Cleaning for sysroot") return cleaned } diff --git a/pkg/mount/dag_steps.go b/pkg/mount/dag_steps.go index e9ef767..2cf4069 100644 --- a/pkg/mount/dag_steps.go +++ b/pkg/mount/dag_steps.go @@ -90,8 +90,6 @@ func (s *State) MountRootDagStep(g *herd.Graph) error { "suid", "dev", "exec", - // "auto", - //"nouser", "async", }, 10*time.Second), ), diff --git a/pkg/mount/operation.go b/pkg/mount/operation.go index 2398644..28601c7 100644 --- a/pkg/mount/operation.go +++ b/pkg/mount/operation.go @@ -18,11 +18,11 @@ type mountOperation struct { func (m mountOperation) run() error { // Add context to sublogger - l := internalUtils.Log.With().Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Strs("options", m.MountOption.Options).Logger().Level(zerolog.InfoLevel) + l := internalUtils.Log.With().Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Strs("options", m.MountOption.Options).Logger() // Not sure why this defaults to debuglevel when creating a sublogger, so make sure we set it properly debug := len(internalUtils.ReadCMDLineArg("rd.immucore.debug")) > 0 if debug { - l.Level(zerolog.DebugLevel) + l = l.Level(zerolog.DebugLevel) } if m.PrepareCallback != nil { diff --git a/pkg/mount/state.go b/pkg/mount/state.go index ab03b0d..73ee973 100644 --- a/pkg/mount/state.go +++ b/pkg/mount/state.go @@ -44,6 +44,7 @@ func (s *State) WriteFstab(fstabFile string) func(context.Context) error { } f.Close() for _, fst := range s.fstabs { + internalUtils.Log.Debug().Str("what", fst.String()).Msg("Adding line to fstab") select { case <-ctx.Done(): default: @@ -122,11 +123,11 @@ func (s *State) RunStageOp(stage string) func(context.Context) error { // MountOP creates and executes a mount operation. func (s *State) MountOP(what, where, t string, options []string, timeout time.Duration) func(context.Context) error { - l := internalUtils.Log.With().Str("what", what).Str("where", where).Str("type", t).Strs("options", options).Logger().Level(zerolog.InfoLevel) + l := internalUtils.Log.With().Str("what", what).Str("where", where).Str("type", t).Strs("options", options).Logger() // Not sure why this defaults to debuglevel when creating a sublogger, so make sure we set it properly debug := len(internalUtils.ReadCMDLineArg("rd.immucore.debug")) > 0 if debug { - l.Level(zerolog.DebugLevel) + l = l.Level(zerolog.DebugLevel) } return func(c context.Context) error { @@ -165,8 +166,12 @@ func (s *State) MountOP(what, where, t string, options []string, timeout time.Du err = op.run() - if err == nil { - s.fstabs = append(s.fstabs, tmpFstab) + // If no error on mounting or error is already mounted, as that affects the sysroot + // for some reason it reports that its already mounted (systemd is mounting it behind our back!). + if err == nil || err != nil && errors.Is(err, constants.ErrAlreadyMounted) { + s.AddToFstab(tmpFstab) + } else { + l.Debug().Err(err).Msg("Mount not added to fstab") } // only continue the loop if it's an error and not an already mounted error @@ -231,3 +236,18 @@ func (s *State) LogIfErrorAndPanic(e error, msgContext string) { internalUtils.Log.Fatal().Msg(e.Error()) } } + +// AddToFstab will try to add an entry to the fstab list +// Will check if the entry exists before adding it to avoid duplicates. +func (s *State) AddToFstab(tmpFstab *fstab.Mount) { + found := false + for _, f := range s.fstabs { + if f.Spec == tmpFstab.Spec { + internalUtils.Log.Debug().Interface("existing", f).Interface("duplicated", tmpFstab).Msg("Duplicated fstab entry found, not adding") + found = true + } + } + if !found { + s.fstabs = append(s.fstabs, tmpFstab) + } +}