Difference between revisions of "Xen installation"

From ERIKA WIKI
Jump to: navigation, search
(Xen Installation procedure)
 
(18 intermediate revisions by 2 users not shown)
Line 1: Line 1:
The section contains the instruction to install Xen hypervisor on platform x86_64 with one of the following operating system:  
+
== Introduction ==
 +
The section contains the instruction to install Xen hypervisor on platform x86-64.
 +
Furthermore, it contains the procedure for running a guest operating system (i.e., Windows OS) under Xen hypervisor.
 +
 
 +
== Xen Installation procedure ==
 +
The following installation procedure aims at installing Xen RELEASE-4.11.0 from source.
 +
It has been performed on the platform x86-64 with one of the following operating system:  
 
<ul>
 
<ul>
 
<li><i>Ubuntu 16.04</i></li>
 
<li><i>Ubuntu 16.04</i></li>
Line 5: Line 11:
 
</ul>
 
</ul>
  
== Build Dependencies ==
+
<b>Build Dependencies</b><br>
 
 
 
Install the following packages:
 
Install the following packages:
 
   # apt update && apt dist-upgrade #update/upgrade the kernel
 
   # apt update && apt dist-upgrade #update/upgrade the kernel
Line 22: Line 27:
 
   # apt install libc6-dev-i386
 
   # apt install libc6-dev-i386
 
   # apt install lzma lzma-dev liblzma-dev #for rombios
 
   # apt install lzma lzma-dev liblzma-dev #for rombios
   # apt install libsystemd-dev  
+
   # apt install libsystemd-dev xorriso
  
== Retrieve the GRUB version ==
+
<b>Retrieve the GRUB version</b><br>
 
The Xen installation strictly depends on the installed Grub version: <code>grub-pc</code> or <code>grub-efi</code>.
 
The Xen installation strictly depends on the installed Grub version: <code>grub-pc</code> or <code>grub-efi</code>.
 
In order to retrieve the grub version, launch the following command:
 
In order to retrieve the grub version, launch the following command:
 
   $ dpkg --get-selections | grep grub
 
   $ dpkg --get-selections | grep grub
  
== Xen Installation ==
+
<b>Retrieve Xen source</b><br>
 
 
<b>Retrieve Xen source</b>
 
 
 
 
Clone the Xen repository and switch to the chosen version (i.e., <code>RELEASE 4.11</code>):
 
Clone the Xen repository and switch to the chosen version (i.e., <code>RELEASE 4.11</code>):
  
Line 41: Line 43:
 
In the following part of the tutorial, we refer to the Xen repository path as <code>$XENPATH</code>.
 
In the following part of the tutorial, we refer to the Xen repository path as <code>$XENPATH</code>.
  
<b>Configure</b>
+
<b>Configure</b><br>
 
 
 
Configure:
 
Configure:
 
   $ $XENPATH/configure --enable-systemd
 
   $ $XENPATH/configure --enable-systemd
  
In case of Xen EFI (as for example in <i>Ubuntu 18.04.01</i>), add the option <code>--enable-targets=x86_64-pep</code> as follows:
+
In case of Xen EFI, add the option <code>--enable-targets=x86_64-pep</code> as follows:
 
   $ $XENPATH/configure --enable-systemd --enable-targets=x86_64-pep
 
   $ $XENPATH/configure --enable-systemd --enable-targets=x86_64-pep
  
<b>Build and install</b>
+
<b>Build and install</b><br>
 
 
 
Build all components (hypervisor, tools, docs, stubdomains, etc):
 
Build all components (hypervisor, tools, docs, stubdomains, etc):
 
   $ cd $XENPATH
 
   $ cd $XENPATH
Line 56: Line 56:
  
 
Install (as root):
 
Install (as root):
   # make install
+
   # sudo make install
  
<b>Enable the Xen services</b>
+
<b>Enable the Xen services</b><br>
 
Reload dynamic libraries:
 
Reload dynamic libraries:
   # /sbin/ldconfig
