xen_based_dual_boot

Prereqisites and Installation of Xen Hypervisor

1. Install Linux Mint 13/14 Mate 64 bit with LVM / (root) and /home partitions

See my how-to here: http://forums.linuxmint.com/viewtopic.php?f=42&t=108442.

Note: Linux Mint 15 and 16 have a LVM option in the installer, which makes above LVM how-to obsolete and shortens the installation process

. But please note - Linux Mint 15 and Xen 4.2 have some bugs / issues that make VGA / PCI passthrough more challenging

. A possible workaround using the xm toolstack in Linux Mint 15 is shown here: http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&p=744210#p743979. Another user reports success with Ubuntu 13.10 (Linux Mint 15) and Xen 4.3.0 (4.3.0-1ubuntu1) by simply switching to the xm toolstack - see here:http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&start=200#p775467.

Another user reported success with the latest Linux Mint 16 Cinnamon RC - see http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&p=786927#p786784.

Recommendation: Until the Linux Mint 15 / Xen 4.2/4.3 bugs are solved I recommend sticking with Linux Mint 13/14 and Xen 4.1 (force version to 4.1.3-3ubuntu1)..

2. Enable VT-d / IOMMU in BIOS

Reboot your PC and enter your BIOS setup. Look for an IOMMU or VT-d option (check the manual of your motherboard) and enable it. VT-d is an essential prerequisite to make this work!

Note: Most motherboard BIOSes have VT-d disabled by default.

3. Install Xen hypervisor and utilities

After reboot into the installed Linux Mint system, open Synaptic and install the following packages:

Linux Mint 13:

  • xen-hypervisor-4.1-amd64

  • xen-utils-4.1

  • bridge-utils

  • xen-utils-common

Linux Mint 14:

  • xen-system-amd64

4. Add boot options to grub

Edit the /etc/default/grub file as root and add or change the following:

CODE: SELECT ALL

GRUB_CMDLINE_XEN="iommu=1 dom0_mem=2048M"

The above Xen command line tells the hypervisor to use IOMMU (VT-d must be ENABLED in your BIOS) and gives the dom0 (Linux Mint) 2048 MB of RAM.

While at it, comment out the GRUB_HIDDEN_TIMEOUT=0 and GRUB_HIDDEN_TIMEOUT_QUIET=true so that it looks like this:

CODE: SELECT ALL

GRUB_DEFAULT="Xen 4.1-amd64"

# GRUB_HIDDEN_TIMEOUT=0

# GRUB_HIDDEN_TIMEOUT_QUIET=true

GRUB_TIMEOUT=10

GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"

GRUB_CMDLINE_LINUX=""

GRUB_CMDLINE_XEN="iommu=1 dom0_mem=2048M"

Note: I changed my GRUB_DEFAULT to load Xen automatically at boot. With the GRUB_HIDDEN... options commented out you will have a grub menu to select your regular Linux kernel if things go bad, or to manually select either Xen or regular boot.

Open a terminal window and run

CODE: SELECT ALL

sudo update-grub

5. Reboot into the Xen hypervisor

Select the appropriate grub menu option.

Last edited by powerhouse on Fri Nov 22, 2013 2:06 pm, edited 17 times in total.

Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Sapphire 7770 GPU, PNY Quatro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB SSD + various HD, Corsair 500R case, SeaSonic 660W Gold X PS

powerhouse

Level 4

Posts: 407

Joined: Thu May 03, 2012 3:54 am

by powerhouse on Sat Sep 15, 2012 7:54 pm

Part 3

Now that you (I hope) successfully booted into the Xen hypervisor / dom0, it's time for some configurations.

6. Adjust the network settings to use a bridge

The following commands require root permission so we make it stick. Open a terminal window and enter:

CODE: SELECT ALL

sudo -i

CODE: SELECT ALL

/etc/init.d/network-manager stop

Linux Mint 14:

CODE: SELECT ALL

stop network-manager

Stops the network manager so we can configure the bridge and enable it.

If you want to use DHCP to automatically assign an IP address etc. to your network card, replace the content of your /etc/network/interfaces file with this:

CODE: SELECT ALL

auto lo

iface lo inet loopback

auto xenbr0

iface xenbr0 inet dhcp

bridge_ports eth0

# auto eth0

For a static IP address, use this configuration in /etc/network/interfaces:

CODE: SELECT ALL

auto lo

iface lo inet loopback

auto xenbr0

iface xenbr0 inet static

bridge_ports eth0

address 192.168.0.120 # the IP address of the Ethernet port

broadcast 192.168.0.255

netmask 255.255.255.0

gateway 192.168.0.1 # the address of the router

# bridge_stp off # disable Spanning Tree Protocol - optional

bridge_waitport 0 # no delay before a port becomes available - optional, comment out if this gives you troubles

bridge_fd 0 # no forwarding delay - optional

Adopt the IP settings above to your requirements.

# There are no IP configurations for eth0, it’s all defined under xenbr0:# auto eth0

Enable networking:

