12

I would like to be able to both interact with the system via the command line, but also get the output to a file at the same time.

If I do:

qemu-sysem-x86_64 -serial stdio |& tee file

then it mostly works, but I would like to avoid any Bash operations and let QEMU do the heavy lifting for me. For example, I'm using Python, and it is not so simple to implement a reliable tee there.

If I do:

qemu-sysem-x86_64 -serial file:myfile

It redirects to the file and I can't give any input.

Is there a way to "combine" both file: and stdio to a single -serial?

Multiple -serial entries just create multiple serial ports instead of modifying a single one.

I'm also interested if it works with telnet as in:

-serial tcp::1234,server,nowait

http://lists.nongnu.org/archive/html/qemu-discuss/2018-11/msg00011.html

1 Answer 1

13

Recently, I ran into the exactly same problem and found a solution:

According to QEMU 3.1.0 documentation, you can use a chardev with options stdio and logfile and redirect your serial into it.

qemu-system-x86_64 -chardev stdio,id=char0,logfile=serial.log,signal=off \
  -serial chardev:char0

Moreover, if you use mux=on option within chardev, you can redirect a monitor (mon), another serial or other interfaces supporting chardev backend into it simultaneously:

qemu-system-x86_64 -chardev stdio,id=char0,mux=on,logfile=serial.log,signal=off \
  -serial chardev:char0 -mon chardev=char0

See the example in the doc. link above.

5
  • 1
    Awesome!!! Can you also provide the full CLI to do the mon setup (hopefully something analogous to -serial mon:stdio but with logging)? I also wanted that actually, but forgot to mention in question, and my initial attempts failed. Mar 7, 2019 at 15:38
  • 1
    In particular, I'd like Ctrl+C to go to guest instead of kill QEMU. Ideally mon output should not go to log file. Mar 7, 2019 at 15:44
  • The signals like Ctrl+C can be enabled or disabled with signal=on|off option within chardev. I'll provide the mon example as edit.
    – user515186
    Mar 7, 2019 at 16:53
  • Perfect! signal=off does what I wanted. Mar 7, 2019 at 20:25
  • signal=off seems to be the preferred way, will add it as edit.
    – user515186
    Apr 1, 2019 at 20:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .