Xen Dom0: Difference between revisions

From Alpine Linux
(network tips)
m (Change link to Repositories page)
(25 intermediate revisions by 13 users not shown)
Line 1: Line 1:
So before anything else verify that you can '''reliably''' log into your Alpine box through [[Setting_up_a_ssh-server|SSH]], because with some video chipset (intel in my case) xen will blank your screen so you will have to use SSH.
This guide will show you how to set up your 'sys' install of Alpine as a Xen Dom0. You can start from either an existing standard install or install a new copy of Alpine with the Alpine Xen ISO.


Then upgrade your setup to [[Upgrading_to_Edge|Edge/testing]] (as of the date of writing, Xen is only available in Edge). Install Xen:
== 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. Replace <code>/dev/sdx</code> with the drive letter of your USB device:
<pre>dd if=alpine-xen-3.12.0-x86_64.iso of=/dev/sdx</pre>


{{Cmd|apk add xen}}
==== Installation ====
Boot from your CD or USB device, 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.
Select what will become 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.}}
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>
# xen-hypervisor isn't installed by default with Xen so we must install it manually
apk add xen-hypervisor
apk add bridge
</pre>


Modify your extlinux.cfg (credits: http://lists.alpinelinux.org/alpine-devel/1406.html)
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. Replace 3.12 and 4.13.1 with your Linux and Xen version numbers, respectively.
since video card is not working for now, we will use a serial console:


After this, [[Repositories#Enabling_the_community_repository|enable the Alpine community repository]] and install the firmware to be used for Xen's virtual machines:
<pre>
<pre>
SERIAL 0 115200
apk add seabios ovmf
DEFAULT menu.c32
</pre>
PROMPT 0
MENU TITLE Alpine/Linux Boot Menu
MENU HIDDEN
MENU AUTOBOOT Alpine will be booted automatically in # seconds.
TIMEOUT 50
LABEL 0
  MENU DEFAULT
  MENU LABEL Linux 2.6.38.8-vs2.3.0.37-rc17
  KERNEL vmlinuz-2.6.38.8-vs2.3.0.37-rc17
  APPEND initrd=initramfs-2.6.38.8-vs2.3.0.37-rc17 root=UUID=f40e340b-ea49-445b-81c0-4d7104b56662 modules=sd-mod,usb-storage,ext4 quiet


LABEL 1
Now you are ready to configure GRUB.
  MENU LABEL Linux 2.6.36.3-scst
  KERNEL vmlinuz-2.6.36.3-scst
  APPEND initrd=initramfs-2.6.36.3-scst root=UUID=f40e340b-ea49-445b-81c0-4d7104b56662 modules=sd-mod,usb-storage,ext4 quiet


LABEL 2
=== Existing installation ===
  MENU LABEL Linux 2.6.38.8-grsec
First you must [[Repositories#Enabling_the_community_repository|enable the Alpine community repository]], then install Xen and the seabios (BIOS) and ovmf (UEFI) firmwares for its virtual machines.
  KERNEL vmlinuz-2.6.38.8-grsec
  APPEND initrd=initramfs-2.6.38.8-grsec root=UUID=f40e340b-ea49-445b-81c0-4d7104b56662 modules=sd-mod,usb-storage,ext4 quiet


LABEL 3
<pre>
  MENU LABEL XEN
# apk add xen xen-hypervisor seabios ovmf
  KERNEL mboot.c32
  APPEND /boot/xen-4.gz loglvl=all guest_loglvl=all com1=115200,8n1 console=com1 dom0_mem=256M --- /boot/vmlinuz-grsec root=UUID=f40e340b-ea49-445b-81c0-4d7104b56662 modules=sd-mod,usb-storage,ext4 console=hvc0 earlyprintk=xen nomodeset --- /boot/initramfs-grsec
</pre>
</pre>
Of course replace root=UUID= with '''your''' UUID in yours.


xl info won't work
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.
 
Start xecommons:
<pre>
alpine:/boot# /etc/init.d/xencommons start
Starting xenstored...FATAL: Failed to open evtchn device: No such file or directory
</pre>
well this will fail but xl info will work anyway


Oh but wait, evtchn device is built in the kernel, so why is there no /dev/xen/evtch file ?
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:
let's start udev ! ;)
<pre>echo "xen-netback" >> /etc/modules
{{Cmd|rc-service udev start}}
echo "xen-blkback" >> /etc/modules
echo "tun" >> /etc/modules</pre>
Then lastly we add the Xen daemons to the default runlevel.
<pre>rc-update add xenconsoled
rc-update add xendomains
rc-update add xenqemu
rc-update add xenstored</pre>
Reboot.


That's all folks !
== GRUB configuration ==
Once running a Xen kernel, you 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># You need to set the amount of RAM to allocate to the Dom0 Alpine install so that
# our future virtual machines will have enough memory.
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=1024M,max:1024M"


on going debug:
GRUB_DEFAULT="saved"
vi /etc/rc.conf
GRUB_SAVEDEFAULT="true"</nowiki>}}
rc_sys="xen0"
You can replace 1024M with the amount of memory you want to allocate to your Dom0 operating system.
why ?
After that, 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>
That sets the 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.


Commands recap:
In Alpine Linux, you will need to add the ''max_loop'' option to the ''loop'' module, then add the loop module to your initramfs.
{{Cmd|
apk add xen
apk add udev
rc-service udev start ; rc-service udev-postmount start
rc-service xencommons start
}}
If you want "xm" command
{{Cmd|rc-service xend start}}


So let's install services at boot time :
Start by populating <code>/etc/modprobe.d/loop.conf</code> with the module options:
{{Cmd|
rc-update add udev sysinit
rc-update add udev-postmount default
rc-update add xencommons
rc-update add xend
}}


since we use a serial line, let'a add a serial console prompt, modify your /etc/inittab accordinly:
<pre>
# touch /etc/modprobe.d/loop.conf
# echo "options loop max_loop=32" > /etc/modprobe.d/loop.conf
</pre>


# Put a getty on the serial port
Update initramfs to reflect the module options:
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
hvc0::respawn:/sbin/getty -L hvc0 115200 vt100


hvc0 is Xen console output, where we have already redirected the kernel messages.
<pre>
To switch to Xen console, type three time "Ctrl+a"
# mkinitfs
# reboot
</pre>


Now you can configure your guest, but before don't forget to load Xen kernel module:
== See also ==
{{Cmd|modprobe xen-gntdev
* [[Xen Dom0 on USB or SD]]
modprobe xen-gntalloc
* [https://wiki.gentoo.org/wiki/Xen#Host_configuration_.28domain-0.29|Xen page on Gentoo wiki]
modprobe tun
[[Category:Virtualization]]
echo "xen-gntdev" >> /etc/modules
echo "xen-gntalloc" >> /etc/modules
echo "tun" >> /etc/modules
}}
Yes, tun is not a Xen module but is needed to create tap interface in Dom0.
Before creating your VM don't forget to create xenbr0 bridge, otherwise Xen will change eth0 into peth0 and eth0 will become a bridge (!):
{{Cmd|
brctl addbr xenbr0
ifconfig xenbr0 up
}}
So now if you want to plug your "real" network card in your bridge: (192.168.1.10 is eth0 ip)
{{Cmd|
ifconfig eth0 0.0.0.0
brctl addif xenbr0 eth0
ifconfig xenbr0 192.168.1.10
}}

Revision as of 04:38, 27 June 2022

This guide will show you how to set up your 'sys' install of Alpine as a Xen Dom0. You can start from either 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. Replace /dev/sdx with the drive letter of your USB device:

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

Installation

Boot from your CD or USB device, 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. Select what will become 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.

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. Replace 3.12 and 4.13.1 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

Reboot.

GRUB configuration

Once running a Xen kernel, you 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

# You need to set the amount of RAM to allocate to the Dom0 Alpine install so that # our future virtual machines will have 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 that, 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)"

That sets the 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

Update initramfs to reflect the module options:

# mkinitfs
# reboot

See also