CODE: SELECT ALL

service networking restart

Check that your network connection is working - open Firefox and see if you have Internet access.

Note: The "network-manager" package that is installed by default can create problems with the bridge configuration. If you can't connect to the Internet, or if networking doesn't work, remove the package.

Optional: xend automatically creates a virbr0 NAT bridge. I didn't find any use for that and disabled it by deleting the "default.xml" link in etc/libvirt/qemu/networks/autostart. In case you wish to enable it again, just create the link with ln -s /etc/libvirt/qemu/networks/default.xml /etc/libvirt/qemu/networks/autostart/default.xml.

7. Create missing links

Linux Mint 13/14 requires some fixes for the xen tools to work properly.

For Linux Mint 13 enter the following commands in the terminal window (as root):

CODE: SELECT ALL

ln -s /usr/lib /usr/lib64

ln -s /usr/lib/xen-default /usr/lib/xen

ln -s /usr/share/qemu-linaro /usr/share/qemu

For Linux Mint 14 use these:

CODE: SELECT ALL

ln -s /usr/lib /usr/lib64

ln -s /usr/lib/xen-4.1 /usr/lib/xen-default

ln -s /usr/share/qemu-linaro/qemu/ /usr/share/qemu

Thanks to Nesousx.

For Linux Mint 15 use these:

CODE: SELECT ALL

ln -s /usr/lib /usr/lib64

ln -s /usr/lib/xen-4.2 /usr/lib/xen-default

ln -s /usr/share/qemu-linaro/qemu/ /usr/share/qemu

Thanks to mantisghost.

8. Determine the PCI IDs of the devices you want to pass through to the domU (guest)

Enter the following command to list your graphics adapters' PCI IDs:

CODE: SELECT ALL

lspci | grep VGA

You should get something like this:

  • 01:00.0 VGA compatible controller: Advanced Micro Devices [AMD] nee ATI Caicos [Radeon HD 6450]

  • 02:00.0 VGA compatible controller: NVIDIA Corporation GF106GL [Quadro 2000] (rev a1)

I have two graphics adapters:

  • 01:00.0 is the primary graphics adapter installed in the first PCIe 16 slot, in my case an AMD Radeon HD 6450 graphics card. This is the GPU currently used by Linux dom0.

  • 02:00.0 is the secondary graphics adapter installed in the second PCIe 16 slot, in my case a Nvidia Quadro 2000 card. This is the one we want to pass through to the guest system. This card MUST support VGA passthrough, or else this whole procedure will fail !!! Read the hardware requirements above at the beginning very carefully.

Make a note of the PCI ID you want to pass through. Most likely your graphics card will have a second PCI ID for the onboard audio controller. This is typically 02:00.1 (for the card with PCI ID 02:00.0). You need to pass that through as well!

To check, enter the following and scroll through the output:

CODE: SELECT ALL

lspci | grep 02:00.

You will see something like this:

  • 02:00.0 VGA compatible controller: NVIDIA Corporation GF106GL [Quadro 2000] (rev a1)

  • 02:00.1 Audio device: NVIDIA Corporation GF106 High Definition Audio Controller (rev a1)

If you don't get the second line, there is no onboard audio controller you need to pass through, so use only the 02:00.0 PCI ID.

Note: You may get different PCI IDs altogether, so use the ones appropriate to your system.

Next are the USB devices:

CODE: SELECT ALL

lspci | grep USB

The output on my machine is this:

  • 00:1a.0 USB controller: Intel Corporation X79 series chipset USB2 Enhanced Host Controller #2 (rev 05)

  • 00:1d.0 USB controller: Intel Corporation X79 series chipset USB2 Enhanced Host Controller #1 (rev 05)

  • 06:00.0 USB controller: ASMedia Technology Inc. ASM1042 SuperSpeed USB Host Controller

  • 07:00.0 USB controller: ASMedia Technology Inc. ASM1042 SuperSpeed USB Host Controller

  • 08:00.0 USB controller: ASMedia Technology Inc. ASM1042 SuperSpeed USB Host Controller

I have 5 host controllers, and each of mine has 2 or more ports (IIRC).

I decided to pass through the second Intel USB controller for mouse/keyboard, since it's a USB-2 host controller which may give less troubles than USB-3. I also have a USB KVM switch that allows me to switch between two USB ports on the PC - one cable is connected to the passed-through USB port, the other to a USB-2 port that hasn't been passed through (for Linux). Here is my setup:

00.1a.0 is passed through to the domU (Windows 7) guest and one cable of the KVM is connected to this port (see below on how to determine that).

00.1d.0 is used with dom0 (Linux) and the second cable of the KVM is connected to that port.

To find out where your keyboard and mouse is currently connected, open:

  • Menu -> Control Center -> System Information -> Input Devices

and scroll down to your mouse and keyboard entry - open them and note the PCI ID you find there.

My KVM has two ports to connect both keyboard and mouse to it. If you don't use a KVM switch, it's best to have both keyboard and mouse on the same controller, so you may need to replug them and check again.