+
   # sudo /sbin/ldconfig
  
 
Enable systemd Xen services:
 
Enable systemd Xen services:
   # systemctl enable xen-qemu-dom0-disk-backend.service
+
   # sudo systemctl enable xen-qemu-dom0-disk-backend.service
   # systemctl enable xen-init-dom0.service
+
   # sudo systemctl enable xen-init-dom0.service
   # systemctl enable xenconsoled.service
+
   # sudo systemctl enable xenconsoled.service
   # systemctl enable xenstored.service
+
   # sudo systemctl enable xenstored.service
   # systemctl enable xendomains.service
+
   # sudo systemctl enable xendomains.service
 
Note that in case of error for enabling xendomains service, remove <code>/etc/init.d/xendomains</code>.
 
Note that in case of error for enabling xendomains service, remove <code>/etc/init.d/xendomains</code>.
  
== Grub setup ==
+
<b>Configure grub</b><br>
<b>Grub-pc</b> (e.g., <i>Ubuntu 16.04</i>)
+
Modify the configuration to show the Grub menu. Change the following line from <code>/etc/default/grub</code>:
 +
  GRUB_TIMEOUT_STYLE=hidden
 +
by setting the following value:
 +
  GRUB_TIMEOUT_STYLE=menu
 +
In order to enable the Xen log messages on the serial port, add the following line:
 +
  GRUB_CMDLINE_XEN="loglvl=all guest_loglvl=all com1=115200,8n1,0x3e8,5 console=com1,vga cpufreq=xen:performance max_cstate=0"
 +
where:
 +
<ul>
 +
<li><code>loglvl=all</code> : set the logging level for Xen
 +
<li><code>guest_loglvl=all</code> : set the logging level for Xen guests
 +
<li><code>com1=115200,8n1,0x3e8,5</code> : specifies the UART parameters
 +
<li><code>console=com1,vga</code> : specifies which console Xen should use
 +
<li><code>cpufreq=xen:performance</code> : sets the power management governor policy to performance
 +
<li><code>max_cstate=0</code> : defines the power modes, called “C-states”, are permitted. Set the power mode to 0, implies that the CPU fully turned on
 +
</ul>
 +
 
 +
<b>Update grub</b><br>
 +
Finally, update grub and reboot:
 +
  # sudo udate-grub
 +
  # sudo reboot
 +
 
 +
== Example: Creating a Windows HVM (Hardware Virtualized) Guest ==
 +
In order to create a Windows HVM (Hardware Virtualized) Guest, performs the following operations:
 +
<ul>
 +
<li> Setup the LVM storage
 +
</li>
 +
<li> Setup Linux Bridge in order to attach guest machines to the external network
 +
</li>
 +
<li> Install Windows OS on the Xen HVM Guest
 +
</li>
 +
<li> Run Windows OS on the Xen HVM Guest
 +
</li>
 +
</ul>
 +
 
 +
=== Setup LVM storage ===
 +
LVM, Logical Volume Manager, allows Linux to manage block devices in a more abstract manner. LVM creates ''logical volumes'' within a ''volume group'' that can share the same physical storage, known as ''physical volume''.
 +
The LVM setup process can be summarized as allocating a physical volume, creating a volume group on top of this, then creating logical volumes to store data.
 +
 
 +
Install LVM:
 +
  # sudo apt-get install lvm2
 +
 
 +
Create a physical partition (if there none free) by using a partition manager (e.g., <code>gparted</code>).
 +
Create a physical volume associated with the physical partition (e.g., <code>/dev/XenVolumeGroup</code>):
 +
  # sudo pvcreate /dev/XenVolumeGroup
 +
 
 +
Create a volume group, called <code>vg0</code>, using this physical volume:
 +
  # sudo vgcreate vg0 /dev/XenVolumeGroup
 +
 
 +
Finally, create a new logical volume, named <code>windows</code>, of 50Gbytes size on the volume group <code>vg0</code>:
 +
  # sudo lvcreate -n windows -L 50G vg0
 +
 
 +
