如何使用-nographic和-monitor运行qemu但仍然可以将Ctrl + C发送给guest虚拟机并使用Ctrl + A X退出?

时间:2018-04-08 10:34:07

标签: qemu

我刚刚发现如果您使用-monitor telnet::45454,server,nowait -nographic运行QEMU,则Ctrl-C会杀死QEMU VM,而不是在来宾上生成SIGINT:How to pass Ctrl-C to the guest when running qemu with -nographic? | Unix & Linux Stack Exchange

但是,我不想删除-monitor,因为自动执行监控命令很方便,例如它允许我创建一个帮助脚本:

echo 'savevm my_snap_id' |  telnet localhost 45454

有没有办法让我的Ctrl-C-monitor-nographic合作?

完整的QEMU命令:

qemu-system-x86_64 -append 'root=/dev/vda console=ttyS0' -kernel 'bzImage' -drive file='rootfs.ext2.qcow2,if=virtio,format=qcow2' -nographic -monitor telnet::45454,server,nowait

在QEMU 2.10.1上,Ubuntu 17.10,完整的QEMU命令:

./x86_64-softmmu/qemu-system-x86_64 \
-append "root=/dev/sda console=ttyS0 nokaslr printk.time=y" \
-drive file="${dir}/out/x86_64/buildroot/images/rootfs.ext2.qcow2,format=qcow2" \
-kernel "${dir}/out/x86_64/buildroot/images/bzImage" \
-nographic \

如果我添加:

-chardev stdio,id=s1,signal=off \
-serial none -device isa-serial,chardev=s1

然后Ctrl+C根据需要开始工作,但Ctrl+A X无法退出QEMU,这有时令人讨厌:我可以telnet使用quit,但它需要更多打字/自动化。

http://lists.nongnu.org/archive/html/qemu-discuss/2018-04/msg00006.html

1 个答案:

答案 0 :(得分:4)

添加-serial mon:stdio并删除其他-serial选项

以下内容满足我的所有要求:

./x86_64-softmmu/qemu-system-x86_64 \
  -append 'root=/dev/vda nopat nokaslr norandmaps printk.devkmsg=on printk.time=y console=ttyS0' \
  -drive file="${dir}/out/x86_64/buildroot/images/rootfs.ext2.qcow2,if=virtio,format=qcow2" \
  -kernel "${dir}/out/x86_64/buildroot/images/bzImage" \
  -nographic \
  -monitor telnet::45454,server,nowait \
  -serial mon:stdio

或者aarch64:

./aarch64-softmmu/qemu-system-aarch64 \
  -M virt \
  -append 'root=/dev/vda nokaslr norandmaps printk.devkmsg=on printk.time=y' \
  -cpu cortex-a57 \
  -drive file="${dir}/out/aarch64/buildroot/images/rootfs.ext2.qcow2,if=virtio,format=qcow2" \
  -kernel "${dir}/out/aarch64/buildroot/images/Image" \
  -monitor telnet::45454,server,nowait \
  -nographic \
  -serial mon:stdio \

在QEMU上测试过9d2a09063922757ec3640d93f6b35921ab95b1c2  (后v2.12.0-rc2)。