Fix missing sysroot mount in fstab (#121)

This commit is contained in:
Itxaka
2023-05-05 12:34:23 +02:00
committed by GitHub
parent d1d05b4ddd
commit 2e9e5de03e
4 changed files with 28 additions and 9 deletions

View File

@@ -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
}

View File

@@ -90,8 +90,6 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
"suid",
"dev",
"exec",
// "auto",
//"nouser",
"async",
}, 10*time.Second),
),

View File

@@ -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 {

View File

@@ -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)
}
}