=== Setup Linux Bridge for guest networking ===
 +
In order to allow network access to the Xen guests, the Linux bridge package allows to create a virtual switch within Dom0. The switch will take packets from the virtual machines and forward them on to the physical network.
 +
 
 +
In order to install the Linux bridge package and its core component, launch the following command:
 +
  # sudo apt-get install bridge-utils
 +
 
 +
In case of Linux bridge configured by DHCP, edit <code>/etc/network/interfaces</code> file as follows:
 +
  auto xenbr0
 +
  iface xenbr0 inet dhcp
 +
    bridge_ports <your-network-interface>
 +
where <code> <your-network-interface></code> is the physical interface (e.g., <code>eth0</code>).
 +
 
 +
In case of static Linux bridge, edit <code>/etc/network/interfaces</code> file as follows:
 +
  auto xenbr0
 +
  iface xenbr0 inet static
 +
    bridge_ports <your-network-interface>
 +
    address <bridge-address>
 +
    netmask 255.255.255.0
 +
    gateway <gtw-address>
 +
    broadcast <bcast-address>
 +
 
 +
where <code> <your-network-interface></code> is the physical interface (e.g., <code>eth0</code>) and
 +
<code><bridge-address></code>, <code><bridge-address></code> and <code><bridge-address></code> are respectively the address assigned to the Linux bridge, the gateway address and the broadcast address.
  
Update grub and reboot:
+
Then, restart networking:
   # udate-grub
+
   # sudo service networking restart
  # reboot
 
  
<b>Grub-efi</b> (e.g., <i>Ubuntu 18.04.01</i>)
+
In case of correct setup, the command <code>brctl</code> will show the bridge setup:
 +
  $ brctl show
 +
 
 +
  bridge name    bridge id              STP enabled    interfaces
 +
  xenbr0 8000.006065444af1 no      <your-network-interface>
  
Remove the entry created for Grub-pc (it will no work since the installed grub is UEFI):
+
=== Install Windows OS on the Xen HVM Guest ===
  # rm /etc/grub.d/20_linux_xen
 
  
Create the Xen UEFI entry as follows:
+
It follows an example of configuration file, referred to as <code>windows.cfg</code> to enable the installation of Windows on the logical volume.  
  # mkdir /boot/efi/EFI/xen
 
  # cp /usr/lib64/efi/xen.efi /boot/efi/EFI/xen
 
  # cp /boot/vmlinuz-$VERSION /boot/efi/EFI/xen
 
  # cp /boot/initrd.img-$VERSION /boot/efi/EFI/xen/
 
where $VERSION is the chosen version of the Linux kernel and initramdisk that MUST reside in the same directory as <code>xen.efi</code>.
 
  
Create the <code>xen.cfg</code> file in <code>/boot/efi/EFI/xen/</code>:
+
  #Domain Name
 +
  name="win"
 +
 
 +
  #Virtualization type
 +
  builder="hvm"
 +
 
 +
  #Initial memory allocation (MB)
 +
  memory=4096
 +
 
 +
  #Number of virtual CPUs to use
 +
  vcpus=2
 +
 
 +
  #Disk device to a domain
 +
  disk=['file:/dev/XenVolumeGroup/windows,hda,w', 'file:/root/windows.iso,hdb:cdrom,r']
 +
  #Order of disk boot devices: (a) floppy, (c) hard-disk, (n) network and (d) cd-rom
 +
  boot="d"
 +
 
 +
  #Networking
 +
  vif=['type=ioemu, bridge=xenbr0']
 +
 
 +
  #Grahics: vnc/sdl
 +
  vnc=1
 +
  sdl=0
 +
 
 +
  #Domain behaviour
 +
  on_poweroff="destroy"
 +
  on_reboot="preserve"
 +
  on_crash="preserve"
 +
 
 +
  #Other options
 +
  stdvga=0
 +
  usb=1
 +
  usbdevice="tablet"
 +
  ide0="noprobe"
 +
  serial="pty"
  
  [global]
