I have a linux kernel that has the following configuration options:

CONFIG_CMDLINE="console=tty0 init=/init"

I execute Qemu with something like this:

qemu-system-x86_64 -nographic -kernel my-vmlinuz

This (correctly) shows me no output because -nographic implicitly attaches the guest ttyS0 (not tty0) to the host stdin/stdout. How can I tell Qemu to attach the guest tty0 to the host stdin/stdout?



I don't think you can. The virtual terminals (tty1 etc.) are implemented on top of the VGA text mode, which basically gives the system a memory-mapped array of characters (+ attributes). The kernel then writes to that array as it wants. File streams like stdout however, are inherently linear, so they're not entirely compatible.

What you can do, however, is to use qemu -curses to have a view into the guest's text mode VGA output; or, put console=ttyS0 in the kernel command line instead to have the guest use the serial port as console. (You may also need to configure grub to use the serial port.)

  • I'm not using any bootloader (beyond what is emulated by qemu), and I don't control the kernel command line. The -curses option looks promising, though --- assuming I can figure out how to build qemu to support it. – rubicks May 14 '18 at 16:09
  • @rubicks, ah yes, you had -kernel there. But in that case, can't QEMU set the kernel command line too? There's the -append <cmdline> switch in my qemu manual for that. But I don't know how that works together with a builtin command line (does it override or append). – ilkkachu May 14 '18 at 19:44
  • 1
    @ikkachu, CONFIG_CMDLINE_OVERRIDE=y causes the kernel to ignore any given command-line parameters. – rubicks May 14 '18 at 20:25

I believe the following will work for you:

CONFIG_CMDLINE="console=tty0 console=ttyS0,9600n8 init=/init"

This comes from tldp's remote serial console HOWTO

See also this question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.