diff --git a/internal/cmd/commands.go b/internal/cmd/commands.go index d8acec8..ef45ff3 100644 --- a/internal/cmd/commands.go +++ b/internal/cmd/commands.go @@ -31,13 +31,16 @@ Sends a generic event payload with the configuration found in the scanned direct }, Action: func(c *cli.Context) (err error) { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Logger() + img := utils.ReadCMDLineArg("cos-img/filename=") + log.Debug().Strs("TargetImage", img).Msg("Target image") g := herd.DAG() s := &mount.State{ Logger: log.Logger, Rootdir: utils.GetRootDir(), MountRoot: true, TargetLabel: utils.BootStateToLabel(), - TargetImage: utils.BootStateToImage(), + TargetImage: img[0], + IsRecovery: utils.IsRecovery(), } err = s.Register(g) diff --git a/internal/utils/common.go b/internal/utils/common.go index b9a98ed..d06cd03 100644 --- a/internal/utils/common.go +++ b/internal/utils/common.go @@ -32,20 +32,16 @@ func BootStateToLabel() string { } } -func BootStateToImage() string { +func IsRecovery() bool { runtime, err := state.NewRuntime() if err != nil { - return "" + return false } switch runtime.BootState { - case "active_boot": - return "/cOS/active.img" - case "passive_boot": - return "/cOS/passive.img" case "recovery_boot": - return "/cOS/recovery.img" + return true default: - return "" + return false } } diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 665d273..4a63fa7 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -35,7 +35,8 @@ type State struct { StateDir string // e.g. "/usr/local/.state" MountRoot bool // e.g. if true, it tries to find the image to loopback mount - fstabs []*fstab.Mount + fstabs []*fstab.Mount + IsRecovery bool // if its recovery it needs different stuff } const ( @@ -235,7 +236,7 @@ func (s *State) Register(g *herd.Graph) error { stateName := runtime.State.Name stateFs := runtime.State.Type // Recovery is a different partition - if s.TargetLabel == "COS_RECOVERY" { + if s.IsRecovery { stateName = runtime.Recovery.Name stateFs = runtime.Recovery.Type } @@ -282,7 +283,7 @@ func (s *State) Register(g *herd.Graph) error { // depending on /run/cos-layout.env // This is building the mountRoot dependendency if it was enabled - mountRootCondition := herd.ConditionalOption(func() bool { return s.MountRoot }, herd.WithDeps(opMountRoot)) + mountRootCondition := herd.ConditionalOption(func() bool { return s.MountRoot && !s.IsRecovery }, herd.WithDeps(opMountRoot)) s.Logger.Debug().Bool("mountRootCondition", s.MountRoot).Msg("condition") // TODO: this needs to be run after sysroot so we can link to /sysroot/system/oem and after /oem mounted @@ -369,7 +370,7 @@ func (s *State) Register(g *herd.Graph) error { } } - overlayCondition := herd.ConditionalOption(func() bool { return rootFSType(s.Rootdir) != "overlay" }, herd.WithDeps(opMountBaseOverlay)) + overlayCondition := herd.ConditionalOption(func() bool { return rootFSType(s.Rootdir) != "overlay" && !s.IsRecovery }, herd.WithDeps(opMountBaseOverlay)) s.Logger.Debug().Bool("overlaycondition", rootFSType(s.Rootdir) != "overlay").Msg("condition") // TODO: Add fsck // mount overlay