+
Let us assume that the Windows iso is located in <code>/root/windows.iso</code> file. Then the configuration disk option will contain the reference to such file exported to the domain as <code>hdb:cdrom</code> device. Furthermore, the configuration disk option will contain reference to the logical volume <code>/dev/XenVolumeGroup/windows</code> exported to the domain as <code>hda</code> device.
  default=ubuntu
+
In order to launch the installer, the <code>boot</code> option will point to the cd-rom ISO installation (i.e., <code>boot="d"</code>).
  [ubuntu]
+
    
  options=console=vga,com1 com1=115200,8n1 iommu=verbose ucode=scan flask=disabled conring_size=2097152  loglvl=all
+
Launch the following command to start the guest:
   kernel=vmlinuz-$VERSION root=UUID=$ROOT_UUID ro quiet vt.handoff=7 console=hvc0
+
   # sudo xl create windows.cfg
   ramdisk=initrd.img-$VERSION
 
  
where <code>$VERSION</code> is the chosen version moved into <code>/boot/efi/EFI/xen</code> and <code>ROOT_UUID</code> is the identifier of the Ubuntu partition (note: command used <code>cat /proc/cmdline</code>).
+
Since the <code>vnc</code> option is enabled in the configuration file, the VNC display should be available on default port 5900 of the Dom0 IP. Use a client application to connect to the VCN server (e.g., <code>gvncviewer</code>, Remmina and so forth).  
 +
  $ gvncviewer <dom0-ip-address>:5900
  
Create an entry for Grub <code>/etc/grub.d/20_linux_xen_efi</code>:
+
Then, proceed with Windows OS installation. At the end of installation, destroy the domain in order to prevent the booting from CD-ROM:
  menuentry "Ubuntu GNU/Linux, with Xen EFI hypervisor" {
+
  # sudo xl destroy win
    insmod part_gpt
+
where <code>win</code> is the domain guest defined in the configuration file.
    insmod search_fs_uuid
 
    insmod chain
 
    chainloader (hd0,gpt1)/EFI/XEN/xen.efi
 
  }
 
  
  # chmod +x /etc/grub.d/20_linux_xen_efi
+
=== Run Windows OS on the Xen HVM Guest ===
  
Update grub and reboot:
+
After installing the Windows on the logical volume, change the boot line in the configuration file (i.e., <code>windows.cfg</code>)
  # udate-grub
+
  boot="c"
  # reboot
+
so that the domain will boot from the hard-disk (i.e., logical volume <code>/dev/XenVolumeGroup/windows</code> ).
  
<b>Grub menu fix-up</b>
+
Then, start the domain:
 +
  $ xl create windows.cfg
  
Note, in case of no Grub menu at start-up, modify the following grub configuration parameter in <code>/etc/default/grub</code>:
+
and reconnect with VNC to have access to the Windows GUI.
  GRUB_TIMEOUT_STYLE=text
 
  GRUB_TIMEOUT=5
 

Latest revision as of 16:30, 27 September 2019

Introduction

The section contains the instruction to install Xen hypervisor on platform x86-64. Furthermore, it contains the procedure for running a guest operating system (i.e., Windows OS) under Xen hypervisor.

Xen Installation procedure

The following installation procedure aims at installing Xen RELEASE-4.11.0 from source. It has been performed on the platform x86-64 with one of the following operating system:

  • Ubuntu 16.04
  • Ubuntu 18.04.1 LTS

