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

风流意气都作罢 提交于 2019-12-31 08:46:32

问题


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 linux installed on it. But my programs need to run on Solaris. I use Nexenta Solaris for x86.

Can qemu be used to run Nexenta Solaris on that machine through terminal. I need to convince the administrator that it can, otherwise he won't install qemu on that machine and therefore allow me to use Solaris through a virtual machine. Also note that I don't use GUI with the Nexenta Solaris, just command line. In my machine, I use VMware to run it.


回答1:


You can compile qemu for youself and install it into your home directory. There will be no kernel-mode qemu accelerator, but the qemu will work and the speed will be rather high.

Qemu has two options for non-gui start: http://wiki.qemu.org/download/qemu-doc.html

Display options:

-nographic - Normally, QEMU uses SDL to display the VGA output. With this option, you can totally disable graphical output so that QEMU is a simple command line application. The emulated serial port is redirected on the console. Therefore, you can still use QEMU to debug a Linux kernel with a serial console.

-curses - Normally, QEMU uses SDL to display the VGA output. With this option, QEMU can display the VGA output when in text mode using a curses/ncurses interface. Nothing is displayed in graphical mode.

Also it can send graphic output to another machine via VNC protocol (-vnc option)




回答2:


-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

console=ttyS0 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

Tested on Ubuntu 18.04, QEMU 2.11.1.




回答3:


I've struggled this for a while and finally figured out how to get it to work for me:

You need to have SGABIOS installed. Interestingly this BIOS is not included in the debian qemu package, so you need to install it (as the superuser):

apt install sgabios  

Then when you run qemu use the -device option to tell the virtural machine to use the sga output

qemu-system-i386 -nographic -device sga discimage.bin

Voila! works perfectly over ssh with both the monitor and text output sent through stdio. You can access the qemu monitor with C-a c.

cheers, ben



来源:https://stackoverflow.com/questions/6710555/how-to-use-qemu-to-run-a-non-gui-os-on-the-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!