How to use qemu to run a non-gui OS on the terminal?

后端 未结 4 1758
傲寒
傲寒 2021-01-30 17:31

I want to run some programs on the High Performance Computer (With 8-core processor) in my department. Now I use that machine with ssh using terminal. The machine has Red Hat li

4条回答
  •  悲哀的现实
    2021-01-30 18:08

    Linux: -append 'console=ttyS0'

    That option was also needed for Linux kernel be besides -nographic mentioned by osgx as in:

    qemu-system-x86_64 -append 'console=ttyS0' \
                       -initrd rootfs.cpio.gz \
                       -kernel bzImage \
                       -nographic \
                       -serial mon:stdio \
                       
    

    Now you can do the following:

    • Ctrl + A X: exit qemu, see: https://superuser.com/questions/1087859/how-to-quit-the-qemu-monitor-when-not-using-a-gui
    • Ctrl + C: gets passed to the guest

    -append 'console=ttyS0' makes QEMU pass the console=ttyS0 kernel command line option to LInux, which tells the kernel to use a serial port instead of the display. The serial port sends characters between host and guest, instead of pixels on a display, and then QEMU can display those characters on the terminal.

    -serial mon:stdio is optional in this minimal command, but it is generally a good idea to have around. E.g., it improves behaviour if you also want to add a handy -monitor telnet later on:

    • How to run qemu with -nographic and -monitor but still be able to send Ctrl+C to the guest and quit with Ctrl+A X?
    • https://unix.stackexchange.com/questions/167165/how-to-pass-ctrl-c-to-the-guest-when-running-qemu-with-nographic

    This can be easily tested with Buildroot qemu_x86_64_defconfig. I've created this is a highly self-contained and automated setup that allows you to try this out easily

    Related but with less OS constraints:

    • redirect QEMU window output to terminal running qemu
    • Redirect Qemu console to a file or the host terminal?

    Tested on Ubuntu 18.04, QEMU 2.11.1.

    FreeBSD

    How to boot FreeBSD image under Qemu

提交回复
热议问题