Build Dependencies
Install the following packages:

 # apt update && apt dist-upgrade #update/upgrade the kernel
 # apt install build-essential
 # apt install bcc bin86 gawk bridge-utils iproute2 
 # apt install libcurl4 libcurl4-openssl-dev bzip2 module-init-tools transfig tgif
 # apt install texinfo texlive-latex-base texlive-latex-recommended texlive-fonts-extra texlive-fonts-recommended
 # apt install pciutils-dev mercurial
 # apt install make gcc libc6-dev zlib1g-dev python python-dev python-twisted 
 # apt install libncurses5-dev patch libsdl-dev libjpeg-dev
 # apt install libvncserver-dev
 # apt install iasl libbz2-dev e2fslibs-dev git-core uuid-dev 
 # apt install ocaml ocaml-findlib libx11-dev bison flex xz-utils libyajl-dev
 # apt install gettext libpixman-1-dev libaio-dev markdown pandoc
 # apt install libc6-dev-i386
 # apt install lzma lzma-dev liblzma-dev #for rombios
 # apt install libsystemd-dev xorriso

Retrieve the GRUB version
The Xen installation strictly depends on the installed Grub version: grub-pc or grub-efi. In order to retrieve the grub version, launch the following command:

 $ dpkg --get-selections | grep grub

Retrieve Xen source
Clone the Xen repository and switch to the chosen version (i.e., RELEASE 4.11):

 $ git clone https://github.com/xen-project/xen.git
 $ cd xen
 $ git checkout RELEASE-4.11.0 -b RELEASE-4.11.0

In the following part of the tutorial, we refer to the Xen repository path as $XENPATH.

Configure
Configure:

 $ $XENPATH/configure --enable-systemd

In case of Xen EFI, add the option --enable-targets=x86_64-pep as follows:

 $ $XENPATH/configure --enable-systemd --enable-targets=x86_64-pep

Build and install
Build all components (hypervisor, tools, docs, stubdomains, etc):

 $ cd $XENPATH
 $ make dist

Install (as root):

 # sudo make install

Enable the Xen services
Reload dynamic libraries:

 # sudo /sbin/ldconfig

Enable systemd Xen services:

 # sudo systemctl enable xen-qemu-dom0-disk-backend.service
 # sudo systemctl enable xen-init-dom0.service
 # sudo systemctl enable xenconsoled.service
 # sudo systemctl enable xenstored.service
 # sudo systemctl enable xendomains.service

Note that in case of error for enabling xendomains service, remove /etc/init.d/xendomains.

Configure grub
Modify the configuration to show the Grub menu. Change the following line from /etc/default/grub:

  GRUB_TIMEOUT_STYLE=hidden

by setting the following value:

  GRUB_TIMEOUT_STYLE=menu

In order to enable the Xen log messages on the serial port, add the following line:

  GRUB_CMDLINE_XEN="loglvl=all guest_loglvl=all com1=115200,8n1,0x3e8,5 console=com1,vga cpufreq=xen:performance max_cstate=0"

where:

  • loglvl=all : set the logging level for Xen
  • guest_loglvl=all : set the logging level for Xen guests
  • com1=115200,8n1,0x3e8,5 : specifies the UART parameters
  • console=com1,vga : specifies which console Xen should use
  • cpufreq=xen:performance : sets the power management governor policy to performance
  • max_cstate=0 : defines the power modes, called “C-states”, are permitted. Set the power mode to 0, implies that the CPU fully turned on

Update grub
Finally, update grub and reboot:

 # sudo udate-grub
 # sudo reboot

Example: Creating a Windows HVM (Hardware Virtualized) Guest

In order to create a Windows HVM (Hardware Virtualized) Guest, performs the following operations:

  • Setup the LVM storage
  • Setup Linux Bridge in order to attach guest machines to the external network
  • Install Windows OS on the Xen HVM Guest
  • Run Windows OS on the Xen HVM Guest

Setup LVM storage

LVM, Logical Volume Manager, allows Linux to manage block devices in a more abstract manner. LVM creates logical volumes within a volume group that can share the same physical storage, known as physical volume. The LVM setup process can be summarized as allocating a physical volume, creating a volume group on top of this, then creating logical volumes to store data.

Install LVM:

 # sudo apt-get install lvm2

Create a physical partition (if there none free) by using a partition manager (e.g., gparted). Create a physical volume associated with the physical partition (e.g., /dev/XenVolumeGroup):

 # sudo pvcreate /dev/XenVolumeGroup

