Xen Dom0: Difference between revisions

From Alpine Linux
(Category:Virtualization)
(actually hyphens, not underscores)
(16 intermediate revisions by 11 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 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:


Then upgrade your setup to [[Upgrading_to_Edge|Edge/testing]] (as of the date of writing, Xen is only available in Edge). Install Xen:
<pre>
# apk add xen xen-hypervisor seabios
</pre>
 
Then [https://wiki.alpinelinux.org/wiki/Enable_Community_Repository enable the community repositories] and install ovmf from community.
 
<pre>
# apk add ovmf
</pre>
 
 
'''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]].


{{Cmd|apk add xen}}
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:


Modify your extlinux.cfg (credits: http://lists.alpinelinux.org/alpine-devel/1406.html)
Normal boot:
since video card is not working for now, we will use a serial console:


<pre>
<pre>
SERIAL 0 115200
LABEL xen
DEFAULT menu.c32
  KERNEL /boot/mboot.c32
PROMPT 0
  APPEND /boot/xen.gz --- /boot/grsec root=UUID=<YOUR-DISK-UUID> modules=ext4 --- /boot/grsec.gz
MENU TITLE Alpine/Linux Boot Menu
</pre>
MENU HIDDEN
MENU AUTOBOOT Alpine will be booted automatically in # seconds.
TIMEOUT 50


LABEL 0
Serial console boot:
  MENU LABEL XEN
<pre>
   KERNEL mboot.c32
LABEL xen
   APPEND /boot/xen-4.gz iommu=1 dom0_mem=1024M dom0_max_vcpus=2 dom0_vcpus_pin  loglvl=all guest_loglvl=all com1=115200,8n1 console=com1 --- /boot/grsec root=UUID=f40e340b-ea49-445b-81c0-4d7104b56662 modules=ext4 console=hvc0 earlyprintk=xen nomodeset --- /boot/grsec.gz
   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>


LABEL 1
{{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>}}
  MENU LABEL Linux
  KERNEL grsec
  APPEND initrd=grsec.gz root=UUID=f40e340b-ea49-445b-81c0-4d7104b56662 modules=ext4


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:
<pre>
# echo "xen-netback" >> /etc/modules
# echo "xen-blkback" >> /etc/modules
# echo "tun" >> /etc/modules
</pre>
</pre>
Of course adapt this accordingly to your setup (UUID, modules, etc).


Let's start Xen services:
The last step is to configure startup services, we will need udev and xencommons at least to be started on boot:
{{Cmd|
 
apk add xen
<pre>
apk add udev
rc-update add xenconsoled
rc-service udev start ; rc-service udev-postmount start
rc-update add xendomains
rc-service xencommons start
rc-update add xenqemu
}}
rc-update add xenstored
xl should work. If you want "xm" command
</pre>
{{Cmd|rc-service xend start}}


So let's install services at boot time :
Ok, now you have a fully functional Xen install, it's time to boot into it.
{{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>
<pre>
# Put a getty on the serial port
# reboot
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
hvc0::respawn:/sbin/getty -L hvc0 115200 vt100
</pre>
</pre>
hvc0 is Xen console output, where we have already redirected the kernel messages.
To switch to Xen console, type three time "Ctrl+a"


Now you can configure your guest, but before don't forget to load Xen kernel module:
Also remember to configure at least one network bridge following the [[Bridge]] guide.
{{Cmd|modprobe xen-gntdev
modprobe xen-gntalloc
modprobe tun
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
}}


== 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 <code>/etc/modprobe.d/loop.conf</code> with the module options:
<pre>
# touch /etc/modprobe.d/loop.conf
# echo "options loop max_loop=32" > /etc/modprobe.d/loop.conf
</pre>
Now reflect the module options in the initramfs:
<pre>
# mkinitfs
# reboot
</pre>


on going debug:
== See also ==
vi /etc/rc.conf
* [[Xen Dom0 on USB or SD]]
rc_sys="xen0"
why ?


[[Category:Virtualization]]
[[Category:Virtualization]]

Revision as of 22:03, 27 November 2019

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:

# apk add xen xen-hypervisor seabios

Then enable the community repositories and install ovmf from community.

# apk add ovmf


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 your configuration.

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:

LABEL xen
  KERNEL /boot/mboot.c32
  APPEND /boot/xen.gz --- /boot/grsec root=UUID=<YOUR-DISK-UUID> modules=ext4 --- /boot/grsec.gz

Serial console boot:

LABEL xen
  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
Note: remember to change <YOUR-DISK-UUID> with the UUID of your boot disk (you can copy it from the normal Alpine Linux boot entry)

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 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:

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

The last step is to configure startup services, we will need udev and xencommons at least to be started on boot:

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

Ok, now you have a fully functional Xen install, it's time to boot into it.

# reboot

Also remember to configure at least one network bridge following the Bridge guide.

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