Note: If you don't want to use two keyboards and mice, or a KVM switch, see the following post for how to use Xen for mouse/keyboard input: http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&start=80#p706770. Thanks gordon.cooke !

EDIT: The following command is VERY helpful in figuring out which PCI IDs are assigned to which USB ports:

CODE: SELECT ALL

usb-devices

You will find the PCI-ID for Bus=xx Lev=00 under the "SerialNumber" entry. If a device (such as a USB stick) is plugged in, you get additional entries for Bus=xx Lev=01, Lev=02 etc. with the device listed.

9. Create pciback.conf file

Once you determined the PCI IDs for your graphics adapter and USB ports, create a config file named pciback.conf in /etc/xen with the following content:

CODE: SELECT ALL

# This file contains the list of pci devices the pciback driver should bind

# to at system startup.

# Please provide the devices in long BDF notation.

# Example:

# 0000:08:00.0

# NO EMPTY LINES!

#

0000:02:00.0

0000:02:00.1

0000:00:1a.0

Note: Replace the PCI IDs in this file with the ones you determined before! You must enter the long PCI ID notation, with a preceding 0000: for the domain! This configuration file is used by the pciback shell script below.

10. Install and activate pciback script

Save the following pciback script named pciback to /etc/init.d:

CODE: SELECT ALL

#!/bin/sh

#

### BEGIN INIT INFO

# Provides: pciback

# Required-Start: $local_fs

# Required-Stop: $local_fs

# Should-Start:

# Should-Stop:

# X-Start-Before: xend

# X-Stop-After:

# Default-Start: 2 3 4 5

# Default-Stop:

### END INIT INFO

. /lib/lsb/init-functions

