Skip to content

Commit 5a35044

Browse files
authored
Merge pull request #1674 from AkihiroSuda/virtio-serial
qemu, vz: connect virtio serial to `serialv.log`
2 parents 61ca384 + 3ea75bf commit 5a35044

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

docs/internal.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ kernel:
4444
QEMU:
4545
- `qemu.pid`: QEMU PID
4646
- `qmp.sock`: QMP socket
47-
- `serial.log`: QEMU serial log, for debugging
48-
- `serial.sock`: QEMU serial socket, for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)
4947

5048
VZ:
5149
- `vz.pid`: VZ PID
5250
- `vz-identifier`: Unique machine identifier file for a VM
5351
- `vz-efi`: EFIVariable store file for a VM
5452

53+
Serial:
54+
- `serial.log`: legacy serial log (QEMU only), for debugging
55+
- `serial.sock`: legacy serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serial.sock`)
56+
- `serialv.log`: virtio serial log, for debugging
57+
- `serialv.sock`: virtio serial socket (QEMU only), for debugging (Usage: `socat -,echo=0,icanon=0 unix-connect:serialv.sock`)
58+
5559
SSH:
5660
- `ssh.sock`: SSH control master socket
5761
- `ssh.config`: SSH config file for `ssh -F`. Not consumed by Lima itself.

pkg/qemu/qemu.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ func Cmdline(cfg Config) (string, []string, error) {
805805
// Parallel
806806
args = append(args, "-parallel", "none")
807807

808-
// Serial
808+
// Serial (legacy)
809809
serialSock := filepath.Join(cfg.InstanceDir, filenames.SerialSock)
810810
if err := os.RemoveAll(serialSock); err != nil {
811811
return "", nil, err
@@ -818,6 +818,20 @@ func Cmdline(cfg Config) (string, []string, error) {
818818
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialChardev, serialSock, serialLog))
819819
args = append(args, "-serial", "chardev:"+serialChardev)
820820

821+
// Serial (virtio)
822+
serialvSock := filepath.Join(cfg.InstanceDir, filenames.SerialVirtioSock)
823+
if err := os.RemoveAll(serialvSock); err != nil {
824+
return "", nil, err
825+
}
826+
serialvLog := filepath.Join(cfg.InstanceDir, filenames.SerialVirtioLog)
827+
if err := os.RemoveAll(serialvLog); err != nil {
828+
return "", nil, err
829+
}
830+
const serialvChardev = "char-serial-virtio"
831+
args = append(args, "-chardev", fmt.Sprintf("socket,id=%s,path=%s,server=on,wait=off,logfile=%s", serialvChardev, serialvSock, serialvLog))
832+
args = append(args, "-device", "virtio-serial-pci,id=virtio-serial0")
833+
args = append(args, "-device", fmt.Sprintf("virtconsole,chardev=%s,id=console0", serialvChardev))
834+
821835
// We also want to enable vsock here, but QEMU does not support vsock for macOS hosts
822836

823837
if *y.MountType == limayaml.NINEP || *y.MountType == limayaml.VIRTIOFS {

pkg/qemu/qemu_driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
178178
}()
179179
}
180180

181-
logrus.Infof("Starting QEMU (hint: to watch the boot progress, see %q)", filepath.Join(qCfg.InstanceDir, filenames.SerialLog))
181+
logrus.Infof("Starting QEMU (hint: to watch the boot progress, see %q)", filepath.Join(qCfg.InstanceDir, "serial*.log"))
182182
logrus.Debugf("qCmd.Args: %v", qCmd.Args)
183183
if err := qCmd.Start(); err != nil {
184184
return nil, err

pkg/store/filenames/filenames.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ const (
3434
KernelCmdline = "kernel.cmdline"
3535
Initrd = "initrd"
3636
QMPSock = "qmp.sock"
37-
SerialLog = "serial.log"
37+
SerialLog = "serial.log" // legacy
3838
SerialSock = "serial.sock"
39+
SerialVirtioLog = "serialv.log" // virtio serial
40+
SerialVirtioSock = "serialv.sock"
3941
SSHSock = "ssh.sock"
4042
SSHConfig = "ssh.config"
4143
VhostSock = "virtiofsd-%d.sock"

pkg/vz/vm_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func attachPlatformConfig(driver *driver.BaseDriver, vmConfig *vz.VirtualMachine
234234
}
235235

236236
func attachSerialPort(driver *driver.BaseDriver, config *vz.VirtualMachineConfiguration) error {
237-
path := filepath.Join(driver.Instance.Dir, filenames.SerialLog)
237+
path := filepath.Join(driver.Instance.Dir, filenames.SerialVirtioLog)
238238
serialPortAttachment, err := vz.NewFileSerialPortAttachment(path, false)
239239
if err != nil {
240240
return err

pkg/vz/vz_driver_darwin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"github.com/Code-Hex/vz/v3"
1616

17-
"github.com/lima-vm/lima/pkg/store/filenames"
1817
"github.com/sirupsen/logrus"
1918

2019
"github.com/lima-vm/lima/pkg/driver"
@@ -132,7 +131,7 @@ func (l *LimaVzDriver) CreateDisk() error {
132131
}
133132

134133
func (l *LimaVzDriver) Start(ctx context.Context) (chan error, error) {
135-
logrus.Infof("Starting VZ (hint: to watch the boot progress, see %q)", filepath.Join(l.Instance.Dir, filenames.SerialLog))
134+
logrus.Infof("Starting VZ (hint: to watch the boot progress, see %q)", filepath.Join(l.Instance.Dir, "serial*.log"))
136135
vm, errCh, err := startVM(ctx, l.BaseDriver)
137136
if err != nil {
138137
if errors.Is(err, vz.ErrUnsupportedOSVersion) {

0 commit comments

Comments
 (0)