# How Xen Works...

## carpenike

I started reading up on Xen today at work, and I'm having a difficult time wrapping my mind around exactly how it works... I've read the wiki and been reading other various websites, so i guess I'll just "brain dump" here some of what I've found out and see if anybody can help correct me if I'm wrong...

I use VMWare server on my windows box at work and virtualize linux... My understanding of Xen is that you create a host OS using a basic kernel, configuring the options that you need for hardware but not installing any application as of yet. You then download a Xen kernel and configure that as your domO machine. At this point do you boot into your new kernel and manage everything from there? It looked like from some of the grub scripts that there was a universal module that got loaded (the hypervisor i think?) that would load all domO and domU kernels... Is that correct?

I saw this girl's macbook pro tonight that had Parallel installed on it and it was slick how she could switch from OSX to WinXP with just a hotkey on her keyboard... It worked like the Desktop 3d package (I can't remember the name) that allows spinning of the desktop for each different desktop installed... Cept it went between OSes.

Does Xen provide this same functionality? How exactly would I use each different operating system once they're both installed? Do both OSes get booted when the PC starts or do I have to manually start each of them?

I'm looking at buying the new Asus W3J+ that'll have intel's VTX hardware support in it, and this would be a cool thing to setup if I could hot-switch between OSes at need...

I'm sorry if this is answered elsewhere, I searched the forums and google but couldn't find any specific answers... Thanks for any help you can provide.

----------

## a7thson

 *carpenike wrote:*   

> 
> 
> I use VMWare server on my windows box at work and virtualize linux... My understanding of Xen is that you create a host OS using a basic kernel, configuring the options that you need for hardware but not installing any application as of yet. You then download a Xen kernel and configure that as your domO machine. At this point do you boot into your new kernel and manage everything from there? 
> 
> 

 

I'd recommend you check out the Xen on Gentoo HOWTO if you haven't seen that already.  I'm no expert on Xen, but will try to explain it as best I can.  First, Xen and VMware (and Qemu) are similar in function but operate with very different approaches to virtualization.  Your dom0 is a Gentoo system compiled specifically for Xen.  The easiest way to explain Xen is to think of it as a layered paradigm, i.e. :

```

+------------------+----------------+

| U1 userspace     | U2 userspace   |

+------------------+----------------+

|    Xen domU 1    |   Xen domU 2 |

+------------------+----------------+

|   Xen-provided virtual h/w        |  emulated hardware

+-----------------------------------+

|           X e n   dom0            |   the "real" kernel layer

|     X e n   h y p e r v i s o r   |  technically here but unreachable

+-----------------------------------+

|   firmware+physical hardware     | 

+-----------------------------------+

```

As we can see from the diagram, Xen entirely abstracts away the hardware from the domU kernels.  So basically, you configure your dom0 much as you would do with any other Linux kernel you might normally run on the system.  The hypervisor loads dom0 and dom0 in turn provides a translation layer which becomes active when you load a domU kernel.  The domU kernel cannot "see" the actual hardware of the machine or interface with it AT ALL, except as dom0 affords it the ability to do so, through virtual devices that it provides.  Sorry if that was wordy.  Basically it means the domU kernel is fooled into thinking that it is working with actual hardware, when in fact it is talking to Xen and Xen in turn is communicating with the hardware.  When a domU kernel panics or something else nasty happens, the system remains stable and only the VM is affected/shut down.

The only real "difference" with Xen at a high-level perspective, is that with VMware and Qemu, you are running an emulation layer in userspace; i.e. as an application that is itself running on top of a kernel, while in Xen, you are taking a more direct approach by baking the emulation layer right into the kernel... i.e. an application running in VMware virtual machine looks like:

```

[ application ][ virtual hardware ][ VMware ][ kernel ][ hardware]

<-------------------------------------------||----------------------->

               u s e r s p a c e                                kernelspace

```

while an application running in a Xen domU kernel appears as:

```

[ application ][ domU ][ virtual h/w ][ dom0 kernel | hv ][ hardware ]

<---------------------||----------------------------------------------->

      u s e r s p a c e              k  e  r  n  e  l  s  p  a  c  e

```