scriptname=/etc/init.d/pcibackconfigfile=/etc/xen/pciback.confunbind() {# Unbind a PCI function from its driver as necessary[ ! -e /sys/bus/pci/devices/$1/driver/unbind ] || \echo -n $1 > /sys/bus/pci/devices/$1/driver/unbind}bind() {# Add a new slot to the PCI Backend’s listecho -n $1 > /sys/bus/pci/drivers/pciback/new_slot# Now that the backend is watching for the slot, bind to itecho -n $1 > /sys/bus/pci/drivers/pciback/bind}case $1 instart)cat $configfile | while read line;doecho $line | grep ^# >/dev/null 2>&1 && continueunbind $linebind $linedone;;stop|status|restart|force-reload)# As we don’t know which driver was bound before, there is not much we can do here;;*)echo “Usage: $scriptname start” >&2exit 3;;esac

Make the pciback shell script executable

CODE: SELECT ALL

chmod +x /etc/init.d/pciback

and run

CODE: SELECT ALL

update-rc.d pciback defaults 21 19

The number 21 means that it will run AFTER xend is started (xend has 20 in the init.d), and stopped before xend will stop.

Note: For some reason, the command insserv didn't work for me. You may try it instead of the above command. insserv doesn't need arguments since it should read the header and determine when to run the script.

11. Make xen-pciback module load at boot

To load the xen-pciback module during boot, edit the /etc/modules file and add on a separate line:

CODE: SELECT ALL

xen-pciback passthrough=1

Note: The option "passthrough=1" causes the xen-pciback module to use PCI ID passthrough (pass) instead of vpci which would assign different PCI IDs when passing the device through to the guest.

For reference, my /etc/modules file looks like this:

  • # /etc/modules: kernel modules to load at boot time.

  • #

  • # This file contains the names of kernel modules that should be loaded

  • # at boot time, one per line. Lines beginning with “#” are ignored.

  • lp

  • rtc

  • # For pciback to be loaded by kernel with PCI ID passthrough enabled, use:

  • xen-pciback passthrough=1

  • # Generated by sensors-detect on Fri Sep 7 15:04:55 2012

  • # Chip drivers

  • coretemp

  • w83627ehf

12. Create the Windows 7 guest configuration file

Copy/paste the following configuration file into /etc/xen and name it win7.cfg (or whatever name you choose - see also note regarding Linux Mint 15 below):

CODE: SELECT ALL

kernel = “/usr/lib/xen-default/boot/hvmloader”

builder=’hvm’

# Memory reserved for Windows domU, in this case 4GB (adjust to your

# needs):

memory = 4096

# Name of the domU that will be created/used:

name = “win7″

vcpus=6 #Most CPUs have 4 cores / 8 threads (=vcpus). Check your CPU

# and change as needed!

#pae=1 #only for 32 bit guests - don't use for 64 bit!

acpi=1

apic=1

# Here my virtual network interfaces – see /etc/network/interfaces below:

vif = [ 'mac=00:16:3e:68:e1:01,bridge=xenbr0' ]

# vif = [ 'vifname=win7,type=ioemu,mac=00:16:3e:68:e1:01,bridge=xenbr0' ]# I assigned a static MAC address, else it will be changed each time Windows# boots. The address should start with 00:16:3e., the rest is up to you.## Specifying the disks and Windows ISO for installation, adjust to your# needs:disk = [ 'phy:/dev/mapper/guest-win7,hda,w' , 'file:/media/install/Win7.iso,hdc:cdrom,r' ]# More disks can be added later using this same method. The path to the# device or a file can be added. After the first comma is how the device will# appear. “hda” is the first, “hdb” the second etc. “hda” will appear as IDE,# sda will appear as SCSI or SATA. After the second comma “r” means read# only and “w” is for write.device_model = ‘/usr/lib/xen-default/bin/qemu-dm’boot=”dc”# The above should be changed once Windows is installed: boot=”c” to only# show the Windows file system, else it may try to boot from the ISO image.sdl=0vnc=1vncpasswd=”stdvga=0# nographic=1 #!!! only uncomment this if you are using win8 or are trying# to get a Nvidia card to work. In my case – Nvidia Quadro 2000 - this was not# needed.serial=’pty’tsc_mode=0viridian=1#soundhw=’all’ # I commented it out since it’s not relevant to me now.usb=1 # This allows sharing the USB mouse/keyboard.usbdevice=’tablet’ # is recommended; in conjunction with USB=1, else comment outgfx_passthru=0# Leaving this as 0 is how it works for me with my Quadro 2000 card.# gfx_passthru=1 would pass through the graphics card as primary display adapter.# You can change this later for iGPUs or nVidia if needed.# Try it with 0 first!pci=[ '02:00.0', '02:00.1' , '00:1a.0' ]# These values are the ones you found out using the lspci command earlier.# I also passed through an entire USB controller for native support.# You can use usb-devices to find out to which hub/host the keyboard/mouse# is connected. I use a USB KVM switch to connect my keyboard/mouse to two# USB ports residing on different hubs! One – 00:1a.0 – is then passed through# to the domU.# The following lets Windows take the local time from the dom0:localtime=1#To turn on pci power management globally, use (see remarks under pci=... below):pci_power_mgmt=1

Important: You must edit the file and adjust it to your requirements !!! It most likely won't work for your hardware/setup.

Note regarding Linux Mint 15: Linux Mint 15 uses the new xl toolstack which uses a slightly different syntax. I haven't tried LM15 yet, but see http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&start=120#p720506 and http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&p=735248#p734932 for more information.

I have commented the configuration file to explain the different configuration options. Here some further explanations about the options you need to change/adopt for your hardware:

memory = # Enter the amount of memory (RAM) in Mbyte your guest will get. For example, if you have 8GB RAM, you could give the guest (Windows) a value of 4096 which is 4GB, leaving the rest for dom0 (Linux) and other Xen guests.

vcpus= # Enter the number of virtual CPUs your guest will get. I have a 6-core CPU with 12 threads and I decided to give Windows 10 of the 12 available threads (virtual CPUs). As long as I run only Linux, it will get all CPUs / VCPUs. Once I start Windows I give it 10 VCPUs, leaving 2 VCPUs for Linux. It's best to leave some CPU resources to the Linux dom0 since Linux still needs to handle I/O, networking, etc. In my case, having a 3930K CPU, 2 VCPUs for dom0 should be enough to handle that.

vif = [ 'vifname=win7,type=ioemu,mac=00:16:3e:68:e1:01,bridge=xenbr0' ] # This defines the networking part for the guest system. vifname=win7 gives a name to the interface (this feature is buggy, so I removed it). iommu means it uses the VT-d functions of the memory controller. mac=... assigns a static MAC address to the bridge so Windows won't complain about "illegal copy" etc. when the MAC changes for each boot. 00:16:3e:68: is reserved for Xen and you should use it too! Change the last two e1:01 to your liking. Just watch out that you don't have the same exact MAC addresses in your LAN or when running two guests simultaneously.

disk = [ 'phy:/dev/mapper/guest-win7,hda,w' , 'file:/media/install/Win7.iso,hdc:cdrom,r' ] # This is the disk configuration for the Windows guest, i.e. as Windows will see it. See below for creating the Windows partition on LVM. The 'file:/media...' option points to the Windows ISO image on your drive, reading it as CDROM.

boot=”dc” # is the boot order for Windows. This entry will first boot from d: then c:. Once Windows is installed you need to edit this file and remove the "d" so it reads: boot="c".

pci=[ '02:00.0', '02:00.1' , '00:1a.0' ] # These are the same PCI IDs specified in the /etc/xen/pciback.conf file we created earlier. If you have problems with the USB ports and power management, and the global "pci_power_mgmt=1" option doesn't work, try this:

pci=[ '02:00.0', '02:00.1' , '00:1a.0,power_mgmt=1' ]

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

The rest should be left as is for now. If, and only if your Windows doesn't boot or you don't get a screen or mouse/keyboard don't work, you may need to change the following, depending on the problem:

# nographic=1 # Uncomment if the Nvidia card doesn't work, or perhaps for Windows 8.

gfx_passthru=0 # Set to 1 may help with some Nvidia cards. Search the Internet for AMD cards and recommendations, though AMD cards should work with 0. Setting gfx_passthru=1 will pass through the graphics card as primary (and only) display adapter, without first booting the virtual Cirrus Logic adapter. In most cases this requires a patched Xen hypervisor, but in some cases it may work, depending on the graphics adapter and perhaps the Windows version in use.

usb=1

usbdevice=’tablet’ # You may need to comment out one of it to get the keyboard/mouse working during the installation. In my case these settings work just fine.

Documentation on the above guest configuration options can be found here: http://xen.org/files/Support/XenConfigurationDetails.pdf

13. Create a logical volume to install Windows

To make this easier, I assume you are installing on a separate disk named /dev/sdb. Of course you can also use a partition.

Note: The disk (here sdb) MUST be flagged for LVM. You can use gparted for it. Don't format it!

CODE: SELECT ALL

pvcreate /dev/sdb

Let's check:

CODE: SELECT ALL

pvdisplay

This shows you the physical LVM volumes (PV). Your newly created PV should show up as empty.

Now we create a logical volume (LV) named "win7", size 100GB for Windows in volume group (VG) "guest":

CODE: SELECT ALL

vgcreate guest /dev/sdb # assign the PV we created to volume group "guest"

lvcreate -L 100G -n win7 guest # create the logical volume named "win7", size 100G in VG "guest"

Let's check the results:

CODE: SELECT ALL

lvdisplay

See if logical volume "win7" appears.

14. Copy the Windows installation DVD to disk

Make an installation folder for Windows:

CODE: SELECT ALL

mkdir /media/install

Insert your Windows DVD into your DVD drive and enter:

CODE: SELECT ALL

dd if=/dev/cdrom of=/media/install/Win7.iso

Note: You will need a Windows retail license to use Windows inside a virtual machine.

15. Reboot the computer into Xen

Important note: After reboot with the PCI devices being detached I had problems with the nouveau driver (Nvidia) for my secondary graphics card (the one to passthrough). My PC got stuck right after login. Blacklisting the nouveau driver worked. See http://community.linuxmint.com/tutorial/view/176 for how to blacklist the nouveau driver.

Comment: In my case the nouveau driver wasn't required, as my Nvidia card is only used by Windows.

EDIT: Similar problems are reported with AMD graphics cards, in which case the solution is to blacklist the radeon driver using the radeon.blacklist=1 grub entry like this:

CODE: SELECT ALL

GRUB_CMDLINE_LINUX_DEFAULT="radeon.blacklist=1 quiet splash nomodeset"

However, if you choose to use 2 AMD or 2 Nvidia graphics cards, you would need the respective driver for your dom0. In that case the PCI devices should be detached before the driver starts. You may need to run update-rc.d pciback defaults 21 19 with different numbers, or find another way to run this script before the graphics drivers are loaded.

See also earlboy's post here: http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&start=60#p705871.

... to be continued

Last edited by powerhouse on Wed Aug 14, 2013 8:26 am, edited 28 times in total.

Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Sapphire 7770 GPU, PNY Quatro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB SSD + various HD, Corsair 500R case, SeaSonic 660W Gold X PS

powerhouse

Level 4

Posts: 407

Joined: Thu May 03, 2012 3:54 am

by powerhouse on Sun Sep 16, 2012 8:37 am

Part 4

We are almost there.

16. Install vncviewer and adjust xend config file

We need a VNC viewer for the installation of Windows. In the terminal window:

CODE: SELECT ALL

sudo apt-get install vncviewer

16a. Alternative to 16.:

You can use virt-manager to install Windows. It's a GUI and has an integrated VNC viewer. In the terminal window:

CODE: SELECT ALL

sudo apt-get install virt-manager

To use virt-manager, we need to modify the /etc/xen/xend-config.sxp file (as root) as follows. I copied only the relevant entries, with a short explanation below:

CODE: SELECT ALL

# -*- sh -*-

#

# Xend configuration file.

#

(xend-unix-server yes)

# If you are using only one bridge, the vif-bridge script will discover that,

# so there is no need to specify it explicitly. The default is to use

# the bridge which is listed first in the output from brctl.

#

#(vif-script vif-bridge)

# This is a minimum both for auto-ballooning (as enabled by

# enable-dom0-ballooning below) and for xm mem-set when applied to# dom0.(dom0-min-mem 196)# Whether to enable auto-ballooning of dom0 to allow domUs to be created.# If enable-dom0-ballooning = no, dom0 will never balloon out.(enable-dom0-ballooning no)# 32-bit paravirtual domains can only consume physical# memory below 168GB. On systems with memory beyond that address,# they’ll be confined to memory below 128GB.# Using total_available_memory (in GB) to specify the amount of memory# reserved in the memory pool exclusively for 32-bit paravirtual domains.# Additionally you should use dom0_mem = as a parameter in# xen kernel to reserve the memory for 32-bit paravirtual domains, default# is “0″ (0GB).(total_available_memory 0)# In SMP system, dom0 will use dom0-cpus # of CPUS# If dom0-cpus = 0, dom0 will take all cpus available(dom0-cpus 0)# Whether to enable core-dumps when domains crash.#(enable-dump no)# The tool used for initiating virtual TPM migration#(external-migration-tool ”)# The interface for VNC servers to listen on. Defaults# to 127.0.0.1 To restore old ‘listen everywhere’ behaviour# set this to 0.0.0.0#(vnc-listen ’127.0.0.1′)# The default password for VNC console on HVM domain.# Empty string is no authentication.(vncpasswd "")

(xend-unix-server yes) # For virt-manager to work we need to enable the xend-unix-server yes - uncomment the line.

The other configuration lines below are optional and don't need to be changed for installing/running the Windows domU:

#(vif-script vif-bridge) # It should not be necessary to uncomment this line, if you have only one bridge configured.

(dom0-min-mem 196) # Specifies the minimum amount of RAM for dom0. This is used in conjunction with enable-dom0-ballooning below. We already set a minimum memory in the /etc/default/grub file. You may increase it just for safety, but not more than the amount specified under grub.

#(enable-dom0-ballooning yes) # This option, when enabled, allows domU guests to take memory from dom0, when there is not enough unused RAM available. The Xen documentation recommends NOT to use this, as Linux configures its memory during the boot process and does not like a changing memory size, or it may be stuck with large memory mappings when there is in fact much less memory available for dom0. For further information, read here: http://wiki.xen.org/wiki/XenBestPractices.

(dom0-cpus 0) # I give my dom0 all CPUs available when not running the Windows domU. Some Xen.org suggestions are pinning the CPUs to dom0 and perhaps domU. In my system, when Windows is not running, I have all CPUs for Linux. It works quite nicely and I can't complain about Linux performance. Again, check the Best Practices wiki linked above.

(vncpasswd "") # Disables password authentication for VNC.

As mentioned before, the "xend-unix-server yes" is required by virt-manager to work. The other settings define how xend will operate and are also relevant for VNC console access.

17. Verify that pciback works

First check that everything is setup correctly:

CODE: SELECT ALL

sudo xm pci-list-assignable-devices

should give the list of detached devices that can be assigned (bound) to the Windows guest. My list looks like that:

  • 0000:02:00.0

  • 0000:02:00.1

  • 0000:00:1a.0

All devices I configured are ready for passthrough.

Note: If some PCI IDs are missing - namely the PCI IDs for the graphics card - check steps 9 to 11 to make sure you didn't miss anything (also verify the IDs). If all fails, try the method in this post: http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&start=120#p711782. The method described in this post integrates the xen-pciback module into the initramfs so it can be loaded via a grub boot option, before the graphics driver grabs the card.

CODE: SELECT ALL

sudo xm list

lists the current domains. At the moment only domain0 should be listed.

Note: For debugging purposes this command can come handy:

CODE: SELECT ALL

sudo xm dmesg

18. Create the Windows domU using its configuration file

CODE: SELECT ALL

sudo xm create /etc/xen/win7.cfg

and connect to it via VNC:

CODE: SELECT ALL

sudo vncviewer localhost:0

Note: It may work without sudo.

18a. Alternatively, use virt-manager (see 16a above):

CODE: SELECT ALL

sudo xm new /etc/xen/win7.cfg # this defines a new domU for xend, using the specified configuration file

sudo virt-manager

In virt-manager, select the domU and click "Open". You can check the settings by pressing the "Details" button. If everything looks good, go back to the console display by clicking the "Console" button. Then click ">" (Run).

19. Install Windows guest

Unless there is some configuration error (check your path to the /media/install/Win7.iso file or whatever you name it), the Windows installer should boot now and you should see the screen output in the console (enlarge it if necessary).

Install Windows as you normally would. At some point Windows will reboot the guest domU (not Linux).

20. Access Windows after automatic reboot

After Windows has rebooted, it should come back to the virt-manager or VNC console. If not, close virt-manager or VNCviewer and run again.

If Windows doesn't start and you get a qemu shell screen, it might have passed through your mouse/keyboard and/or your display adapter. Alternatively, you might need to change your /etc/xen/win7.cfg file and specify boot="c". Before you edit the win7.cfg file, shutdown the domU (from within virt-manager or via xm shutdown win7). Edit your win7.cfg file and run xm delete win7, followed by

a) sudo xm new /etc/xen/win7.cfg and virt-manager

or

b) sudo xm create /etc/xen/win7.cfg, and connect via VNC

Note: If, after your Windows guest reboots, you get a message like "parallel0 console" on your VNCviewer screen, see here: http://forums.linuxmint.com/viewtopic.php?f=42&t=112013&p=786927#p786784.

21. Install Windows graphics driver

After the second Windows 7 VM reboot, Windows will tell that "Setup is preparing your computer for first use...". Once booted, still in the VNC console screen, you'll need to install and enable the graphics adapter driver for your display card. Inside Windows under Device Manager, check for graphics adapters. It should list two graphics adapters, one is for the emulated Cirrus VGA adapter that you are currently using, the other one is the real graphics adapter (in my case it had a yellow triangle as the driver was missing).

Before going any further, check the following hardware requirements:

a) A separate screen connected to the secondary graphics adapter to be used by Windows; or a second cable connection to your current screen; or a KVM switch for keyboard, mouse, and optionally display. I use my KVM switch only for keyboard/mouse and connected my secondary graphics adapter via DVI cable to the second DVI port on my screen. Some screens will have VGA ports, or HDMI. Both should work, though I don't care much about VGA because of it's low quality compared to DVI or HDMI. The screen should have a button to select the input source, if using only one screen.

b) If you want to pass through your keyboard/mouse, the best choice is a USB KVM switch. Else you need to unplug and replug your keyboard/mouse to the appropriate USB ports.

