Implement qemu-system stderr log passthrough
This commit is contained in:
parent
9ccd820e71
commit
ec99bc4ef1
5 changed files with 11 additions and 6 deletions
|
|
@ -68,7 +68,7 @@ func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
rootCmd.AddCommand(copyrightCmd)
|
rootCmd.AddCommand(copyrightCmd)
|
||||||
|
|
||||||
rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor. You can log in with root user and no password.")
|
rootCmd.PersistentFlags().BoolVar(&vmDebugFlag, "vm-debug", false, "Enables the VM debug mode. This will open an accessible VM monitor and enable direct QEMU command log passthrough. You can log in with root user and no password.")
|
||||||
rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.")
|
rootCmd.PersistentFlags().BoolVar(&unrestrictedNetworkingFlag, "vm-unrestricted-networking", false, "Enables unrestricted networking. This will allow the VM to connect to the internet.")
|
||||||
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB. (the default is %v in LUKS mode)", defaultMemAllocLUKS))
|
rootCmd.PersistentFlags().Uint32Var(&vmMemAllocFlag, "vm-mem-alloc", defaultMemAlloc, fmt.Sprintf("Specifies the VM memory allocation in KiB. (the default is %v in LUKS mode)", defaultMemAllocLUKS))
|
||||||
rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.")
|
rootCmd.PersistentFlags().Uint32Var(&vmOSUpTimeoutFlag, "vm-os-up-timeout", 30, "Specifies the VM OS-up timeout in seconds.")
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ func runVM(passthroughArg string, fn runvm.Func, forwardPortsRules []vm.PortForw
|
||||||
OSUpTimeout: time.Duration(vmOSUpTimeoutFlag) * time.Second,
|
OSUpTimeout: time.Duration(vmOSUpTimeoutFlag) * time.Second,
|
||||||
SSHUpTimeout: time.Duration(vmSSHSetupTimeoutFlag) * time.Second,
|
SSHUpTimeout: time.Duration(vmSSHSetupTimeoutFlag) * time.Second,
|
||||||
|
|
||||||
ShowDisplay: vmDebugFlag,
|
Debug: vmDebugFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
vi, err := vm.NewVM(slog.Default().With("caller", "vm"), vmCfg)
|
vi, err := vm.NewVM(slog.Default().With("caller", "vm"), vmCfg)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ type BuildContext struct {
|
||||||
vi *vm.VM
|
vi *vm.VM
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBuildContext(logger *slog.Logger, baseISOPath string, outPath string, showVMDisplay bool, biosPath string) (*BuildContext, error) {
|
func NewBuildContext(logger *slog.Logger, baseISOPath string, outPath string, debug bool, biosPath string) (*BuildContext, error) {
|
||||||
baseISOPath = filepath.Clean(baseISOPath)
|
baseISOPath = filepath.Clean(baseISOPath)
|
||||||
outPath = filepath.Clean(outPath)
|
outPath = filepath.Clean(outPath)
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ func NewBuildContext(logger *slog.Logger, baseISOPath string, outPath string, sh
|
||||||
MemoryAlloc: 512,
|
MemoryAlloc: 512,
|
||||||
|
|
||||||
UnrestrictedNetworking: true,
|
UnrestrictedNetworking: true,
|
||||||
ShowDisplay: showVMDisplay,
|
Debug: debug,
|
||||||
InstallBaseUtilities: true,
|
InstallBaseUtilities: true,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func configureBaseVMCmd(logger *slog.Logger, cfg Config) (string, []qemucli.Arg,
|
||||||
args = append(args, biosArg)
|
args = append(args, biosArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.ShowDisplay {
|
if !cfg.Debug {
|
||||||
args = append(args, qemucli.MustNewStringArg("display", "none"))
|
args = append(args, qemucli.MustNewStringArg("display", "none"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
7
vm/vm.go
7
vm/vm.go
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
@ -99,7 +100,7 @@ type Config struct {
|
||||||
SSHUpTimeout time.Duration
|
SSHUpTimeout time.Duration
|
||||||
|
|
||||||
// Mostly debug-related options.
|
// Mostly debug-related options.
|
||||||
ShowDisplay bool
|
Debug bool // This will show the display and forward all QEMU warnings/errors to stderr.
|
||||||
InstallBaseUtilities bool
|
InstallBaseUtilities bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -176,6 +177,10 @@ func NewVM(logger *slog.Logger, cfg Config) (*VM, error) {
|
||||||
stderrBuf := bytes.NewBuffer(nil)
|
stderrBuf := bytes.NewBuffer(nil)
|
||||||
cmd.Stderr = stderrBuf
|
cmd.Stderr = stderrBuf
|
||||||
|
|
||||||
|
if cfg.Debug {
|
||||||
|
cmd.Stderr = io.MultiWriter(cmd.Stderr, os.Stderr)
|
||||||
|
}
|
||||||
|
|
||||||
// This function is OS-specific.
|
// This function is OS-specific.
|
||||||
osspecifics.SetNewProcessGroupCmd(cmd)
|
osspecifics.SetNewProcessGroupCmd(cmd)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue