Xen Dom0: Difference between revisions

From Alpine Linux
(extlinux.cfg does not exist. Fixed to extlinux.conf)
No edit summary
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This guide will show you how to perform a Xen Dom0 install on a HDD, so you can have your Dom0. The first step is to perform a normal HDD install of Alpine Linux, which can be accomplished following the guide [[Install to disk]]. Once the install is finished, and you have rebooted into your new system, it's time to install the Xen packages:
This guide will show you how to have your 'sys' install of Alpine run as a Xen Dom0. You can start either from an existing standard install or install a new copy of Alpine with the Alpine Xen ISO.


== Install Xen ==
=== New installation ===
==== Writing the medium ====
{{Warning|This will erase '''everything''' on the drive you point it at. Check and double check that <code>/dev/sdx</code> is the correct USB device you want to write to, using the commands <code>lsblk</code> and <code>blkid</code>.}}
First download Alpine's [https://www.alpinelinux.org/downloads/ Xen install ISO], and either [[Burning ISOs|burn the ISO to a CD/DVD]] or write it to a USB storage device with the following command, where <code>3.12.0</code> should be replaced with the release number of your downloaded ISO and <code>/dev/sdx</code> should be replaced with the drive letter of your USB:
<pre>dd if=alpine-xen-3.12.0-x86_64.iso of=/dev/sdx</pre>
==== Installation ====
Now boot from your CD or USB, and type 'root' when prompted for a username. After you have logged in run <code>setup-xen-dom0</code>, then continue with a standard [[Install to disk|Alpine installation]] until you get to the prompt asking to choose your network card.
What you'll want to do is select what is to be your internet-facing interface, and when asked to bridge it type 'yes'. Then you can configure the networking settings of your bridge device, <code>br0</code>, as you would have configured your internet-facing interface.
{{Note|You cannot bridge a WiFi interface in the automatic installation script due to incompatible protocols. Make sure you pick an ethernet interface for this.}}
Now continue with your installation to disk until you reach the 'reboot' prompt. There are a few more things to do before you can boot without errors:
<pre>
<pre>
# apk add xen xen-hypervisor seabios
# xen-hypervisor isn't installed by default with Xen so we must install it manually
apk add xen-hypervisor
apk add bridge
</pre>
</pre>


Then [https://wiki.alpinelinux.org/wiki/Enable_Community_Repository enable the community repositories] and install ovmf from community.
Now you can safely reboot after removing your install medium, making sure to pick the <code>Alpine Linux v3.12, with Xen 4.13.1 and Linux lts</code> boot option in your GRUB menu, with 3.12 and 4.13.1 replaced with your Linux and Xen version numbers, respectively.


After this, [[Enable Community Repository|enable the Alpine community repository]] and install the firmware to be used for Xen's virtual machines:
<pre>
<pre>
# apk add ovmf
apk add seabios ovmf
</pre>
</pre>


Now you are ready to configure GRUB.


'''seabios''' and '''ovmf''' provide BIOS and UEFI firmwares for Xen virtual machines. Please be advised that ovmf is part of the community repository. In order to download it, you will need to add the community repository to [[Alpine_Linux_package_management#Packages_and_Repositories|your configuration]].
=== Existing installation ===
 
First you must [[Enable Community Repository|enable the Alpine community repository]], then install Xen and the seabios (BIOS) and ovmf (UEFI) firmwares for its virtual machines.
This will install Xen Hypervisor, xl cli command and all the required packages. The next step is to modify your extlinux.conf and add an entry to boot Xen:
 
Normal boot:
 
<pre>
LABEL xen
  KERNEL /boot/mboot.c32
  APPEND /boot/xen.gz --- /boot/grsec root=UUID=<YOUR-DISK-UUID> modules=ext4 --- /boot/grsec.gz
</pre>


Serial console boot:
<pre>
<pre>
LABEL xen
# apk add xen xen-hypervisor seabios ovmf
  KERNEL /boot/mboot.c32
  APPEND /boot/xen.gz com1=115200,8n1 console=com1 --- /boot/grsec root=UUID=<YOUR-DISK-UUID> modules=ext4  --- /boot/grsec.gz
</pre>
</pre>


{{Note|<nowiki>remember to change <YOUR-DISK-UUID> with the UUID of your boot disk (you can copy it from the normal Alpine Linux boot entry)</nowiki>}}
This will install Xen Hypervisor, xl cli command and all the required packages. The next step is to modify your GRUB configuration to properly boot Xen.
 
com1=115200,8n1 console=com1 redirect xen and dom0 to a physical serial port, handy if you want to use a serial null modem cable instead of a keyboard+monitor combo or if your server has an kvm over ip.
 
It's also a good idea to check [http://wiki.xen.org/wiki/Xen_Hypervisor_Boot_Options Xen Boot options] and set dom0_mem, dom0_vcpus_pin and dom0_max_vcpus at least.


The next step is to load the necessary kernel modules for Xen, we will add them to /etc/modules, so they will be loaded automatically on boot:
The next step is to load the necessary kernel modules for Xen, we will add them to /etc/modules, so they will be loaded automatically on boot:
 
<pre>echo "xen-netback" >> /etc/modules
<pre>
echo "xen-blkback" >> /etc/modules
# echo "xen_netback" >> /etc/modules
echo "tun" >> /etc/modules</pre>
# echo "xen_blkback" >> /etc/modules
Then lastly we add the Xen daemons to the default runlevel.
# echo "tun" >> /etc/modules
<pre>rc-update add xenconsoled
</pre>
 
The last step is to configure startup services, we will need udev and xencommons at least to be started on boot:
 
<pre>
rc-update add xenconsoled
rc-update add xendomains
rc-update add xendomains
rc-update add xenqemu
rc-update add xenqemu
rc-update add xenstored
rc-update add xenstored</pre>
</pre>
Now reboot.


Ok, now you have a fully functional Xen install, it's time to boot into it.
== GRUB configuration ==
Once running a Xen kernel we will need to edit its command-line options and enable the setting of a default GRUB entry by inserting this at the bottom of <code>/etc/default/grub</code>:
{{Cat|/etc/default/grub|<nowiki># We need to set the amount of RAM we allocate to our Dom0 Alpine install so that
# our future virtual machines are left with enough memory.
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=1024M,max:1024M"


<pre>
GRUB_DEFAULT="saved"
# reboot
GRUB_SAVEDEFAULT="true"</nowiki>}}
You can replace 1024M with the amount of memory you want to allocate to your Dom0 operating system.
After this you need to run the following:
<pre>grub-mkconfig -o /boot/grub/grub.cfg
grub-set-default "$(grep ^menuentry /boot/grub/grub.cfg | grep Xen | cut -d \' -f 2 | head -1)"
</pre>
</pre>
 
What this does is set your default entry in GRUB to the first entry containing 'Xen'. Run this every time you upgrade Alpine or Xen.
Also remember to configure at least one network bridge following the [[Bridge]] guide.


== Loop Devices ==
== Loop Devices ==
Line 83: Line 84:
== See also ==
== See also ==
* [[Xen Dom0 on USB or SD]]
* [[Xen Dom0 on USB or SD]]
 
* [https://wiki.gentoo.org/wiki/Xen#Host_configuration_.28domain-0.29|Xen page on Gentoo wiki]
[[Category:Virtualization]]
[[Category:Virtualization]]

Revision as of 08:18, 27 August 2020

This guide will show you how to have your 'sys' install of Alpine run as a Xen Dom0. You can start either from an existing standard install or install a new copy of Alpine with the Alpine Xen ISO.

Install Xen

New installation

Writing the medium

Warning: This will erase everything on the drive you point it at. Check and double check that /dev/sdx is the correct USB device you want to write to, using the commands lsblk and blkid.


First download Alpine's Xen install ISO, and either burn the ISO to a CD/DVD or write it to a USB storage device with the following command, where 3.12.0 should be replaced with the release number of your downloaded ISO and /dev/sdx should be replaced with the drive letter of your USB:

dd if=alpine-xen-3.12.0-x86_64.iso of=/dev/sdx

Installation

Now boot from your CD or USB, and type 'root' when prompted for a username. After you have logged in run setup-xen-dom0, then continue with a standard Alpine installation until you get to the prompt asking to choose your network card. What you'll want to do is select what is to be your internet-facing interface, and when asked to bridge it type 'yes'. Then you can configure the networking settings of your bridge device, br0, as you would have configured your internet-facing interface.

Note: You cannot bridge a WiFi interface in the automatic installation script due to incompatible protocols. Make sure you pick an ethernet interface for this.

Now continue with your installation to disk until you reach the 'reboot' prompt. There are a few more things to do before you can boot without errors:

# xen-hypervisor isn't installed by default with Xen so we must install it manually
apk add xen-hypervisor
apk add bridge

Now you can safely reboot after removing your install medium, making sure to pick the Alpine Linux v3.12, with Xen 4.13.1 and Linux lts boot option in your GRUB menu, with 3.12 and 4.13.1 replaced with your Linux and Xen version numbers, respectively.

After this, enable the Alpine community repository and install the firmware to be used for Xen's virtual machines:

apk add seabios ovmf

Now you are ready to configure GRUB.

Existing installation

First you must enable the Alpine community repository, then install Xen and the seabios (BIOS) and ovmf (UEFI) firmwares for its virtual machines.

# apk add xen xen-hypervisor seabios ovmf

This will install Xen Hypervisor, xl cli command and all the required packages. The next step is to modify your GRUB configuration to properly boot Xen.

The next step is to load the necessary kernel modules for Xen, we will add them to /etc/modules, so they will be loaded automatically on boot:

echo "xen-netback" >> /etc/modules
echo "xen-blkback" >> /etc/modules
echo "tun" >> /etc/modules

Then lastly we add the Xen daemons to the default runlevel.

rc-update add xenconsoled
rc-update add xendomains
rc-update add xenqemu
rc-update add xenstored

Now reboot.

GRUB configuration

Once running a Xen kernel we will need to edit its command-line options and enable the setting of a default GRUB entry by inserting this at the bottom of /etc/default/grub:

Contents of /etc/default/grub

# We need to set the amount of RAM we allocate to our Dom0 Alpine install so that # our future virtual machines are left with enough memory. GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=1024M,max:1024M" GRUB_DEFAULT="saved" GRUB_SAVEDEFAULT="true"

You can replace 1024M with the amount of memory you want to allocate to your Dom0 operating system. After this you need to run the following:

grub-mkconfig -o /boot/grub/grub.cfg
grub-set-default "$(grep ^menuentry /boot/grub/grub.cfg | grep Xen | cut -d \' -f 2 | head -1)"

What this does is set your default entry in GRUB to the first entry containing 'Xen'. Run this every time you upgrade Alpine or Xen.

Loop Devices

If you plan to use more than 8 DomU's, you may need to increase the amount of loop-devices in your Dom0.

In Alpine Linux, you will need to add the max_loop option to the loop module, then add the loop module to your initramfs.

Start by populating /etc/modprobe.d/loop.conf with the module options:

# touch /etc/modprobe.d/loop.conf
# echo "options loop max_loop=32" > /etc/modprobe.d/loop.conf

Now reflect the module options in the initramfs:

# mkinitfs
# reboot

See also