c) You could also use your keyboard and mouse without passing the PCI device through (using the USB=1 and/or tablet=1 settings in the win7.cfg file). Frankly I have no experience with this.

Or you could use a second mouse/keyboard just for Windows when using PCI passthrough on the USB port.

Now install the driver for your graphics adapter. In my case, I went to the Nvidia support website and ran the Java script to determine the correct driver, downloaded and installed it. The more common option would be to let Windows find the suitable display driver.

Once the installation has finished:

* the screen should reset and switch to the graphics adapter. If at that point you get a black screen, switch your screen to the other display port. If you see the Windows screen - open a bottle of Champagne - you've done it.

* alternatively Windows may ask you to reboot. Do so and watch the boot process in the VNC screen. After loading the graphics driver, and before the login screen, Windows should switch the output to your installed graphics adapter and you should be greeted with a Windows screen on your display.

If you get a black screen when rebooting Windows, or at any point during installation, switch your display to the second input. Do you see a Windows screen - if yes, it's a reason to celebrate.

22. What if VGA passthrough doesn't work?

If you can't get your VGA adapter to pass through to Windows, there are some options you may want to check:

a) First make absolutely sure your graphics adapter is supported !!! See my lengthy introduction to hardware requirements. Unless you have a Nvidia "multi-OS" graphics adapter, AMD will be a better choice. Have a look at the following threads/blogs for more information on VGA passthrough and adapters:

