]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds VNC support
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 1 Apr 2017 16:59:53 +0000 (13:59 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 1 Apr 2017 16:59:53 +0000 (13:59 -0300)
README.md
kvmx
kvmxfile

index 3d6a870aad344a7ce61136e6348fcae3a6ba61b6..d93b154ef9fbff12058efdd857ca8605909fbf68 100644 (file)
--- a/README.md
+++ b/README.md
@@ -46,7 +46,6 @@ If no folder is specified, the current folder is assumed as the project home.
 
 ## Further development
 
-* VNC support.
 * Alternative folder sharing support (NFS or SMB).
 * Remount 9p shared folders and reinitialize spice-vdagent upon resume from disk [see possible bug](https://bugzilla.redhat.com/show_bug.cgi?id=1333072).
 * More params (memory, cpus, ssh, serial console, additional shared folders, etc).
diff --git a/kvmx b/kvmx
index 2b410f28d297df850a2038ad4c805b814a4dc6cf..1b7c4cf7c44653559734cdfb0edd967a4bdfb544 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -97,6 +97,7 @@ function __kvmx_initialize {
   # Default parameters
   PORT="$(($RANDOM + 1024))"
   SSH="$(($PORT + 22))"
+  GUEST_DISPLAY="$(((RANDOM % 10) + 1))"
 
   # Initalize
   mkdir -p $GLOBAL_USER_CONFIG_FOLDER
@@ -138,6 +139,7 @@ function __kvmx_initialize {
     PIDFILE="$STATE_DIR/pid"
     PORTFILE="$STATE_DIR/port"
     SSHFILE="$STATE_DIR/ssh"
+    DISPLAYFILE="$STATE_DIR/display"
     SPICEFILE="$STATE_DIR/spice"
     LOGFILE="$LOG_DIR/qemu"
     SPICELOG="$LOG_DIR/spice"
@@ -258,9 +260,13 @@ function kvmx_up {
     fi
   fi
 
+  if [ -z "$graphics" ]; then
+    graphics="-vga qxl"
+  fi
+
   # Run virtual machine
   # See https://en.wikipedia.org/wiki/Nohup#Overcoming_hanging
-  nohup kvm -m 2048 -name $VM -drive file=$image,if=virtio -vga qxl $shared \
+  nohup kvm -m 2048 -name $VM -drive file=$image,if=virtio $graphics $shared \
       -spice port=$PORT,addr=127.0.0.1,disable-ticketing,streaming-video=off,jpeg-wan-compression=never,playback-compression=off,zlib-glz-wan-compression=never,image-compression=off \
       -device virtio-serial-pci \
       -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
@@ -272,9 +278,10 @@ function kvmx_up {
   PID="$!"
 
   # Save state
-  echo $PID  > $PIDFILE
-  echo $PORT > $PORTFILE
-  echo $SSH  > $SSHFILE
+  echo $PID           > $PIDFILE
+  echo $PORT          > $PORTFILE
+  echo $SSH           > $SSHFILE
+  echo $GUEST_DISPLAY > $DISPLAYFILE
 
   if [ "$run_spice_client" == "1" ]; then
     kvmx_spice
@@ -764,6 +771,26 @@ function kvmx_start {
   kvmx_up $*
 }
 
+# Connect to the guest using VNC
+function kvmx_vnc {
+  if ! kvmx_running; then
+    echo "$BASENAME: guest $VM is not running"
+    exit 1
+  fi
+
+  if [ -z "$vnc_client" ]; then
+    vnc_client="xvncviewer"
+  fi
+
+  if which $vnc_client &> /dev/null; then
+    GUEST_DISPLAY="`cat $DISPLAYFILE`"
+    $vnc_client :$GUEST_DISPLAY
+  else
+    echo "$BASENAME: no vnc_client configured"
+    exit 1
+  fi
+}
+
 # Dispatch
 if type kvmx_$ACTION 2> /dev/null | grep -q 'function'; then
   __kvmx_initialize
index 78670497f933126d5498fd503e2ff17de98c58e7..20309f416474dbf7c7b07baad2749848edff270f 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -21,6 +21,16 @@ shared_folder_mountpoint="/home/$user/code/$VM"
 # Absolute path for a provision script located inside the guest.
 #provision_command="/usr/local/share/kvmx/provision/desktop-basic"
 
+# Graphics
+# See https://wiki.archlinux.org/index.php/QEMU#Graphics
+#graphics="-vga std -nographic -vnc :$GUEST_DISPLAY"
+graphics="-vga qxl"
+
+# VNC Client
+#vnc_client="xtightvncviewer"
+#vnc_client="xvnc4viewer"
+vnc_client="xvncviewer"
+
 # Set this if you want to automatically attach an spice client when the machine
 # boots.
 run_spice_client="1"