Difference between pages "Creating VMs" and "Compiling Xen"

From Wikislax
(Difference between pages)
Jump to: navigation, search
(Creating a HVM)
 
(Updating go)
 
Line 1: Line 1:
 
{{RightTOC}}
 
{{RightTOC}}
  
== the xl tool ==
+
== What is Xen ? ==
  
There is a variety of tools and commands to handle virtual machines. Here we will use the Xen '''xl''' command.
+
[http://wiki.xen.org/wiki/Xen_Overview Xen] is an hypervisor, a thin software layer executing multiple virtual machines, each running its own operating system. Xen is normally used as a server virtualization platform, running on headless servers without graphical console and controlled through the network. However it is also possible to run Xen on graphical desktops, and with proper hardware virtualization, to dedicate the primary graphics card (and keyboard / mouse) to a virtual machine, making it possible to have high performance full 3D and video acceleration in a virtual machine (see [http://wiki.xen.org/wiki/Xen_VGA_Passthrough Xen VGA Passthru]). Xen is otherwise free and open source.
  
* '''xl create ''file''''' affords creating a virtual machine based on the configuration in file ''file''. A one-starting sequential domain id is created.
+
== A few quirks ==
  
* '''xl destroy ''domid''''' affords destroying a virtual machine with domain id ''domid''. Of course using the system in the VM will be a preferred method to terminate.
+
The '''dev86-0.16.21-x86_64-1.txz''' package included with Slackware 14.2 does not afford compiling '''xen-4.9.0''' properly, and must be replaced by '''[{{SERVER}}/wikislax/download/dev86-0.16.17-x86_64-2.txz dev86-0.16.17-x86_64-2.txz]''', that can be found on the Slackware 13.37, 14.0, or 14.1 distribution disks, in directory '''slackware64/d'''. Trying to compile dev86 [http://v3.sk/~lkundrak/dev86/ from source] is not an alternative : dev86 source versions 0.16.18 to 0.16.21 have the same issue compiling xen-4.9.0, and older 0.16.17 does not compile on Slackware 14.2.
  
* '''xl help''' affords getting more information on other xm commands.
+
# removepkg /var/log/packages/dev86-0.16.21-x86_64-1.txz
 +
# installpkg dev86-0.16.17-x86_64-2.txz
  
Xen supports paravirtualisation and hardware virtualization. Both can be used at the same time on a single Xen system.
+
Also, the '''grub-2.00''' included with Slackware 14.2 does not afford booting xen. However, getting the latest version '''grub-2.02''' from source does work.
  
== Creating a PV VM ==
+
== Hardware requirements ==
  
* in paravirtualization (PV) guest operating systems are modified so they are able to interlock with Xen without emulation or virtual emulated hardware. Xen PV guest kernels exist for Linux, NetBSD, FreeBSD, OpenSolaris and Novell Netware. Upstream kernel.org Linux kernels since Linux 2.6.24 include Xen PV guest (domU) support based on the Linux pvops framework, so every upstream Linux kernel can be automatically used as Xen PV guest kernel without any additional patches or modifications.
+
Xen runs on Intel X86 hardware and requires a processor and motherboard supporting VT-x and optionally VT-d for hardware virtualization. See this [http://www.intel.com/support/motherboards/desktop/sb/cs-030922.htm page] for a list of Intel compatible motherboards and chipsets and this [http://ark.intel.com/ page] for a list of compatible processors. Our system running Xen successfully at the time of this writing (and since June 2012) is based on a DZ77GA70K Intel motherboard, an Intel® Core™ i7-3770 Processor (the overclockable i7-3770 "K" model does not afford virtualization), 32 Gb of PC12800 memory and an MSI GeForce G210 graphics board.
  
Paravirtualization requires storing the kernel to boot in the dom0 filesystem, and populating the system in a virtual partition. The kernel generated must be able to manage [http://wiki.qemu.org/download/qemu-doc.html#QEMU-PC-System-emulator the QEMU devices] and include the .config file [http://wiki.xen.org/wiki/Mainline_Linux_Kernel_Configs#Configuring_the_kernel domU options]. Here is a minimal example of such a [{{SERVER}}/wikislax/download/config-domU .config domU] file. The swap partition and VM filesystem can be created as below. Don't forget to update the root device in fstab :
+
== Documentation difficulties ==
  
# dd if=/dev/zero of=pv-sl12.swap bs=1024k count=1024
+
Although the software itself works well and is pretty straighforward, good quality Internet information is missing. The volume of information on the Xen wiki is plethoric, but mostly irrelevant as pertaining to old versions of everything. Building the big picture requires interpretation of tiny bits in forum messages, a pretty painful process, although I have to recognize that it worked for me in the end. An alternative is to use one of these old-style information repositories named "books". Yes it is pretty old-fashionned ;) but actually there are good ones on the topic. Here is [http://www.amazon.co.uk/The-Book-Xen-Practical-Administrator/dp/1593271867/ref=sr_1_1?s=books&ie=UTF8&qid=1341037874&sr=1-1 the most recent I found], it is a good value but of course you can find more on [http://www.amazon.co.uk/s/ref=nb_sb_noss_2?url=search-alias%3Dstripbooks&field-keywords=xen&x=0&y=0 amazon(.co.uk)].
# mkswap pv-sl12.swap
 
# dd if=/dev/zero of=pv-sl12.img bs=1024k count=8192
 
# mkfs -t ext3 pv-sl12.img
 
# mkdir /tmp/loop
 
# mount -o loop pv-sl12.img /tmp/loop
 
# cp -ax /mnt/sl12/{bin,dev,etc,lib,root,sbin,usr,var} /tmp/loop
 
# mkdir /tmp/loop/{home,proc,opt,sys,tmp}
 
# chmod 777 /tmp/loop/tmp
 
# vi /tmp/loop/etc/fstab
 
# umount /tmp/loop
 
  
Then a PV config file needs to be created. Samples are available from the /etc/xen directory. Here is an [{{SERVER}}/slax/download/sl12 example] running in a X window for slackware 12.1 (32 bits). The main config options to modify are :
+
== Software constraints ==
  
# Kernel image file in dom0 filesystem
+
To make a long story short, at the time of this writing (and since June 2012) working with nVidia graphic boards on Xen and X11 requires the "nouveau" driver. Other drivers like nv or the nVidia proprietary driver do not support Xen and switch off the screen when launched or do not display properly. "Nouveau" requires a fairly recent version of X11. Slackware 13.37 or newer is required. "Nouveau" is available in kernel 3.4.2 upstream and was previously included as a staging driver. Xen dom0 support was included in kernel 3.0. To benefit from both Xen and "Nouveau", the best is to use kernel 3.4.2 upstream.
kernel = "/boot/vmlinuz-3.4.2-domU"
 
# Not using any optional ramdisk
 
#ramdisk = "/boot/initrd.gz"
 
# Initial memory allocation (in megabytes) for the new domain.
 
memory = 2048
 
# A name for the new domain. All domains have to have different names,
 
name = "sl12"
 
# Number of virtual CPUs
 
vcpus = 2
 
# Define network interfaces
 
vif = [ ' ' ]
 
# Define disk devices. Note the device names xvda and xvdb
 
disk = [ 'file:/mnt/xen/sl12.img,xvda1,w', 'file:/mnt/xen/sl12.swap,xvdb,w' ]
 
# Define frame buffer device. Use sdl to view virtual machine in a window
 
vfb = [ 'sdl=1' ]
 
# Set root device.
 
root = "/dev/xvda1 ro"
 
# Window resolution additional parameters
 
extra = "xen-fbfront.video=16,1280,768"
 
  
The VM can then be launched with '''xl create ''file''''' :
+
== Compiling acpica ==
  
root@inner:/etc/xen# xl create sl12
+
Xen requires acpica. [https://www.acpica.org/downloads Download] then install as below :
Parsing config from sl12
 
root@inner:/etc/xen#
 
  
== Creating a HVM ==
+
# tar -C /usr/local -xvf acpica-unix-yyyymmdd.tar.gz
 +
# cd /usr/local
 +
# chown -R root:root acpica-unix-yyyymmdd
 +
# cd acpica-unix-yyyymmdd
 +
# make
 +
# make install
 +
# cd ..
 +
# rm -r acpica-unix-yyyymmdd
  
* in full hardware virtualization (HVM) guests require CPU virtualization extensions from the host CPU (Intel VT-x, AMD-V). Xen uses a modified version of Qemu to emulate full PC hardware, including BIOS, IDE disk controller, VGA graphic adapter, USB controller, network adapter etc for HVM guests. CPU virtualization extensions are used to boost performance of the emulation. Fully virtualized guests do not require kernel support, so for example Windows operating systems can be used as Xen HVM guest. Fully virtualized guests are usually slower than paravirtualized guests, because of the required emulation.
+
== Compiling yajl ==
  
Full hardware virtualization requires only a disk image to execute in. Then a HV config file needs to be created. Samples are available from the /etc/xen directory. Here is an [{{SERVER}}/wikislax/download/win7 example] running in a X window for Windows 7. The main config options to modify are :
+
Xen requires yajl. [http://lloyd.github.io/yajl/ Download] then install as below. <u>Note</u> : there is no option to specify the target library directory so the files need to be moved manually.
  
  # Initial memory allocation (in megabytes) for the new domain.
+
  # tar -C /usr/local -xvf lloyd-yajl-x.y.z.66cb08c.tar.gz
  memory = 2048
+
  # cd /usr/local
  # A name for the new domain. All domains have to have different names,
+
  # chown -R root:root lloyd-yajl-66cb08c
  name = "win7"
+
  # cd lloyd-yajl-66cb08c
  # Number of virtual CPUs
+
  # ./configure
  vcpus = 4
+
  # make
  # Define network interfaces
+
  # make install
  vif = [ 'type=ioemu, bridge=br0' ]
+
  # cd ../lib
  # Define disk devices. Note the device names xvda and xvdb
+
  # mv libyajl* ../lib64
disk = [ 'file:/mnt/xen/win7.img,hda,w', 'file:/mnt/xen/win7.iso,hdc:cdrom,r' ]
+
  # ldconfig
  # enable SDL library for graphics, default = 0
+
  # cd ..
sdl=1
+
  # rm -r lloyd-yajl-66cb08c
  # enable VNC library for graphics, default = 1
 
vnc=0
 
  # set VNC display number, default = domid
 
vncdisplay=7
 
  
The VM can then be launched with '''xl create ''file''''' :
+
== Updating go ==
  
root@inner:/etc/xen# xl create win7
+
Xen 4.19.1 requires the go language. Go is included as part of gcc but does not work "as is" and must be replaced by the version from the go web site. [https://go.dev/dl/ Download] then install as below.
Parsing config from win7
 
root@inner:/etc/xen#
 
  
== A little screen shot ==
+
# ls /var/log/packages | grep gcc-go
 +
gcc-go-11.2.0-x86_64-2
 +
# removepkg gcc-go-11.2.0-x86_64-2
 +
. . .
 +
# tar -C /usr/local -xvf go1.23.5.linux-amd64.tar.gz
  
The 3 VMs displayed on this slackware 13.37 dom0 are slackware 12.1, windows 7 and windows 8.  
+
Then add the '''/usr/local/go/bin''' to '''$PATH''' in /etc/profile.
  
[[file:Screenshot.png]]
+
== Compiling Xen ==
 +
 
 +
[http://xen.org/products/xen_source.html Download Xen] from the official [http://www.xen.org xen.org] site. <u>Note</u> : File stubs-32.h is missing in the compiler includes so we add a link to the existing stubs-64.h. Also, some Xen Python scripts are installed in /usr/local/lib64/python-2.7/site-packages which python cannot find so we add links from the standard library as well.
 +
 
 +
# cd /usr/include/gnu
 +
# ln -s stubs-64.h stubs-32.h
 +
# cd
 +
# tar -C /usr/local -xvf xen-x.y.z.tar.gz
 +
# cd /usr/local
 +
# chown -R root:root xen-x.y.z
 +
# cd xen-x.y.z
 +
# ./configure --libdir=/usr/local/lib64 --with-initddir=/etc/rc.d
 +
# make world
 +
# make install
 +
# make clean
 +
# cd ../lib64/python2.7/site-packages
 +
# ln -s xen /usr/lib64/python2.7/site-packages
 +
# ln -s xen-3.0-py2.7.egg-info /usr/lib64/python2.7/site-packages
 +
 
 +
== Adjusting rc.local* ==
 +
 
 +
Xen needs a couple of daemons to run to ensure VM management. Add these lines to rc.local and rc.local_shutdown :
 +
 
 +
PATH=/usr/local/sbin:/usr/local/bin:$PATH
 +
export PATH
 +
 +
# start xencommons
 +
if [ -x /etc/rc.d/xencommons ]; then
 +
    /etc/rc.d/xencommons start
 +
fi
 +
 +
# stop xencommons
 +
if [ -x /etc/rc.d/xencommons ]; then
 +
    /etc/rc.d/xencommons stop
 +
fi
 +
 
 +
== Compiling a dom0 Kernel ==
 +
 
 +
Domain-0 (dom0 for short) is a special guest (virtual machine) that the Xen hypervisor always loads on host startup. Dom0 is used to control and manage the Xen hypervisor, and provides virtual disks and networks for other unprivileged guests (=domUs). Dom0 support was introduced in Linux kernel 3.0. The kernel generated must include the .config file domU and [http://wiki.xen.org/wiki/Mainline_Linux_Kernel_Configs#Configuring_the_kernel dom0 options]. Here is a minimal example of such a [{{SERVER}}/wikislax/download/config-dom0 .config dom0] file. Feel free to use it as a base, replacing device drivers as required. The rest of the kernel compilation is nominal :
 +
 
 +
# tar -C /usr/src -xvf linux-4.4.88.tar.bz2
 +
# cd /usr/local
 +
# rm linux
 +
# ln -s linux-4.4.88 linux
 +
# cd linux
 +
# make menuconfig
 +
# make
 +
# make modules_install
 +
# cp arch/x86_64/boot/bzImage /boot/vmlinuz-4.4.88-dom0
 +
# cp System.map /boot/System.map-4.4.88-dom0
 +
# cp .config /boot/config-4.4.88-dom0
 +
 
 +
We're now all set up, Xen is ready to be booted by grub2 !
  
 
<br/>
 
<br/>
  
{{pFoot|[[Using Grub2]]|[[Main Page]]|[[OpenSSL]]}}
+
{{ pFoot |[[Compiling from Source]]|[[Main Page]]|[[Using Grub2]]}}

Revision as of 14:48, 4 February 2025

What is Xen ?

Xen is an hypervisor, a thin software layer executing multiple virtual machines, each running its own operating system. Xen is normally used as a server virtualization platform, running on headless servers without graphical console and controlled through the network. However it is also possible to run Xen on graphical desktops, and with proper hardware virtualization, to dedicate the primary graphics card (and keyboard / mouse) to a virtual machine, making it possible to have high performance full 3D and video acceleration in a virtual machine (see Xen VGA Passthru). Xen is otherwise free and open source.

A few quirks

The dev86-0.16.21-x86_64-1.txz package included with Slackware 14.2 does not afford compiling xen-4.9.0 properly, and must be replaced by dev86-0.16.17-x86_64-2.txz, that can be found on the Slackware 13.37, 14.0, or 14.1 distribution disks, in directory slackware64/d. Trying to compile dev86 from source is not an alternative : dev86 source versions 0.16.18 to 0.16.21 have the same issue compiling xen-4.9.0, and older 0.16.17 does not compile on Slackware 14.2.

# removepkg /var/log/packages/dev86-0.16.21-x86_64-1.txz
# installpkg dev86-0.16.17-x86_64-2.txz

Also, the grub-2.00 included with Slackware 14.2 does not afford booting xen. However, getting the latest version grub-2.02 from source does work.

Hardware requirements

Xen runs on Intel X86 hardware and requires a processor and motherboard supporting VT-x and optionally VT-d for hardware virtualization. See this page for a list of Intel compatible motherboards and chipsets and this page for a list of compatible processors. Our system running Xen successfully at the time of this writing (and since June 2012) is based on a DZ77GA70K Intel motherboard, an Intel® Core™ i7-3770 Processor (the overclockable i7-3770 "K" model does not afford virtualization), 32 Gb of PC12800 memory and an MSI GeForce G210 graphics board.

Documentation difficulties

Although the software itself works well and is pretty straighforward, good quality Internet information is missing. The volume of information on the Xen wiki is plethoric, but mostly irrelevant as pertaining to old versions of everything. Building the big picture requires interpretation of tiny bits in forum messages, a pretty painful process, although I have to recognize that it worked for me in the end. An alternative is to use one of these old-style information repositories named "books". Yes it is pretty old-fashionned ;) but actually there are good ones on the topic. Here is the most recent I found, it is a good value but of course you can find more on amazon(.co.uk).

Software constraints

To make a long story short, at the time of this writing (and since June 2012) working with nVidia graphic boards on Xen and X11 requires the "nouveau" driver. Other drivers like nv or the nVidia proprietary driver do not support Xen and switch off the screen when launched or do not display properly. "Nouveau" requires a fairly recent version of X11. Slackware 13.37 or newer is required. "Nouveau" is available in kernel 3.4.2 upstream and was previously included as a staging driver. Xen dom0 support was included in kernel 3.0. To benefit from both Xen and "Nouveau", the best is to use kernel 3.4.2 upstream.

Compiling acpica

Xen requires acpica. Download then install as below :

# tar -C /usr/local -xvf acpica-unix-yyyymmdd.tar.gz
# cd /usr/local
# chown -R root:root acpica-unix-yyyymmdd
# cd acpica-unix-yyyymmdd
# make
# make install
# cd ..
# rm -r acpica-unix-yyyymmdd

Compiling yajl

Xen requires yajl. Download then install as below. Note : there is no option to specify the target library directory so the files need to be moved manually.

# tar -C /usr/local -xvf lloyd-yajl-x.y.z.66cb08c.tar.gz
# cd /usr/local
# chown -R root:root lloyd-yajl-66cb08c
# cd lloyd-yajl-66cb08c
# ./configure
# make
# make install
# cd ../lib
# mv libyajl* ../lib64
# ldconfig
# cd ..
# rm -r lloyd-yajl-66cb08c

Updating go

Xen 4.19.1 requires the go language. Go is included as part of gcc but does not work "as is" and must be replaced by the version from the go web site. Download then install as below.

# ls /var/log/packages | grep gcc-go
gcc-go-11.2.0-x86_64-2
# removepkg gcc-go-11.2.0-x86_64-2
. . .
# tar -C /usr/local -xvf go1.23.5.linux-amd64.tar.gz

Then add the /usr/local/go/bin to $PATH in /etc/profile.

Compiling Xen

Download Xen from the official xen.org site. Note : File stubs-32.h is missing in the compiler includes so we add a link to the existing stubs-64.h. Also, some Xen Python scripts are installed in /usr/local/lib64/python-2.7/site-packages which python cannot find so we add links from the standard library as well.

# cd /usr/include/gnu
# ln -s stubs-64.h stubs-32.h
# cd
# tar -C /usr/local -xvf xen-x.y.z.tar.gz
# cd /usr/local
# chown -R root:root xen-x.y.z
# cd xen-x.y.z
# ./configure --libdir=/usr/local/lib64 --with-initddir=/etc/rc.d
# make world
# make install
# make clean
# cd ../lib64/python2.7/site-packages
# ln -s xen /usr/lib64/python2.7/site-packages
# ln -s xen-3.0-py2.7.egg-info /usr/lib64/python2.7/site-packages

Adjusting rc.local*

Xen needs a couple of daemons to run to ensure VM management. Add these lines to rc.local and rc.local_shutdown :

PATH=/usr/local/sbin:/usr/local/bin:$PATH
export PATH

# start xencommons
if [ -x /etc/rc.d/xencommons ]; then
    /etc/rc.d/xencommons start
fi

# stop xencommons
if [ -x /etc/rc.d/xencommons ]; then
    /etc/rc.d/xencommons stop
fi

Compiling a dom0 Kernel

Domain-0 (dom0 for short) is a special guest (virtual machine) that the Xen hypervisor always loads on host startup. Dom0 is used to control and manage the Xen hypervisor, and provides virtual disks and networks for other unprivileged guests (=domUs). Dom0 support was introduced in Linux kernel 3.0. The kernel generated must include the .config file domU and dom0 options. Here is a minimal example of such a .config dom0 file. Feel free to use it as a base, replacing device drivers as required. The rest of the kernel compilation is nominal :

# tar -C /usr/src -xvf linux-4.4.88.tar.bz2
# cd /usr/local
# rm linux
# ln -s linux-4.4.88 linux
# cd linux
# make menuconfig
# make
# make modules_install
# cp arch/x86_64/boot/bzImage /boot/vmlinuz-4.4.88-dom0
# cp System.map /boot/System.map-4.4.88-dom0
# cp .config /boot/config-4.4.88-dom0

We're now all set up, Xen is ready to be booted by grub2 !


Compiling from Source Main Page Using Grub2