diff --git a/internal/utils/common.go b/internal/utils/common.go index 47cb2d9..c9a49d8 100644 --- a/internal/utils/common.go +++ b/internal/utils/common.go @@ -1,6 +1,7 @@ package utils import ( + "fmt" "github.com/joho/godotenv" "github.com/kairos-io/kairos/sdk/state" "os" @@ -130,12 +131,14 @@ func DisableImmucore() bool { cmdline, _ := os.ReadFile("/proc/cmdline") cmdlineS := string(cmdline) - return strings.Contains(cmdlineS, "live:LABEL") || strings.Contains(cmdlineS, "live:CDLABEL") || strings.Contains(cmdlineS, "netboot") || strings.Contains(cmdlineS, "rd.cos.disable") + return strings.Contains(cmdlineS, "live:LABEL") || strings.Contains(cmdlineS, "live:CDLABEL") || + strings.Contains(cmdlineS, "netboot") || strings.Contains(cmdlineS, "rd.cos.disable") || + strings.Contains(cmdlineS, "rd.immucore.disable") } // RootRW tells us if the mode to mount root func RootRW() string { - if len(ReadCMDLineArg("rd.cos.debugrw")) > 0 { + if len(ReadCMDLineArg("rd.cos.debugrw")) > 0 || len(ReadCMDLineArg("rd.immucore.debugrw")) > 0 { Log.Warn().Msg("Mounting root as RW") return "rw" } @@ -172,8 +175,16 @@ func IsUKI() bool { func CommandWithPath(c string) (string, error) { cmd := exec.Command("/bin/sh", "-c", c) cmd.Env = os.Environ() - // TODO: extract PATH from env and append to existing instead of overwriting - cmd.Env = append(cmd.Env, "PATH=/usr/bin:/usr/sbin") + pathAppend := "/usr/bin:/usr/sbin:/bin:/sbin" + // try to extract any existing path from the environment + for _, env := range cmd.Env { + splitted := strings.Split(env, "=") + if splitted[0] == "PATH" { + pathAppend = fmt.Sprintf("%s:%s", pathAppend, splitted[1]) + } + } + Log.Debug().Str("content", pathAppend).Msg("PATH") + cmd.Env = append(cmd.Env, fmt.Sprintf("PATH=%s", pathAppend)) o, err := cmd.CombinedOutput() return string(o), err } diff --git a/internal/utils/mounts.go b/internal/utils/mounts.go index ea66f16..df78418 100644 --- a/internal/utils/mounts.go +++ b/internal/utils/mounts.go @@ -172,32 +172,13 @@ func Fsck(device string) error { return e } -// MinimalMounts will set the minimal mounts needed for immucore -// For now only proc is needed to read the cmdline fully in uki mode -// in normal modes this should already be done by the initramfs process, so we can ignore errors -// Just mount dev, tmp and sys just in case -func MinimalMounts() { - type m struct { - source string - target string - t string - flags int - data string - } - toMount := []m{ - {"dev", "/dev", "devtmpfs", syscall.MS_NOSUID, "mode=755"}, - {"proc", "/proc", "proc", syscall.MS_NOSUID | syscall.MS_NODEV | syscall.MS_NOEXEC | syscall.MS_RELATIME, ""}, - {"sys", "/sys", "sysfs", syscall.MS_NOSUID | syscall.MS_NODEV | syscall.MS_NOEXEC | syscall.MS_RELATIME, ""}, - {"tmp", "/tmp", "tmpfs", syscall.MS_NOSUID | syscall.MS_NODEV, ""}, - {"run", "/run", "tmpfs", syscall.MS_NOSUID | syscall.MS_NODEV | syscall.MS_NOEXEC | syscall.MS_RELATIME, "mode=755"}, - } - for _, mnt := range toMount { - _ = os.MkdirAll(mnt.target, 0755) - if !IsMounted(mnt.target) { - err := syscall.Mount(mnt.source, mnt.target, mnt.t, uintptr(mnt.flags), mnt.data) - if err != nil { - fmt.Println(err.Error()) - } - } +// MountProc will mount /proc +// For now proc is needed to read the cmdline fully in uki mode +// in normal modes this should already be done by the initramfs process, so we can skip this +func MountProc() { + _ = os.MkdirAll("/proc", 0755) + if !IsMounted("/proc") { + _ = syscall.Mount("proc", "/proc", "proc", syscall.MS_NOSUID|syscall.MS_NODEV|syscall.MS_NOEXEC|syscall.MS_RELATIME, "") } + } diff --git a/main.go b/main.go index c8f028c..db2a3fb 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ func main() { var targetDevice, targetImage string var state *mount.State - utils.MinimalMounts() + utils.MountProc() utils.SetLogger() v := version.Get() @@ -42,7 +42,7 @@ func main() { } if utils.DisableImmucore() { - utils.Log.Info().Msg("Stanza rd.cos.disable on the cmdline or booting from CDROM/Netboot/Squash recovery. Disabling immucore.") + utils.Log.Info().Msg("Stanza rd.cos.disable/rd.immucore.disable on the cmdline or booting from CDROM/Netboot/Squash recovery. Disabling immucore.") err = state.RegisterLiveMedia(g) } else if utils.IsUKI() { utils.Log.Info().Msg("UKI booting!")