Create a volume group, called vg0, using this physical volume:

 # sudo vgcreate vg0 /dev/XenVolumeGroup

Finally, create a new logical volume, named windows, of 50Gbytes size on the volume group vg0:

 # sudo lvcreate -n windows -L 50G vg0

Setup Linux Bridge for guest networking

In order to allow network access to the Xen guests, the Linux bridge package allows to create a virtual switch within Dom0. The switch will take packets from the virtual machines and forward them on to the physical network.

In order to install the Linux bridge package and its core component, launch the following command:

  # sudo apt-get install bridge-utils

In case of Linux bridge configured by DHCP, edit /etc/network/interfaces file as follows:

 auto xenbr0
 iface xenbr0 inet dhcp
    bridge_ports <your-network-interface>

where <your-network-interface> is the physical interface (e.g., eth0).

In case of static Linux bridge, edit /etc/network/interfaces file as follows:

 auto xenbr0
 iface xenbr0 inet static
   bridge_ports <your-network-interface>
   address <bridge-address>
   netmask 255.255.255.0
   gateway <gtw-address>
   broadcast <bcast-address>

where <your-network-interface> is the physical interface (e.g., eth0) and <bridge-address>, <bridge-address> and <bridge-address> are respectively the address assigned to the Linux bridge, the gateway address and the broadcast address.

Then, restart networking:

 # sudo service networking restart

In case of correct setup, the command brctl will show the bridge setup:

 $ brctl show
 
 bridge name     bridge id               STP enabled     interfaces
 xenbr0		8000.006065444af1	no      <your-network-interface>

Install Windows OS on the Xen HVM Guest

It follows an example of configuration file, referred to as windows.cfg to enable the installation of Windows on the logical volume.

 #Domain Name
 name="win"
 
 #Virtualization type 
 builder="hvm"
 
 #Initial memory allocation (MB)
 memory=4096
 
 #Number of virtual CPUs to use
 vcpus=2
 
 #Disk device to a domain
 disk=['file:/dev/XenVolumeGroup/windows,hda,w', 'file:/root/windows.iso,hdb:cdrom,r']
 #Order of disk boot devices: (a) floppy, (c) hard-disk, (n) network and (d) cd-rom 
 boot="d"
 
 #Networking
 vif=['type=ioemu, bridge=xenbr0']
 
 #Grahics: vnc/sdl
 vnc=1
 sdl=0
 
 #Domain behaviour
 on_poweroff="destroy"
 on_reboot="preserve"
 on_crash="preserve"
 
 #Other options
 stdvga=0
 usb=1
 usbdevice="tablet"
 ide0="noprobe"
 serial="pty"

Let us assume that the Windows iso is located in /root/windows.iso file. Then the configuration disk option will contain the reference to such file exported to the domain as hdb:cdrom device. Furthermore, the configuration disk option will contain reference to the logical volume /dev/XenVolumeGroup/windows exported to the domain as hda device. In order to launch the installer, the boot option will point to the cd-rom ISO installation (i.e., boot="d").

Launch the following command to start the guest:

 # sudo xl create windows.cfg

Since the vnc option is enabled in the configuration file, the VNC display should be available on default port 5900 of the Dom0 IP. Use a client application to connect to the VCN server (e.g., gvncviewer, Remmina and so forth).

 $ gvncviewer <dom0-ip-address>:5900

Then, proceed with Windows OS installation. At the end of installation, destroy the domain in order to prevent the booting from CD-ROM:

 # sudo xl destroy win

where win is the domain guest defined in the configuration file.

Run Windows OS on the Xen HVM Guest

After installing the Windows on the logical volume, change the boot line in the configuration file (i.e., windows.cfg)

  boot="c"

so that the domain will boot from the hard-disk (i.e., logical volume /dev/XenVolumeGroup/windows ).

Then, start the domain:

  $ xl create windows.cfg

and reconnect with VNC to have access to the Windows GUI.