26

I seem to recall being able to start qemu with only the terminal emulator output, with the graphic window disabled. And here I don't mean with the ncurses interface, that one is nice, but I want the output to flow directly into my terminal, to make cut and paste easier.

I have tried:

qemu -nographic binary.img # simply no display
qemu -curses binary.img # nice text output, but not directly flowing in the terminal
qemu -noframe -curses binary.img # same as above
qemu -nographic -curses binary.img

I guess an acceptable workaround would be for me to be able to resize the curses console to fit the terminal I am using. Right now it's annoying because it doesn't fit the terminal size...

qemu -curses  binary.img



           SeaBIOS (version 1.7.0-20120603_194846-gandalf)



           iPXE (http://ipxe.org) 00:03.0 C900 PCI2.10 PnP PMM+07FC86A0+07F886A0 C900


           Booting from Hard Disk...
           [...]

Notice how the display is indented 12 spaces? Annoying. :)

anarcat
  • 740
  • 1
  • 9
  • 18

3 Answers3

28

Old question, but it might still interest people.

Short anwser :

qemu -nographic -serial mon:stdio -append 'console=ttyS0' binary.img

ttyS0 valid on most PC. it would be something different on ARM system.

Then the serial port and the QEMU are multiplexed on your output. You can switch between them with ctrl-A + C + ENTER.

Long answer: check this blog, it's awesome.

Arkanosis
  • 103
  • 4
FredG
  • 391
  • 3
  • 3
  • 1
    Seemed to work without serial for me. – Ciro Santilli OurBigBook.com May 21 '15 at 20:11
  • yes it seems so on latest qemu it's still interesting to learn you can also to multiplex serial + qemu console on stdio – FredG Sep 15 '15 at 09:23
  • 1
    Unfortunately this doesn't redirect any BIOS output, including int 0x10 output used by real-mode code; you only start getting output once the Linux kernel boots up enough to open the serial port. – David Given Nov 25 '16 at 19:20
  • @DavidGiven I suppose that's a matter of what the BIOS code (which is SeaBIOS, not qemu proper) actually *does* with the 0x10 "output". – DepressedDaniel Mar 22 '17 at 04:44
  • 1
    You can also add `console=ttyS0` to `GRUB_CMDLINE_LINUX_DEFAULT` in `/etc/grub` (make sure to call `update-grub` after) for it to take place automatically. – Steve Mar 29 '18 at 04:51
  • @DavidGiven haven't tested but: https://www.seabios.org/Debugging "Additionally, if a serial port is available, one may compile SeaBIOS to send the diagnostic messages to the serial port. See the SeaBIOS CONFIG_DEBUG_SERIAL option." – Ciro Santilli OurBigBook.com Jun 14 '18 at 09:47
  • doesn't work. qemu-system-x86_64: -append only allowed with -kernel option – Some Name Jun 06 '21 at 23:25
3

Install SGABIOS -- ISTR that recent Qemu versions use it automatically when run with -nographic.

sendmoreinfo
  • 1,742
  • 12
  • 33
  • oddly enough, that doesn't seem to be packaged in Debian, so I doubt this was what I was using... – anarcat Mar 07 '13 at 03:18
1

You can update GRUB to pass the required options to the kernel. I'm using Ubuntu 18.04, and I did the following:

Update grub in the guest OS:

  • sudoedit /etc/default/grub
  • Change GRUB_CMDLINE_LINUX="" to GRUB_CMDLINE_LINUX="console=tty0 console=ttyS0,9600n8"
  • run sudo update-grub

Reboot guest OS using the following:

qemu-system-x86_64 \
  -drive file=ubuntu-18.04-live-server-amd64.img.qcow2,format=qcow2 \
  -nographic \
  -m 4G \
;

I recommend adding -nic user,hostfwd=tcp:127.0.0.1:2222-:22 or similar as an option as well, this will enable ssh connectivity via ssh -p 2222 localhost which gives a slightly nicer interface than the console.

The console options are copied from tldp's remote serial HOWTO

Julian
  • 111
  • 1
  • the question wasn't really about how to configure grub, but more qemu. but i believe, as the first answer says, that `-nographic` is correct. thanks for your contirbution! :) – anarcat Nov 30 '18 at 16:40