Skip to content

Instantly share code, notes, and snippets.

@jaseg
Created August 27, 2012 10:10
Show Gist options
  • Select an option

  • Save jaseg/3487142 to your computer and use it in GitHub Desktop.

Select an option

Save jaseg/3487142 to your computer and use it in GitHub Desktop.

Revisions

  1. jaseg revised this gist Aug 27, 2012. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,11 @@ Planned features and problems

    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.
    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):
    <[email protected]> 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
  2. jaseg revised this gist Aug 27, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -23,4 +23,4 @@ Planned features and problems

    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.
    Of course, nobody requires you to spawn a Windows XP VM. You could also just kick off a guest session or start MAME.
  3. jaseg created this gist Aug 27, 2012.
    26 changes: 26 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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.
    3 changes: 3 additions & 0 deletions xp-awesome.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    require("awful")
    require("awful.autofocus")
    awful.tag.new({1},1,awful.layout.suit.max.fullscreen)
    10 changes: 10 additions & 0 deletions xp-screensaver.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #!/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