Friday, March 22, 2013

gentoo/xen awesomeness

...or the possibilities of linux as an gaming platform...



+Gentoo +Linux is incredible, really! :D

Recently i've made an blogpost about gaming via xen. I showed a picture playing 2 games at the same time. One game on Windows, one game on Linux over 3 screens.
Since there are not that much games which supports multimonitor on linux - at least not correctly, i've searched for other games and came across +0 A.D. which is an strategy game like Age of Empires.
While it's still in alpha state, it's already really good playable. However, most importantly it supports multi monitors really well.
Today i'm going to show a video about this setup...


Setup:

So, what is showed in this video. The host system is - surprise, surprise -  Gentoo unstable 64bit with an xen enabled kernel-3.8. The Guest system is Windows 7. On Linux runs KDE 4.10.1 on VT7, awesome on VT8 (where i'll gonna start 0 A.D.) and on VT11 is running cmus - my favorite music player. That's actually nothing really new, really new is: Synergy!

Caution: Playing over 3 screens isn't bug-free at all! Especially when having different resolutions.
For example, the left and the right screen are cut at the bottom (see above). While that doesn't make much difference in playing 0 A.D., i couldn't actually start a game because the "Start game" button is in the bottom right. (but i could load a game) While this seems to be a hardware limitation (looks like i need two other 30" screens ;) ), two other games which i've tried (Amensia and Defcon) suffers form a bug where i can't move the mouse beyond not even the half of the screen (i can move it from the left side to about 30% of the middle screen). However this might be already fixed with recent mesa-9.1 since this works in 0 A.D. while +Steam games running with old emul mesa-9.0.1 libs.


Synergy:

On my first post about xen i'll got an comment from a user who ask me if i ever tried synergy on my setup to fix my input "problem". Until now my usual solution was an usb-switcher, where i could switch my input devices (keyboard & mouse) between my host and guest system. This actually worked - but never that good. The reason i'll never tried out synergy was because i was quite convenient with my actual solution and i always thought with synergy i have an much worse input lag - well, i was wrong.
Recently i've tested synergy and i was quite impressed. There is nearly no input lag and i think it fits perfectly well for causal gamers like me.
However, there are few settings to made, otherwise games wouldn't be playable with synergy.


How synergy works:

Synergy is a software which shares input's from one system (input server) on multiple other system's (input clients). The really good thing is, it's available on linux, windows and mac and it's even open source. First i've installed synergy on the system where the input (keyboard and mouse) is directly connected and set it up as the synergy server. All the other system's which should be accessible over synergy are client's. On my computer it would mean my host system (linux) would be the server while my guest system (windows) would be a client which tries to connect to the server directly after boot up.


Setting up synergy:

1.) Start the synergy server on the host and click on "Server Configuration". Set up an new client which should have access to the host. In my case i've put the client above the host, so that if i cross the top border of my host, my mouse appears in the guest system.

2.) Change the setting "Use relative mouse moves" in the "Advanced server settings" tab. This is important. While the mouse would work in windows without problems, in games you couldn't play anything. I don't know what exactly happens, but it looks like the mouse speed is incredible increased.

3.) I also made an keyboard shortcut which toggles switching between the systems. That's also important, because that keeps the mouse on the actual system (you don't want to switch accidently to linux while your gaming).

4.) Start the server.
5.) Install synergy on the client, add the server ip-address and click start. Synergy should immediately connect to the server. Now you should be able to use mouse & keyboard from the host system. Also check the option to start synergy directly after boot so that you don't have to start it every time..


The video:

For those who are interested, latest synergy is also in portage (even stable) and the windows version can be downloaded on their website. Below is now the video showing all the stuff whats possible :D


Thursday, March 21, 2013

qemu control script


Since i've played with +QEMU i always searched for an easy way to create or modify my guest. Start or stopping them was easy with my init script, but creating new one always involved many steps. Even though it isn't complicated i wanted something simpler.


So i've started to write an new script and called it qemu control or simple qc. Over the time it got more and more features and now i though maybe someone else could be interested, especially in case someone uses my init script.
In the last days i've cleaned up the init script to make it more readable. Now it shouldn't be to difficult to get into the code, however i'll gonna show how it's used.



Usage:

First of all, what can you do with it? Since my vm's are all on lvm partitions, qc works only with lvm partitions. It can create new vm's, copy exiting one, delete, modify configs, convert to qcow2 and compress vm's. More on every single feature below.
For every new guest it also creates default init scripts (based on my own one), while it also removes it when deleting a vm.
Everything (except deleting) can be done even when a vm is running, because the script always creates snapshots of the given vm.


Features:

 ./qc copy  
Copies an exiting vm (even when running) including their init script config, but changes its setting to suit the new vm. It also changes the vm host name (if possible) to the given name.

 ./qc new  
Creates an new empty lvm partition for an vm, including an changed default config which suit the vm. This doesn't install the guest os.

 ./qc edit   
Edit an exiting configuration file (based on my own init script) of an qemu guest.

 ./qc del  
Deletes a vm, including their init script config.

 ./qc convert [path]  
Converts a exiting lvm partition to a qcow2 file. It's also possible to directly compress it afterwards. You can also add an default path.

 ./qc compress [path]  
Only compresses a lvm partition into a gz file (like for backups). You can also add an default path.

Default init script and config can be set in the script. Also things like default logical volume name, snapshot size and image size can be set in the script. Logical volume name and path must be set anyway.

Note: I'm usually using pigz to compress the vms since it's much faster on multicore systems. If you don't have it you can either change it to gzip or simple install pigz (its in portage).


