diff --git a/pkg/machine/apple/apple.go b/pkg/machine/apple/apple.go index 93201407e9..0e81569650 100644 --- a/pkg/machine/apple/apple.go +++ b/pkg/machine/apple/apple.go @@ -8,6 +8,7 @@ import ( "fmt" "net" "os" + "os/exec" "syscall" "time" @@ -275,6 +276,42 @@ func StartGenericAppleVM(mc *vmconfigs.MachineConfig, cmdBinary string, bootload logrus.Debugf("helper command-line: %v", cmd.Args) + if mc.LibKrunHypervisor != nil && logrus.IsLevelEnabled(logrus.DebugLevel) { + rtDir, err := mc.RuntimeDir() + if err != nil { + return nil, nil, err + } + kdFile, err := rtDir.AppendToNewVMFile("krunkit-debug.sh", nil) + if err != nil { + return nil, nil, err + } + f, err := os.Create(kdFile.Path) + if err != nil { + return nil, nil, err + } + err = os.Chmod(kdFile.Path, 0744) + if err != nil { + return nil, nil, err + } + + _, err = f.WriteString("#!/bin/sh\nexec ") + if err != nil { + return nil, nil, err + } + for _, arg := range cmd.Args { + _, err = f.WriteString(fmt.Sprintf("%q ", arg)) + if err != nil { + return nil, nil, err + } + } + err = f.Close() + if err != nil { + return nil, nil, err + } + + cmd = exec.Command("/usr/bin/open", "-Wa", "Terminal", kdFile.Path) + } + if err := cmd.Start(); err != nil { return nil, nil, err } diff --git a/pkg/machine/apple/vfkit.go b/pkg/machine/apple/vfkit.go index 6369441466..301167a78d 100644 --- a/pkg/machine/apple/vfkit.go +++ b/pkg/machine/apple/vfkit.go @@ -9,6 +9,7 @@ import ( "github.com/containers/podman/v5/pkg/machine/vmconfigs" vfConfig "github.com/crc-org/vfkit/pkg/config" "github.com/crc-org/vfkit/pkg/rest" + "github.com/sirupsen/logrus" ) func GetDefaultDevices(mc *vmconfigs.MachineConfig) ([]vfConfig.VirtioDevice, *define.VMFile, error) { @@ -41,7 +42,12 @@ func GetDefaultDevices(mc *vmconfigs.MachineConfig) ([]vfConfig.VirtioDevice, *d if err != nil { return nil, nil, err } - devices = append(devices, disk, rng, serial, readyDevice) + devices = append(devices, disk, rng, readyDevice) + if mc.LibKrunHypervisor == nil || !logrus.IsLevelEnabled(logrus.DebugLevel) { + // If libkrun is the provider and we want to show the debug console, + // don't add a virtio serial device to avoid redirecting the output. + devices = append(devices, serial) + } if mc.AppleHypervisor != nil && mc.AppleHypervisor.Vfkit.Rosetta { rosetta := &vfConfig.RosettaShare{