http://www.overclock.net/t/1307834/xen-vga-passthrough-compatible-graphics-adapters

http://gro.solexiv.de/2012/08/pci-passthrough-howto/

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

http://wiki.xen.org/wiki/Xen_VGA_Passthrough

http://wiki.xen.org/wiki/Xen_VGA_Passthrough_Tested_Adapters

This page seems a bit outdated, but probably the safest reference when purchasing a graphics card. Pay attention to the Xen hypervisor release - Linux Mint is currently (15.04.2013) using version 4.1.3. However, Xen already released the 4.2 hypervisor, which is supposed to bring better support for graphics adapters, including some unto now unsupported graphics cards (see wiki page for details).

Note: Xen 4.2 uses the xl toolstack which is different from the xm toolstack used in this how-to!!! There are some reports about VGA passthrough related issues with xl, so for some it may work, for others not.

http://www.phoronix.com/scan.php?page=news_item&px=MTA3NjA - this is the complicated way to get Xen VGA passthrough with Nvidia cards (see link inside the text). This procedure should work with some Nvidia cards that are NOT "multi-OS".

http://www.davidgis.fr/blog/index.php?2011/12/07/860-xen-42unstable-patches-for-vga-pass-through - this is currently THE resource for instructions and patches when you want or need to compile the Xen hypervisor. This is specifically for Nvidia cards that don't have native support for VGA passthrough.

23. Change Windows boot order in guest config file

After Windows is installed, edit the /etc/xen/win7.cfg file and change the "boot=dc" option to boot="c". This is equivalent to ejecting the installation disk from the DVD drive. If the installation ISO is still required, but you want/need to change the boot order, specify boot="cd".

24. Booting the Windows guest

After everything is installed and VGA / PCI passthrough is working properly, you can use the following command to start your Windows domU:

CODE: SELECT ALL

sudo xm create /etc/xen/win7.cfg

25. Install GPLPV drivers under Windows

Inside Windows, download and install the latest GPLPV drivers from here: http://www.meadowcourt.org/downloads/*.

As of this writing, the latest version is 0.11.0.372.

For my Windows 7 64-bit version I downloaded the gplpv_Vista2008x64_0.11.0.372.msi driver. Double-click on it to install under Windows. If the installer requests testsigning to be enabled, quit the installer, open a Windows admin shell and enter

CODE: SELECT ALL

bcdedit.exe /set TESTSIGNING ON

Then reboot Windows and install the GPLPV drivers.

Important:When using the GPLPV network driver, you need to modify the win7.cfg and remove the "type=ioemu" option from the vif=... line.

