diff --git a/docs/internal.md b/docs/internal.md index 64f43dc5a9c..1bafb3f8277 100644 --- a/docs/internal.md +++ b/docs/internal.md @@ -44,14 +44,18 @@ kernel: QEMU: - `qemu.pid`: QEMU PID - `qmp.sock`: QMP socket -- `serial.log`: QEMU serial log, for debugging -- `serial.sock`: QEMU serial socket, for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`) VZ: - `vz.pid`: VZ PID - `vz-identifier`: Unique machine identifier file for a VM - `vz-efi`: EFIVariable store file for a VM +Serial: +- `serial.log`: legacy serial log (QEMU only), for debugging +- `serial.sock`: legacy serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`) +- `serialv.log`: virtio serial log, for debugging +- `serialv.sock`: virtio serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serialv.sock`) + SSH: - `ssh.sock`: SSH control master socket - `ssh.config`: SSH config file for `ssh -F`. Not consumed by Lima itself. diff --git a/pkg/qemu/qemu.go b/pkg/qemu/qemu.go index 3e2214d4f69..e80285f8605 100644 --- a/pkg/qemu/qemu.go +++ b/pkg/qemu/qemu.go @@ -805,7 +805,7 @@ func Cmdline(cfg Config) (string, []string, error) { // Parallel args = append(args, "-parallel", "none") - // Serial + // Serial (legacy) serialSock := filepath.Join(cfg.InstanceDir, filenames.SerialSock) if err := os.RemoveAll(serialSock); err != nil { return "", nil, err @@ -818,6 +818,20 @@ func Cmdline(cfg Config) (string, []string, error) { args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog)) args = append(args, "-serial", "chardev:"+serialChardev) + // Serial (virtio) + serialvSock := filepath.Join(cfg.InstanceDir, filenames.SerialVirtioSock) + if err := os.RemoveAll(serialvSock); err != nil { + return "", nil, err + } + serialvLog := filepath.Join(cfg.InstanceDir, filenames.SerialVirtioLog) + if err := os.RemoveAll(serialvLog); err != nil { + return "", nil, err + } + const serialvChardev = "char-serial-virtio" + args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialvChardev, serialvSock, serialvLog)) + args = append(args, "-device", "virtio-serial-pci,id=virtio-serial0") + args = append(args, "-device", fmt.Sprintf("virtconsole,chardev=%s,id=console0", serialvChardev)) + // We also want to enable vsock here, but QEMU does not support vsock for macOS hosts if *y.MountType == limayaml.NINEP || *y.MountType == limayaml.VIRTIOFS { diff --git a/pkg/qemu/qemu_driver.go b/pkg/qemu/qemu_driver.go index 00867246d88..02052595605 100644 --- a/pkg/qemu/qemu_driver.go +++ b/pkg/qemu/qemu_driver.go @@ -178,7 +178,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) { }() } - logrus.Infof("Starting QEMU (hint: to watch the boot progress, see %q)", filepath.Join(qCfg.InstanceDir, filenames.SerialLog)) + logrus.Infof("Starting QEMU (hint: to watch the boot progress, see %q)", filepath.Join(qCfg.InstanceDir, "serial*.log")) logrus.Debugf("qCmd.Args: %v", qCmd.Args) if err := qCmd.Start(); err != nil { return nil, err diff --git a/pkg/store/filenames/filenames.go b/pkg/store/filenames/filenames.go index 11184ca9e18..e57d0ba9604 100644 --- a/pkg/store/filenames/filenames.go +++ b/pkg/store/filenames/filenames.go @@ -34,8 +34,10 @@ const ( KernelCmdline = "kernel.cmdline" Initrd = "initrd" QMPSock = "qmp.sock" - SerialLog = "serial.log" + SerialLog = "serial.log" // legacy SerialSock = "serial.sock" + SerialVirtioLog = "serialv.log" // virtio serial + SerialVirtioSock = "serialv.sock" SSHSock = "ssh.sock" SSHConfig = "ssh.config" VhostSock = "virtiofsd-%d.sock" diff --git a/pkg/vz/vm_darwin.go b/pkg/vz/vm_darwin.go index 2d08e5e5915..157e6a04599 100644 --- a/pkg/vz/vm_darwin.go +++ b/pkg/vz/vm_darwin.go @@ -234,7 +234,7 @@ func attachPlatformConfig(driver *driver.BaseDriver, vmConfig *vz.VirtualMachine } func attachSerialPort(driver *driver.BaseDriver, config *vz.VirtualMachineConfiguration) error { - path := filepath.Join(driver.Instance.Dir, filenames.SerialLog) + path := filepath.Join(driver.Instance.Dir, filenames.SerialVirtioLog) serialPortAttachment, err := vz.NewFileSerialPortAttachment(path, false) if err != nil { return err diff --git a/pkg/vz/vz_driver_darwin.go b/pkg/vz/vz_driver_darwin.go index 38ea6398ff4..843e4163ba7 100644 --- a/pkg/vz/vz_driver_darwin.go +++ b/pkg/vz/vz_driver_darwin.go @@ -14,7 +14,6 @@ import ( "github.com/Code-Hex/vz/v3" - "github.com/lima-vm/lima/pkg/store/filenames" "github.com/sirupsen/logrus" "github.com/lima-vm/lima/pkg/driver" @@ -132,7 +131,7 @@ func (l *LimaVzDriver) CreateDisk() error { } func (l *LimaVzDriver) Start(ctx context.Context) (chan error, error) { - logrus.Infof("Starting VZ (hint: to watch the boot progress, see %q)", filepath.Join(l.Instance.Dir, filenames.SerialLog)) + logrus.Infof("Starting VZ (hint: to watch the boot progress, see %q)", filepath.Join(l.Instance.Dir, "serial*.log")) vm, errCh, err := startVM(ctx, l.BaseDriver) if err != nil { if errors.Is(err, vz.ErrUnsupportedOSVersion) {