Skip to content

Instantly share code, notes, and snippets.

@saikocat
Last active January 4, 2021 10:27
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save saikocat/212a277a4733a4561f1d to your computer and use it in GitHub Desktop.
QEMU + Spice with Copy & Paste

Create a runner shell script in host -> init with:

  • 2GB RAM
  • Host CPU with 2 Cores
  • Localhost port 2222 traffic redirect to guest port 22
  • Spice display with copy and paste enabled
#!/bin/sh
SPICE_PORT=5924
SPARK_IMG=/home/hoa/spark-training.qcow2

qemu-system-x86_64 \
  -name Spark \
  -m 2048 \
  -drive file=${SPARK_IMG},if=virtio,cache=off \
  -enable-kvm -cpu host \
  -smp 2 \
  -redir tcp:2222::22 \
  -vga qxl \
  -spice port=${SPICE_PORT},addr=127.0.0.1,disable-ticketing \
  -device virtio-serial-pci \
  -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
  -chardev spicevmc,id=spicechannel0,name=vdagent \
  -monitor stdio
  # "$@"            # other args
  # -loadvm persist # load existing tag|id name 'persist'

Open up the graphical using spice client

[@host]$ spicec --title Spark -h 127.0.0.1 -p ${SPICE_PORT}

Inside guest, enable copy and paste listener

[@guest]$ sudo service spice-vdagentd start
[@guest]$ spice-vdagent

Interacting with host (default to 10.0.2.2 ip) via ssh

[@guest]$ ssh hostuser@10.0.2.2

Interacting with guest via ssh

[@host]$ ssh guessuser@localhost -p 2222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment