Introduction
This HOWTO cover how to configure XEN in order to be able to install Alpine Linux as a virtual machine (DomU).
Preperation and installation
Download Alpine ISO
In this HOWO we have created a directory called /opt/images where we download the installation image for Alpine Linux.
cd /opt/images && wget "https://dl-cdn.alpinelinux.org/alpine/v3.15/releases/x86_64/alpine-extended-3.15.4-x86_64.iso"
Create Logical Volumes in LVM for the disk and swap
lvcreate -n alpine-disk -L 4G <path to volume group>
lvcreate -n alpine-swap -L 1G <path to volume group>
Adjust the disk size and swap to your needs.
Extract the kernel from the ISO
Mount the downloaded ISO and copy the boot directory to /opt/boot/alpine-3.15
mkdir -p /opt/boot
mount -o ro /opt/images/alpine-extended-3.15.4-x96_64.iso /mnt
cp -a /mnt/boot /opt/boot/alpine-3.15
umount /mnt
Create your Xen configuration file
/etc/xen/alpine.cfg
cat > /etc/xen/alpine.cfg << EOF
# basic config for alpine linux installation
vcpus = '2'
memory = '1024'
#kernel = '/usr/lib/grub-xen/grub-x86_64-xen.bin'
kernel = "/opt/boot/alpine-3.15/vmlinuz-lts"
ramdisk = "/opt/boot/alpine-3.15/initramfs-lts"
extra = "alpine_dev=hdc:iso9660 modules=loop,squashfs,sd-mod,usb-storage console=hvc0"
disk = [
'file:/opt/images/alpine-extended-3.15.4-x86_64.iso,hdc:cdrom,r',
'phy:/dev/vg_md0/alpine-disk,xvda1,w',
'phy:/dev/vg_md0/alpine-swap,xvda2,w',
]
name = 'alpine'
vif = [ 'mac=00:16:3E:A0:00:01,bridge=br_202' ]
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
EOF
Start the installation
xl create -c /etc/xen/alpine.cfg
At the login prompt login as root
Run the command setup-alpine
Select your keyboard layout, network etc.
In the last steps when selecting where and what to install, select none.
Available disks are:
xvda1 (21.5 GB )
xvda2 (2.1 GB )
Which disk(s) would you like to use? (or '?' for help or 'none') [none]
Enter where to store configs ('floppy', 'usb' or 'none') [none]
Install e2fsprogs
apk add e2fsprogs
Format the disk
mkfs.ext4 /dev/xvda1
Create the swap
mkswap /dev/xvda2
Mount the disk
modprobe ext4
mount /dev/xvda1 /mnt
Install to the disk
setup-disk /mnt
Installing system on /dev/xvda1:
extlinux: Not a directory: /mnt/boot
100% ███████████████████==> initramfs: creating /boot/initramfs-lts
/boot is device /dev/xvda1
extlinux: no previous syslinux boot sector found
You might need fix the MBR to be able to boot
Create grub.cfg
mkdir /mnt/boot/grub
cat > /mnt/boot/grub/grub.cfg << EOF
set timeout=2
set default=0
menuentry "alpine" {
linux /boot/vmlinuz-lts modules=ext4 console=hvc0 root=/dev/xvda1
initrd /boot/initramfs-lts
}
EOF
Unmount and power off
cd
umount /mnt
poweroff
Update the Xen config file
Update the alpine.cfg file as follows
cat > /etc/xen/alpine.cfg << EOF
# basic config for alpine linux installation
vcpus = '2'
memory = '1024'
type = 'pvh'
kernel = '/usr/lib/grub-xen/grub-i386-xen_pvh.bin'
disk = [
'phy:/dev/vg_md0/alpine-disk,xvda1,w',
'phy:/dev/vg_md0/alpine-swap,xvda2,w',
]
name = 'alpine'
vif = [ 'mac=00:16:3E:A0:00:01,bridge=br_202' ]
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
EOF
Start and test the new machine
xl create /etc/xen/alpine.cfg