It's a subtle but important distinction - in Xen you are pushing the emulation responsibilities right into the kernel itself, which can mean significant performance gains... but also risk, because if something is wrong with the dom0 kernel, you are in real trouble.  VMware and Qemu use a kernel module to speed performance but (I think, but IANAD) aren't nearly as intrusive since they don't modify the kernel itself, while in Xen you are actually patching into the kernel itself.  Instead you are running an application in userspace which in turn is providing a simulated hardware platform that is (basically) isolated from the actual machine.  Technically, this isn't true, but it is the easiest way to think about what's going on unless you're a Xen/Qemu/Vmware developer (I'm not).

 *Quote:*   

> 
> 
> Does Xen provide this same functionality? How exactly would I use each different operating system once they're both installed? Do both OSes get booted when the PC starts or do I have to manually start each of them?
> 
> 

 

You'll need to start the OS's yourself, the hypervisor only bootstraps your dom0, from which you load in your domU kernel(s) for the operating system.  As for booting both OS's automatically, I suppose you could simply script this and perhaps stick it into local.start or something.  Same issue with VMware or Qemu.  To my knowledge there is no built-in ability to boot one or more dom0's.  

Hopefully something in this pile of text helps to answer your questions.  This is a complex topic, IANAD, and I may have made some mistakes and corrections will be made if (when) suggested.

----------

## helmet

[quote="a7thson"] *carpenike wrote:*   

> 
> 
> Currently Xen doesn't support Windows, but this will undoubtedly be changing, in part due to recent relations between XenSource and MS.

 

not entirely true. if you have an Intel proc with VT or an AMD with SVM (i think...pacifica) you can run windows unmodified (or any OS unmodified)....i'm in the process of trying this, on my desktop AM2 processor and my core duo laptop when i get it

----------

## a7thson

 *helmet wrote:*   

>  *a7thson wrote:*   
> 
> Currently Xen doesn't support Windows, but this will undoubtedly be changing, in part due to recent relations between XenSource and MS. 
> 
> not entirely true. if you have an Intel proc with VT or an AMD with SVM (i think...pacifica) you can run windows unmodified (or any OS unmodified)....i'm in the process of trying this, on my desktop AM2 processor and my core duo laptop when i get it

 

Oh yeah, my mistake here, I actually meant it wasn't supported natively, but technically that's not true either (on this subset of machines).  I have removed the offending line.  Curses! ... how about "Xen doesn't currently support Windows on architectures that lack native hardware-level support for virtualization"?

From the official Xen Faq:

 *Quote:*   

> 
> 
> 1.4. Does Xen support Microsoft Windows?
> 
> The paravirtualized approach we use to get such high performance has not been usable directly for Windows to date. However Xen 3.0 added Intel VT-x support to enable the running of unmodified guest operating systems, including Windows XP & 2003 Server, using hardware virtualization technology. We are working on implementing support for the equivalent AMD Pacifica technology.
> ...

 

In other words, he's right.  If you have a system with VT-x support or AMD Pacifica, it will indeed work.  If you're a poor fellow like me, lacking the newer technologies, you will need to use Qemu or VMware if you want to see Windows on your Linux box, at least as of this writing, and/or wait until XenSource, possibly in collaboration with MS themselves, offers support for it on other (older) platforms.  Whew!  Hope this bit of CYA has been helpful.  :Smile: 

----------

## neuron

 *helmet wrote:*   

> 
> 
> not entirely true. if you have an Intel proc with VT or an AMD with SVM (i think...pacifica) you can run windows unmodified (or any OS unmodified)....i'm in the process of trying this, on my desktop AM2 processor and my core duo laptop when i get it

 

please update us on how that works.  A friend of mine (with an extreme budget) needs some 3d software that only runs in windows, and dual boots a whole lot because of it.  

I'd love to see how well that'd work in xen (it'd of course need relativly good performance in the virtual enviroment, AND working 3d acceleration, the last part is the one I'm wondering will work at all).  Has anyone seen any information about 3d acceleration in a virtual enviroment?

Saw this in the howto:

```

Note: If you intend on running Windows in domU (or any other guest that needs to think it has access to "real VGA" hardware) then you need to make sure that you add sdl to your USE Flags and emerge media-libs/libsdl before you emerge xen and xen-tools (there is currently no 'sdl' use flag for xen, it just builds support if libsdl is installed)

```

Looks promising atleast  :Smile: 

----------

## gpierce

 *helmet wrote:*   

> 
> 
> not entirely true. if you have an Intel proc with VT or an AMD with SVM (i think...pacifica) you can run windows unmodified (or any OS unmodified)....i'm in the process of trying this, on my desktop AM2 processor and my core duo laptop when i get it

 

If you get this working, I beg you to post the details of your efforts. I would love to try  this out myself. There are unfortunately many work related applications I use that require Windows. I am anticipating arrival of a Core Duo Extreme system which I am pretty sure uses Intel's VT. 

Greg

----------

## xming

unmodified guests (DomUs) run with ~30% performance penalties. 3D in Dom0 is possible but not on DomUs.

----------

## obefritz

Hello, 

is there anybody who succeeded in having gentoo with XEN on a dual core cpu running? And who has Windows XP as guest System?   :Question: 

I found this howto and hopefully will be able to test it the next days ....    :Very Happy: 

http://www.xensource.com/files/xen_install_windows.pdf

Regards,

Fritz

----------

## xming

I have xen running in production on SMT, SMP and duo core (opteron). No windows guest though.

----------

## clockwork06

xming: Where did you read that 3d wasnt availble for non-dom0 guests ?

----------

## Headrush

 *clockwork06 wrote:*   

> xming: Where did you read that 3d wasnt availble for non-dom0 guests ?

 

The Xen web site.

Nvidia has stated that they are interested in looking into 3d driver support for Xen guests.

----------

## neuron

getting the linux nvidia driver working seems to be very doable though.

But only in linux afaik, it's atleast not possible in any windows guest.

----------

## clockwork06

Well the only real reasons for doing this from a desktop/user perspective are all apps related. To my mind at least the only real reasons I had were running a windows guest so I could play games (EVE and Warhammer when it comes out. Eve on Cedega is horrid) and/or any DRM protected videos I wanted to watch.

So for me no 3d = no point.

----------