* Note: The Univention website (http://wiki.univention.de/index.php?title=Installing-signed-GPLPV-drivers) that I had listed here before does NOT have these latest drivers!

END

Note: Once you successfully installed Windows on a Xen hypervisor, you may like the backup and restore scripts I've written. See http://forums.linuxmint.com/viewtopic.php?f=42&t=133089. Enjoy!

Last edited by powerhouse on Fri Nov 22, 2013 2:18 pm, edited 16 times in total.

Asus Sabertooth X79 (NOT recommended), i7 3930K CPU, 8x4GB Kingston DDR3 RAM, Noctua NH-D14 CPU cooler, Sapphire 7770 GPU, PNY Quatro 2000 GPU, Asus Xonar Essence STX, Sandisk Extreme 120GB SSD + various HD, Corsair 500R case, SeaSonic 660W Gold X PS

powerhouse

Level 4

Posts: 407

Joined: Thu May 03, 2012 3:54 am

by powerhouse on Sun Sep 16, 2012 9:09 am

Edit: New startup script for Windows guest

Once you got everything running and you can boot and shutdown and reboot your Windows guest, with Windows using the graphics card, it's time for a startup script.

Here are the steps to create and launch a startup script without the need to give a root password:

1. If it doesn't exist, create a folder named .bin in your home directory. This is a hidden folder so it won't show up unless you select -> View -> Show hidden files in your file browser.

2. Create a file named "windows.sh" inside /home/myusername/.bin and paste the following shell script into that file:

CODE: SELECT ALL

#!/bin/sh

if xm list | grep -q win7; then

zenity --warning --timeout=15 --text="Windows is already running." &

exit 1

else

xm create /etc/xen/win7.cfg &> /dev/null

zenity --info --timeout=15 --text="Starting Windows, please wait." &

exit 0

fi

Check that your Windows guest config file is /etc/xen/win7.cfg - if not, replace the win7.cfg name in the script above.

In a terminal window, enter the following:

CODE: SELECT ALL

cd ~/.bin

sudo chown root windows.sh

sudo chmod 500 windows.sh

This changes the ownership of the file to root and allows only root to read and execute the script. This is an important security measure. Don't skip it, since the next steps will allow you to run this script without a password!

3. I'm using "zenity" in my script to display screen messages. Check if /usr/bin/zenity exists. If yes, continue with the step 4.

If not and you are using Mate instead of Gnome, the mate-dialogs package should be installed. To make it work under Mate, you can use either of the two methods below:

a) Enter in a terminal window:

CODE: SELECT ALL

sudo ln -s matedialog /usr/bin/zenity

OR

b) Install the mate-dialogs-gnome package.

4. Warning:

This step is potentially dangerous. It changes the way sudo works. Entering incorrect values here can render the sudo command nonfunctional. Instead of creating the /etc/sudoers.d/permissions file, you may also use sudo visudo and make the changes / additions directly in the /etc/sudoers file, where visudo will check the syntax and prevent syntax errors. You have been warned.

Create a file named permissions in the /etc/sudoers.d folder (you need to be root to do that), and paste the following into the file:

CODE: SELECT ALL

# Host alias specification

Host_Alias HOST = hostname

Host_Alias LAN = 192.168.1.0/255.255.255.0

Host_Alias HOME = HOST,LAN

# User alias specification

User_Alias WIN_USERS = myusername

# Cmnd alias specification

Cmnd_Alias WIN = /home/myusername/.bin/windows.sh

# User privilege specification

WIN_USERS HOME=(root) NOPASSWD:WIN

Important ! Replace the following in the /etc/sudoers.d/permissions file before saving it:

hostname: Replace with the hostname of your PC. If you don't know, open a terminal window and type:

CODE: SELECT ALL

cat /etc/hostname

192.168.1.0: Replace with the IP of your network. To find out, use:

CODE: SELECT ALL

ifconfig | grep -A 1 xenbr0

The second line reads something like "inet addr:192.168.1.145 Bcast:192.168.1.255 Mask:255.255.255.0". "192.168.1.145" in this example is the IP address of xenbr0 (your virtual network device), so the network IP would be 192.168.1.0. Adjust to what you find.

myusername: Replace with your username. If you forgot your user name, type whoami in a terminal window (isn't it amazing, your PC can tell you who you are).

After you replaced the hostname, IP, and myusername, save the file.

5. Open a terminal window and enter the following:

CODE: SELECT ALL

cd /etc/sudoers.d/

sudo chmod 440 permissions

to change the file permissions to read-only for root and group.

6. To create a launcher, right-click on the desktop and fill in the prompt. For the Command: prompt, enter

CODE: SELECT ALL

sudo /home/myusername/.bin/windows.sh

Replace "myusername" with your user name.

The above steps will allow you to run the windows.sh start script from your PC (host) as well as from your home network (LAN). Remove "LAN" from the "Host_Alias HOME = HOST,LAN" line of the permissions file if you do not want to grant password-free access from the LAN (as user myusername). The script also checks if Windows is already running (make sure the domain name win7 in the script matches the name specified in your /etc/xen/win7.cfg file).

source : http://forums.linuxmint.com/viewtopic.php?f=42&t=112013