mirror of
https://github.com/kairos-io/immucore.git
synced 2025-09-25 05:15:51 +00:00
Add fsck before mounting (#56)
Respect all options from systemd-fsck as that it what is currently used on kairos. Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
@@ -119,3 +119,53 @@ func CleanSysrootForFstab(path string) string {
|
|||||||
}
|
}
|
||||||
return cleaned
|
return cleaned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fsck will run fsck over the device
|
||||||
|
// options are set on cmdline, but they are for systemd-fsck,
|
||||||
|
// so we need to interpret ourselves
|
||||||
|
func Fsck(device string) error {
|
||||||
|
if device == "tmpfs" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mode := ReadCMDLineArg("fsck.mode=")
|
||||||
|
repair := ReadCMDLineArg("fsck.repair=")
|
||||||
|
// Be safe with defaults
|
||||||
|
if len(mode) == 0 {
|
||||||
|
mode = []string{"auto"}
|
||||||
|
}
|
||||||
|
if len(repair) == 0 {
|
||||||
|
repair = []string{"preen"}
|
||||||
|
}
|
||||||
|
args := []string{"fsck", device}
|
||||||
|
// Check the mode
|
||||||
|
// skip means just skip the fsck
|
||||||
|
// force means force even if fs is deemed clean
|
||||||
|
// auto or others means normal fsck call
|
||||||
|
switch mode[0] {
|
||||||
|
case "skip":
|
||||||
|
return nil
|
||||||
|
case "force":
|
||||||
|
args = append(args, "-f")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check repair type
|
||||||
|
// preen means try to fix automatically
|
||||||
|
// yes means say yes to everything (potentially destructive)
|
||||||
|
// no means say no to everything
|
||||||
|
switch repair[0] {
|
||||||
|
case "preen":
|
||||||
|
args = append(args, "-a")
|
||||||
|
case "yes":
|
||||||
|
args = append(args, "-y")
|
||||||
|
case "no":
|
||||||
|
args = append(args, "-n")
|
||||||
|
}
|
||||||
|
cmd := strings.Join(args, " ")
|
||||||
|
log.Logger.Debug().Str("cmd", cmd).Msg("fsck command")
|
||||||
|
out, e := utils.SH(cmd)
|
||||||
|
log.Logger.Debug().Str("output", out).Msg("fsck output")
|
||||||
|
if e != nil {
|
||||||
|
log.Logger.Warn().Str("error", e.Error()).Str("what", device).Msg("fsck")
|
||||||
|
}
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
@@ -56,7 +56,7 @@ func (s *State) MountRootDagStep(g *herd.Graph) error {
|
|||||||
log.Logger.Debug().Str("targetImage", s.TargetImage).Str("path", s.Rootdir).Str("TargetDevice", s.TargetDevice).Msg("Not mounting loop, already mounted")
|
log.Logger.Debug().Str("targetImage", s.TargetImage).Str("path", s.Rootdir).Str("TargetDevice", s.TargetDevice).Msg("Not mounting loop, already mounted")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// TODO: squashfs recovery image?
|
_ = internalUtils.Fsck(s.path("/run/initramfs/cos-state", s.TargetImage))
|
||||||
cmd := fmt.Sprintf("losetup --show -f %s", s.path("/run/initramfs/cos-state", s.TargetImage))
|
cmd := fmt.Sprintf("losetup --show -f %s", s.path("/run/initramfs/cos-state", s.TargetImage))
|
||||||
_, err := utils.SH(cmd)
|
_, err := utils.SH(cmd)
|
||||||
s.LogIfError(err, "losetup")
|
s.LogIfError(err, "losetup")
|
||||||
|
@@ -116,6 +116,10 @@ func (s *State) MountOP(what, where, t string, options []string, timeout time.Du
|
|||||||
MountOption: mountPoint,
|
MountOption: mountPoint,
|
||||||
FstabEntry: *tmpFstab,
|
FstabEntry: *tmpFstab,
|
||||||
Target: where,
|
Target: where,
|
||||||
|
PrepareCallback: func() error {
|
||||||
|
_ = internalUtils.Fsck(what)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
err = op.run()
|
err = op.run()
|
||||||
|
Reference in New Issue
Block a user