Skip to content

Instantly share code, notes, and snippets.

@jaseg
Created August 27, 2012 10:10
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaseg/3487142 to your computer and use it in GitHub Desktop.
Save jaseg/3487142 to your computer and use it in GitHub Desktop.
Windows XP as your screensaver!

Windows XP as your screensaver!

Overview

When xscreensaver starts screen saving, instead of a boring screen saver it spawns a small shell script. This shell script starts a new X server with a very minimal awesome window manager and unfreezes a kvm virtual machine containing a Windows XP on that X server, ready to be used by any passersby. To unlock the screen, you need to switch back to the VT where your usual X is running. As soon as the screen is unlocked, xscreensaver sends a SIGTERM to the shell script which in turn stops all the X servers, window managers and virtual machines it launched and resets the VM image. Should the VM exit before the screen is unlocked because somebody pressed "Shut down" the VM image is reset and the VM restarted.

Setup

A little note of caution: This is not yet well-tested and nobody except for me had a look on it, so please do not trust it and do not blame me if some process gets loose and flips all your bits ;)

First, you need to make a qemu qcow2-image and install a Windows XP into it. Bonus points if you make it look like you are actually using that XP. Since this process is rather straightforward, I won't go into detail here. Once you have the windows inside the image, boot it and switch to the qemu monitor which you should normally be able to find by pressing ctrl-alt-shift-2. Now type savevm clean-running and hit enter, thereby saving a snapshot of the current state of the VM into the image file (be patient, it might take a few minutes). Later, instead of slowly booting, the VM is just restored from this snapshot (taking approx. 10 seconds on my little netbook). Now copy the xp-screensaver.sh script and the awesome config lua file into some folder readable by your normal user account and give the shell script some executable bits. Also, you will probably want to modify the script to suit your particular configuration. Finally add the script to your ~/.xscreensaver config file as the first entry of the programs list and set mode to one and selected to 0. Done!

Planned features and problems

  • I would like a locally hosted web page where you can look at what the VM is doing currently. This would be pretty easy to implement since libvirt has bindings for every major scripting language and allows you to take a screenshot of the VM. That screenshot just needs to be written somewhere into /var/www every few seconds et voila!
  • The network traffic of the VM seriously needs to be directed through some tunnel so it is not stamped with your name when you are in a network requiring authentication (say, at university).
  • I am not entirely sure that the awesome config does not allow anyone to run programs or modify files. I have a working but horribly unelegant fix for this which spawns the awesome under an unprivileged user account.
  • A running VM does not survive a suspend-to-ram on my setup (and for some reason does not get restarted, either).

Ways to "abuse" this

Of course, nobody requires you to spawn a Windows XP VM. You could also just kick off a guest session or start MAME.

License

"THE MATE-WARE LICENSE" (Revision 23): s@jaseg.de wrote these files. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a mate in return -- jaseg

require("awful")
require("awful.autofocus")
awful.tag.new({1},1,awful.layout.suit.max.fullscreen)
#!/bin/bash
cd $(dirname $0)
trap "echo 'QEMU: cleaning up...'; pkill -15 -P$$ '.*'; qemu-img snapshot -a clean-running winxp-screensaver.qcow2; exit" EXIT
coproc xinit /usr/bin/awesome -c xp-awesome.lua -- :1
export DISPLAY=:1
while true
do
coproc /usr/bin/qemu-kvm -smp 2 -m 1024m -chardev pty,id=ctrl -mon chardev=ctrl -usb -usbdevice tablet -hda winxp-screensaver.qcow2 -loadvm clean-running
wait $! && qemu-img snapshot -a clean-running winxp-screensaver.qcow2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment