MediaPC in a Xen Virtual Machine

The aim of this project was to get my MediaPC running as a VM host. This would allow me to run instances alongside my MediaPC, thus giving me a platform to experiment and develop things without having to setup separate machines etc.

I decided to use Xen on Ubuntu and found the Ubuntu Xen guide very useful.

Note: I never got this working – this is just documenting what I did and how it failed.

It is also useful to understand how to manage logical volumes in linux. If you don’t know much about this then I recommend this guide on logical volumes.

Once I had got Xen up and running and created a logical volume for installing Windows 7 to I create the following configuration file for my Xen instance with VNC listening on the machine’s physical interface.

$ cat win7_32b.cfg
builder = "hvm"
name = "win7media"
memory = "1024"
vcpus = 2
vif = ['bridge=xenbr0']
#vif = ['']
disk = ['phy:/dev/mediapc/win7_32b,hda,w','file:/home/user/isos/win7_32b.iso,hdc:cdrom,r']
vnc = 1
vncconsole = 1
vncviewer = 0
vnclisten = '0.0.0.0'
boot="dc"

When setting up this instance I encountered an error regarding

error: domain 'Win7_32b' does not exist

This lead me to a stackexchange post explaining how to fix it.

With the Xen isntance up and running I was able to connected using TightVNC – but would get errors and found it very unreliable so I moved to UltraVNC and this was a lot more useful.

Once the Windows installation was complete it was time to begin experimenting with Xen’s VGA passthrough to get the image out to my TV using my video card. To get a tutorial on Xen VGA pass-through I recommend the Xen VGA passthrough secondary display tutorial/howto – note I didn’t need to build a custom kernel.

This was not really very successful – I managed to get the card detected (an ATI/HD Radeon 24xx series). But could not get past the BSOD errors I would get at boot regarding Atikmpag.sys – it looks like the driver cannot reset the PCI card because of the passthrough. However, I will detail the steps I used below.

There were some minor changes to the Xen configuration:

$ cat win7_32b.cfg
builder = "hvm"
name = "win7media"
memory = "1024"
vcpus = 2
vif = ['bridge=xenbr0']
#vif = ['']
disk = ['phy:/dev/mediapc/win7_32b,hda,w']

gfx_passthru=0
pci=['00:01.0']

vnc = 1
vncconsole = 1
vncviewer = 0
vnclisten = '0.0.0.0'
boot="c"

I add a new config to /etc/modprobe.d/ – to stop the host system binding onto the gfx card as per these instructions.


$ cat /etc/modprobe.d/xen-pciback.conf
install radeon /sbin/modprobe xen-pciback ; /sbin/modprobe --first-time --ignore-install radeon
options xen-pciback hide=(0000:00:01.0)

This results in the following output when running lspci:

01:00.0 VGA compatible controller: Advanced Micro Devices [AMD] nee ATI RV610 [Radeon HD 2400 XT] 
Subsystem: Advanced Micro Devices [AMD] nee ATI Device 0d02 
Kernel driver in use: pciback 
Kernel modules: radeon

The card now shows up when windows boots as another Display Adapter in Device Manager in windows. I couldn’t get it working either with AMD Catalyst drivers or Microsoft’s own drivers from windows update. They just resulted in BSOD.

To revert out of the BSOD state you need to boot into safe mode and remove the drivers from the system. The other option is to use LVM snapshots (as detailed in the LVM link above).

I gave up on using the ATI/AMD Radeon card due to the BSOD and decided to switch over the internal graphics card as the available documentation seemed to suggest that this would be more successful.

I modified the /etc/modprobe.d/xen-pciback.conf file to do the same, but with the internal graphics (i915 and PCI id 00:02.0). I then passed that id through to the config file and added the USB device.

I first booted with gfx_passthru=0 – this brings the PCI passed through card up as a secondary device. Windows 7 successfully booted up through the VNC session and then installed the driver for the internal graphics card.

I then rebooted and got another BSOD – I decided to try and boot the system with gfx_passthru set to 1 – and it worked! Once I had gotten USB passthrough working I was able to control it as normal.

My final configuration is this:

$ cat win7_32b.cfg
builder = "hvm"
name = "win7media"
memory = "1024"
vcpus = 2
vif = ['bridge=xenbr0']
disk = ['phy:/dev/mediapc/win7_32b,hda,w']

gfx_passthru=1
pci=['00:02.0']

usb=1
usbdevice="host:045e:00db"

vnc = 1
vncconsole = 1
vncviewer = 0
vnclisten = '0.0.0.0'
boot="c"

Now I have that up and running I shall be installing and setting up XBMC. I will probably update this post with performance information and anything else I come up with.

UPDATE: It worked once… just once 🙁 when I got into windows it updated the drivers again it seems and now BSODs on PAGE_FAULT_ON_NONPAGED_AREA…

UPDATE 2: It looks like it’s working again – I booted into safe mode, the GFX card comes up ok, then I ‘ejected’ it using the USB eject and then started the system again with gfx_passthru=1 (I had changed it to 0 for safe mode though VNC). This would point to a reset issue – the card doesn’t support FLR.

Other useful references:

http://wiki.xen.org/wiki/Comprehensive_Xen_Debian_Wheezy_PCI_Passthrough_Tutorial

http://www.overclock.net/t/1205216/guide-create-a-gaming-virtual-machine

http://serverfault.com/questions/299877/how-do-i-add-xen-kernel-boot-parameters-in-grub2

 

This entry was posted in Howto, Projects, Virtualised Media PC and tagged , , , , , . Bookmark the permalink.

One Response to MediaPC in a Xen Virtual Machine

  1. Claire says:

    Hi! I work with engineering website EEWeb.com and would love to do an
    exchange of website links and feature you as a site of the day on
    EEWeb. Let me know if this is of interest to you! I can be reached at claire@eeweb.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.