Download:

The script is a work in progress and it's probably still in a bad shape, however for those who are interested, you can download the script on github. The link is: https://github.com/mm1ke/qc

Wednesday, March 6, 2013

keeping alix devices up-to-date


Over one and a half year passed by since i last mentioned my alix device. However, it's still working as it should and i'm really happy with it. Today i'm showing you how i've managed to update my alix. Updating on the device directly would work, but it would take ages for packages like gcc and it also reduce the lifetime of a compact flash card drastically.


Right now i'm using +QEMU for upgrading my alix. A complete copy of the system is running in virtual machine  It's not directly started in the virtual machine but it's booting up a live-cd. When it's up i just have to mount the file system and make a chroot. It's really simple and compiles much faster.
When the update process is finish i only have to copy the image back to the compact flash card, usually done with dd.

Qemu settings for the alix image:
 /usr/bin/qemu-system-x86_64 -name img_name -runas kvm \  
 -monitor unix:/var/run/kvm/img_name.sock,server,nowait \  
 -pidfile /var/run/kvm/img_name.pid -m 2048 -smp 2 -daemonize \  
 -device virtio-serial -chardev spicevmc,id=vdagent,name=vdagent \  
 -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \  
 -drive file=/dev/vms/img_name,if=ide,cache=none,aio=threads \  
 -netdev type=tap,id=img_name_2,vhost=on,ifname=qtap2,script=no,downscript=no \  
 -device rtl8139,netdev=img_name_2,mac=DE:AD:CA:5E:DC:A7 \  
 -spice port=5802,addr=192.168.2.60,password="",disable-ticketing -k de \  
 -cpu host -vga qxl -cdrom /mnt/data/data/isolinks/gentoo_x86 -boot d  

A side effect of this update process is that i have to keep to two configuration in sync, because usually changes are made on the life system. If i wouldn't make those changes in the guest system too, i would lost them so i've wrote an script which syncs all configurations from the live system to the guest system.

More specifically it doesn't sync directly from the live system. On the alix device is a backup script which copies daily "/etc" to my server (where also the vm runs). I'll pass the backup file to my script which copies given configurations directly from the backup file to the guest vm's filesystem.

This saves my a lot of time because i only have to care about one system. For those who are interested in this script, i've uploaded it here: Link

Friday, March 1, 2013

gentoo/xen gaming part three

xl info

Continue on experimenting with xen i though about to share my latest experiences. Right now i'm on kernel 3.8 which brings clearly some improvements over last versions. Especially shutting down windows 7 seems to be faster then before. I'm also using the official +Gentoo xen-4.2.1 ebuilds now.





Udev:
Finally i could solve my udev problem.
However it wasn't really a problem with udev nor with xen. Basically the problem was that i didn't load the tap module before starting the vm. Xen aborted the start because it couldn't create a tap device (for the network). It seems that in earlier version of udev some configurations files caused the load of the module.
However, adding the tap module to /etc/conf.d/modules did solve the problem:

/etc/conf.d/modules:
 modules="nfs tun"  

Boot parameters:
Since my last posts i also got some feedback from other users.
Sandy McArthur showed me a typo in the boot parameters at my first post, which made the "pci=resource_alignmet" useless. I was surprised that xen/passthru still worked, because i though those parameters where important.
However, after fixing it, the kernel couldn't boot anymore and hang at "already setup the gsi". A quick search at google didn't show up any useful information so i just removed it. You'll see my actual boot parameters below.

Sandy McArthur also told me that RIFT may need a constant mac address in order to not have to activate it every time. Anyway, i can't say it for sure since i didn't play RIFT for a long time but his objection sound logical and so i've added a fixed mac address. +Václav Hájek also pointed out that Xen even has his own OUI (Organizational Unique Identifier) from the IEEE, thus using a mac address beginning with 00:16:3e is recommended.

Fixed mac address:
 vif=['mac=00:16:3e:5e:13:37,bridge=br0,type=ioemu']  

Another bug which seems to be fixed recently was a problem where xen breaks badly if you don't set xsave=1 at the boot parameters. I still don't know what exactly "xsave" does, but it's not needed anymore.

My actual boot parameters are:
 title Gentoo Linux XEN  
 root (hd0,0)  
 kernel /boot/xen.gz dom0_mem=8192M,max:8192M iommu=1 dom0_max_vcpus=4 dom0_vcpus_pin   
 module /boot/gentoo-3.8.0 root=/dev/md3 radeon.pcie_gen2=1 softlevel=xen xen-pciback.permissive xen-pciback.hide=(01:00.0)(01:00.1)(00:12.0)(00:12.2)  

Multilib:
There is also an ongoing work to make it possible using xen with an no-multilib profile. At my initial xen post i said xen with hvm enabled needs a multilib profile. However, +Gentoo Dev's are working to remove this dependency. You can follow the progress at bug #351648.

Status:
Right now my systems are up-to-date. (~amd64)
For the moment i don't even use any git ebuilds. It's much easier to go with the usual update flow. Windows still works flawless and very snappy, using it on a nearly daily base. Actually i'm quite addicted to Borderlands 2 and L4D2 (still the windows version). Maybe someone wants to join me in a game, my steam id is: mmike.

Below you see another screenshot of my system, running Far Cry 3 in Xen and Defcon (from +Steam) on the host over all 3 screens. With the picture in picture feature of my screen you see both games running in parallel. I should also mention that Defcon runs on VT8 while kde still runs at VT7 (whitout effects) so i can easily switch between gaming and kde - video is following the next days ;)