mirror of
https://github.com/containers/podman.git
synced 2025-07-02 00:30:00 +08:00
Enable libkrun provider to open a debug console
When running with "log-level=debug" and libkrun as machine provider, spawn a Terminal to execute "krunkit" to enable users to have full access to the VMs console for debugging purposes. Users obtain an interactive, text console with scrollback. It's possible to interact with both the kernel and GRUB2. To obtain even additional debugging information, users can add "console=hvc0" to the linux kernel command line through GRUB2 (it may be worth considering extending the initial configuration of the VM to add that argument by default). Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:

committed by
Sergio López

parent
0e57573d1e
commit
550cb07fc0
@ -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
|
||||
}
|
||||
|
@ -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{
|
||||
|
Reference in New Issue
Block a user