community.riocities.com
  • Home
  • Categories
  • Tags
  • Archives

Alpine Linux as a XEN dom0 from a USB stick

Contents

  • Preparations
  • Installation on the SLC stick
  • Basic alpine host setup
  • XEN dom0 setup
  • domU installation
  • XEN dom0 mem (optional)
  • dom0 kernel update

Preparations¶

What you need:

  • 1x 16GB SLC USB stick to run the dom0 from
  • 1x 1GB Installer USB stick
  • 1x Laptop or similar to run the setup (initial installation) from

Later (when you are ready to deploy)

  • 1x Proper server to run the alpine dom0 on (e.g. HP MicroServer or similar)

Plug in the Installer USB stick in your workstation an add the alpine-xen iso to it.

from dmesg

[162562.819054] sd 5:0:0:0: [sdb] 2046240 512-byte logical blocks: (1.04 GB/999 MiB)
[162562.823977]  sdb: sdb1

Put the installation iso on the installer usb-stick

$ sudo dd if=/tmp/alpine-xen-3.5.2-x86_64.iso of=/dev/sdb
299008+0 records in
299008+0 records out
153092096 bytes (153 MB) copied, 56.1059 s, 2.7 MB/s
$ sync 

unplug the usb-stick from the workstation.

Installation on the SLC stick¶

Boot the laptop from the installer usb-stick.

When booted connect the 16GB SLC stick as well and then partition it with

  1. Small partition of 1GB for booting the dom0
  2. LVM partition that will be holding supporting domUs

With supporting domUs I am referring to network driver domain and storage driver domain. The storage driver domain for instance uses storage connected to a local PCI exported PCIe card or alternatively bringing in storage via iSCSI from a remote iscsi-target.

Partition table for the SLC USB device:

Disk /dev/sdf: 15.9 GB, 15977152512 bytes
64 heads, 32 sectors/track, 15237 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks  Id System
/dev/sdf1   *           1         955      977904   c Win95 FAT32 (LBA)
/dev/sdf2             956       15237    14624768  8e Linux LVM

Note: you might need to unplug/replug the stick after partitioning it.

Run apk add syslinux to install syslinux package

Run modprobe vfat to load the vfat kernel module

Create a file system on the bootable vfat partition

# mkfs.vfat /dev/sdf1

Run the setup-bootable script to add Alpine Linux to the USB stick and make it bootable (replacing sdf with your USB stick name):

Note /media/sdb could be other mountpoint as well (e.g. /media/usb), check in the output of df (before running setup-bootable).

# setup-bootable /media/sdb /dev/sdf1

Now you can reboot the laptop from the 16GB SLC stick (unplug the Installer USB stick).

Basic alpine host setup¶

After reboot, login on console again.

Note: you must setup working networking with Internet access in alpine-setup.

Basic dom0/host setup

# apk add syslinux bridge
# setup-alpine

choose to bridge eth0 if any domUs will share eth0 with dom0, name it br_eth0

 Which disk(s) would you like to use: none
  Enter where to store configs: usb
  Enter apk cache directory: /media/usb/cache

Save changes to the USB drive

dom0:~# lbu commit

XEN dom0 setup¶

dom0:~# setup-xen-dom0
dom0:~# lbu commit

Setup LVM (before continuing make sure what name the stick have by checking df output)

dom0:~# apk add lvm2
dom0:~# rc-update add lvm
dom0:~# pvcreate /dev/sdb2 
 Physical volume "/dev/sdb2" successfully created.
dom0:~# vgcreate vg_domU /dev/sdb2 
 Volume group "vg_domU" successfully created
dom0:~# lbu commit

Install pv-grub2 from edge/testing

dom0:~# echo "@edge http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
dom0:~# apk add grub-xenhost@edge --update-cache

domU installation¶

Now follow Alpine Linux as a XEN domU to setup a network driver domain called fw. Store alpine-extended-3.4.4-x86_64.iso in /media/usb and you can reuse /media/usb/boot/vmlinuz-grsec and /media/usb/boot/initramfs-grsec from the dom0 to boot the domU installer from.

E.g. directory for alpine-extended-3.4.4-x86_64.iso

dom0:~# mkdir /media/usb/domu_installer

Example /etc/xen/fw.cfg

# fw domU

vcpus       = '1'
memory      = '128'

kernel = "/media/usb/boot/vmlinuz-grsec"
ramdisk = "/media/usb/boot/initramfs-grsec"
extra="alpine_dev=hdc:iso9660 modules=loop,squashfs,sd-mod,usb-storage console=hvc0"


disk        = [
                  'file://media/usb/domu_installer/alpine-extended-3.4.4-x86_64.iso,hdc:cdrom,r',
                  'phy:/dev/vg_domU/fw-disk,xvda1,w',
              ]


name        = 'fw'

vif         = [ 'mac=00:16:3E:AA:BB:CC,bridge=br_eth0' ]

on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'

Example creation of storage for the new domU

dom0:~# lvcreate -n fw-disk -L 512M vg_domU
  Logical volume "fw-disk" created.
dom0:~# apk add e2fsprogs
dom0:~# mkfs.ext4 /dev/vg_domU/fw-disk
dom0:~# xl create /etc/xen/fw.cfg -c

Test rest of the steps as described in Alpine Linux as a XEN domU. But make sure to install the iptables and bridge packages as well.

Make the fw domU start at boot

dom0:~# cd /etc/xen/auto
dom0:/etc/xen/auto# ln -s ../fw.cfg 00-fw.cfg
dom0:/etc/xen/auto# rc-update add xendomains
dom0:/etc/xen/auto# lbu commit

XEN dom0 mem (optional)¶

When the dom0 boots from the SLC USB stick the bootloader is syslinux, hence dom0_mem should be configured in syslinux.cfg.

Before editing make the usb stick writeable

dom0:~# mount /media/usb -o remount,rw

Edit /media/usb/boot/syslinux/syslinux.cfg and add dom0_mem=1024M. A lower value will not work as the dom0 is running on a RAM disk.

Example after editing

TIMEOUT 20
PROMPT 1
DEFAULT grsec

LABEL grsec
MENU LABEL Xen/Linux grsec
KERNEL /boot/syslinux/mboot.c32
APPEND /boot/xen.gz  dom0_mem=1024M --- /boot/vmlinuz-grsec modules=loop,squashfs,sd-mod,usb-storage quiet nomodeset --- /boot/initramfs-grsec

After editing make the usb stick readonly

dom0:~# mount /media/usb -o remount,ro

Note: 1024M will not be enough to upgrade the kernel with the update-kernel command.

dom0 kernel update¶

You can update the kernel by putting <hostname>.apkovl.tar.gz on a freshly installed USB stick or with the update-kernel command. However using update-kernel requires more dom0_mem, I use 1536M.

Free space on / need to be about 700MB free for update-kernel to complete.

Example with too little free:

dom0:~# df -h /
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   616.8M    205.4M    411.4M  33% /

Check free RAM

dom0:~# free -m
             total       used       free     shared    buffers     cached
Mem:          1285        464        821        205          2        293
-/+ buffers/cache:        168       1117
Swap:            0          0          0

Add more RAM to tmpfs mounted on /

dom0:~# mount -o remount,size=900M /
dom0:~# df -h /
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   900.0M    205.1M    694.9M  23% /

Now update-kernel can be used.

dom0:~# mount -o remount,rw /media/usb
dom0:~# update-kernel
dom0:~# mount -o remount,ro /media/usb

Now you can reboot the dom0 to the updated kernel.


  • « apt-dater-host for Alpine
  • Alpine Linux on Solid Run I2EX-300-D »

Published

Dec 29, 2016

Last Updated

2017-04-20 23:45:11+02:00

Author

henrik

Category

HOWTOs

Tags

  • Alpine 15
  • XEN 21

Social

  • atom feed
  • rss feed
  • ipv6 ready
  • Powered by Pelican. Theme: Elegant by Talha Mansoor