Create Alpine Linux PV DomU: Difference between revisions

From Alpine Linux
(simplify, fix ext4 and use macros)
Line 1: Line 1:
== Obtain a copy of Alpine Linux ==
== Obtain a copy of Alpine Linux ==


To create an Alpine Linux paravirtualized (PV) DomU you will need an Alpine Linux iso.


To create an Alpine Linux paravirtualized (PV) DomU you will need an Alpine Linux iso.
Download the latest alpine-virtgrsec iso from https://alpinelinux.org/downloads/


Download the latest and greatest iso
In this example we will use {{path|/data/}} for our download and for our disk images.


{{download|alpine}}
==Mount the ISO image ==


== Extract the xen-aware linux kernel ==
Next, mount the iso so we can read the kernel and initramfs:


Next, mount the iso and extract the kernel and initramfs:
{{cmd | mount -t iso9660 -o loop /data/alpine-virtgrsec-3.5.2-x86_64.iso /media/cdrom }}


<pre>
Now we have the kernel in {{path|/media/cdrom/boot/vmlinuz-virtgrsec}} and initramfs in {{path|/media/cdrom/boot/initramfs-virtgrsec}}.
# mkdir -p /mnt/alpine_iso
# mount -t iso9660 -o loop /path/to/the/iso /mnt/alpine_iso
# cp /mnt/alpine_iso/boot/vmlinuz-grsec /path/to/save/kernel/
# cp /mnt/alpine_iso/boot/initramfs-grsec /path/to/save/kernel/
# umount /mnt/alpine_iso
# rmdir /mnt/alpine_iso
</pre>


Now we have the kernel in /path/to/save/kernel/vmlinuz-grsec and initramfs in /path/to/save/kernel/initramfs-grsec.
Alternatively you can use {{path|uniso}} or {{path|p7zip}} to extract the content to a temp area.


== Create the disk image ==
== Create the disk image ==
Now we should create an empty file, that will be the hard drive of the DomU (in this example we are using a 3GB disk):
Now we should create an empty file, that will be the hard drive of the DomU (in this example we are using a 3GB disk):


<pre>
{{cmd | <nowiki>dd if=/dev/zero of=/data/a1.img bs=1M count=3000</nowiki>}}
# dd if=/dev/zero of=/path/to/disk.img bs=1M count=3000
 
</pre>


== Create a DomU config file that boots the ISO image ==
== Create a DomU config file that boots the ISO image ==
The next step is to create a basic DomU configuration file, so we can launch the pv guest iso (save it where you like, although the most common place is /etc/xen/).
The next step is to create a basic DomU configuration file, so we can launch the pv guest iso (save it where you like, although the most common place is {{path|/etc/xen/}}).


<pre>
{{cat | /etc/xen/a1.cfg | <nowiki># Alpine Linux PV DomU
# Alpine Linux PV DomU


# Kernel paths for install
# Kernel paths for install
kernel = "/path/to/save/kernel/vmlinuz-grsec"
kernel = "/media/cdrom/boot/vmlinuz-virtgrsec"
ramdisk = "/path/to/save/kernel/initramfs-grsec"
ramdisk = "/media/cdrom/boot/initramfs-virtgrsec"
extra="alpine_dev=xvdc:iso9660 modules=loop,squashfs,sd-mod,usb-storage console=hvc0"
extra="modules=loop,squashfs console=hvc0"


# Path to HDD and iso file
# Path to HDD and iso file
disk = [
disk = [
         'format=raw, vdev=xvda, access=w, target=/path/to/disk.img',
         'format=raw, vdev=xvda, access=w, target=/data/a1.img',
         'format=raw, vdev=xvdc, access=r, devtype=cdrom, target=/path/to/the/iso'
         'format=raw, vdev=xvdc, access=r, devtype=cdrom, target=/data/alpine-virtgrsec-3.5.2-x86_64.iso'
       ]
       ]


Line 52: Line 44:
# DomU settings
# DomU settings
memory = 512
memory = 512
name = "alpine"
name = "alpine-a1"
vcpus = 1
vcpus = 1
maxvcpus = 1
maxvcpus = 1
</pre>
</nowiki>}}


== Install the guest ==
== Install the guest ==
Now that we have all the necessary files, we can start the DomU to proceed with the install:
Now that we have all the necessary files, we can start the DomU to proceed with the install:


<pre>
{{cmd|xl create -f /etc/xen/a1.cfg  -c}}
# xl create -f /path/to/conf -c
 
</pre>
Login into the system with user "root" and no password.


Login into the system with user "root" and no password, and proceed with the normal install:
We need disable the ext4 64bit feature since pv-grub does not support ext4. Then we proceed with the normal install:


<pre>
{{cmd |<nowiki>export MKFS_OPTS_BOOT="-O ^64bit"; setup-alpine</nowiki>}}
# setup-alpine
</pre>


After configuring the basic system, you will be asked where would you like to install Alpine, choose xvda and sys.
After configuring the basic system, you will be asked where would you like to install Alpine, choose xvda and sys.
Line 91: Line 81:
Installation is complete. Please reboot.
Installation is complete. Please reboot.


# halt
#
</pre>
 
Before you reboot, mount the boot partition and create a {{path|grub/menu.lst}} file for pv-grub.


</pre>
{{cmd |<nowiki>mount /dev/xvda1 /mnt
mkdir /mnt/grub</nowiki>}}


== Adjust the domU config file to boot from fresh install ==
{{cat | /mnt/grub/menu.lst |<nowiki>default 0
timeout 5
title alpine-xen-pv
root (hd0,0)
kernel /boot/vmlinuz-virtgrsec modules=ext4 console=hvc0 root=/dev/xvda3
initrd /boot/initramfs-virtgrsec</nowiki>}}


In your Dom0, edit your DomU config file to boot from the fresh install
Unmount and power off.
{{cmd |umount /mnt
poweroff}}


== Adjust the domU config file to boot from fresh install ==


<pre>
In your Dom0, edit your DomU config file to boot with pv-grub.
# Alpine Linux PV DomU


# Kernel paths for install
{{cat | /etc/xen/a1.cfg |<nowiki># Alpine Linux PV DomU
kernel = "/path/to/save/kernel/vmlinuz-grsec"
ramdisk = "/path/to/save/kernel/initramfs-grsec"
extra="modules=sd-mod,usb-storage,ext4,squashfs console=hvc0 root=/dev/xvda3"


kernel = "/usr/lib/xen/boot/pv-grub-x86_64.gz"


# Path to HDD and iso file
# Path to HDD and iso file
disk = [
disk = [
         'format=raw, vdev=xvda, access=w, target=/path/to/disk.img'
         'format=raw, vdev=xvda, access=w, target=/data/a1.img'
       ]
       ]


Line 119: Line 119:
# DomU settings
# DomU settings
memory = 512
memory = 512
name = "alpine"
name = "alpine-a1"
vcpus = 1
vcpus = 1
maxvcpus = 1
maxvcpus = 1
</pre>
</nowiki>}}


==Adding a grub config file to boot with pvgrub==
Remember to unmount the loopback iso image.
 
{{cmd | umount /media/cdrom}}
Now boot the VM once more to add a grub config file so that we may load the xen-aware kernel from within the VM.
 
This means that upgrading the kernel will not mean copying it to the dom0.
 
<pre>
# xl create -f /path/to/conf -c
</pre>
 
Log in as root and create the file /boot/grub/menu.lst with the following content. If you used LVM, adjust the "root" entry to read /dev/vg0/lv_root.
 
<pre>
 
#/boot/grub/menu.lst
 
default 0
timeout 5
title alpine-xen-pv
root (hd0,0)
kernel /boot/vmlinuz-grsec modules=sd-mod,usb-storage,ext4,squashfs console=hvc0 root=/dev/xvda3
initrd /boot/initramfs-grsec
 
</pre>
 
Halt your VM one last time
 
<pre>
# halt
</pre>
 
==Adjust the DomU config file one last time to use pvgrub==
 
Your final xen DomU config file should look something like this.
 
<pre>
# Alpine Linux PV DomU
disk = [
        'format=raw, vdev=xvda, access=w, target=/path/to/alpine.img'
        ]
 
kernel = "/usr/lib/xen/boot/pv-grub-x86_64.gz"
 
vif = [ 'bridge=br0' ]
memory = 1024
name = "alpine"
vcpus = 1
maxvcpus = 1
 
</pre>


When you next boot, you will be presented with the grub boot menu, and your VM will boot.
When you next boot, you will be presented with the grub boot menu, and your VM will boot.


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

Revision as of 11:39, 14 April 2017

Obtain a copy of Alpine Linux

To create an Alpine Linux paravirtualized (PV) DomU you will need an Alpine Linux iso.

Download the latest alpine-virtgrsec iso from https://alpinelinux.org/downloads/

In this example we will use /data/ for our download and for our disk images.

Mount the ISO image

Next, mount the iso so we can read the kernel and initramfs:

mount -t iso9660 -o loop /data/alpine-virtgrsec-3.5.2-x86_64.iso /media/cdrom

Now we have the kernel in /media/cdrom/boot/vmlinuz-virtgrsec and initramfs in /media/cdrom/boot/initramfs-virtgrsec.

Alternatively you can use uniso or p7zip to extract the content to a temp area.

Create the disk image

Now we should create an empty file, that will be the hard drive of the DomU (in this example we are using a 3GB disk):

dd if=/dev/zero of=/data/a1.img bs=1M count=3000


Create a DomU config file that boots the ISO image

The next step is to create a basic DomU configuration file, so we can launch the pv guest iso (save it where you like, although the most common place is /etc/xen/).

Contents of /etc/xen/a1.cfg

# Alpine Linux PV DomU # Kernel paths for install kernel = "/media/cdrom/boot/vmlinuz-virtgrsec" ramdisk = "/media/cdrom/boot/initramfs-virtgrsec" extra="modules=loop,squashfs console=hvc0" # Path to HDD and iso file disk = [ 'format=raw, vdev=xvda, access=w, target=/data/a1.img', 'format=raw, vdev=xvdc, access=r, devtype=cdrom, target=/data/alpine-virtgrsec-3.5.2-x86_64.iso' ] # Network configuration vif = ['bridge=br0'] # DomU settings memory = 512 name = "alpine-a1" vcpus = 1 maxvcpus = 1

Install the guest

Now that we have all the necessary files, we can start the DomU to proceed with the install:

xl create -f /etc/xen/a1.cfg -c

Login into the system with user "root" and no password.

We need disable the ext4 64bit feature since pv-grub does not support ext4. Then we proceed with the normal install:

export MKFS_OPTS_BOOT="-O ^64bit"; setup-alpine

After configuring the basic system, you will be asked where would you like to install Alpine, choose xvda and sys.

This will create three partitions on your disk, xvda1 for /boot, xvda2 for swap and xvda3 for /

Available disks are:
  xvda	(3.1 GB  )
Which disk(s) would you like to use? (or '?' for help or 'none') [none] xvda
The following disk is selected:
  xvda	(3.1 GB  )
How would you like to use it? ('sys', 'data' or '?' for help) [?] sys
WARNING: The following disk(s) will be erased:
  xvda	(3.1 GB  )
WARNING: Erase the above disk(s) and continue? [y/N]: y
Initializing partitions on /dev/xvda...
Creating file systems...
Installing system on /dev/xvda3:


Installation is complete. Please reboot.

#

Before you reboot, mount the boot partition and create a grub/menu.lst file for pv-grub.

mount /dev/xvda1 /mnt mkdir /mnt/grub

Contents of /mnt/grub/menu.lst

default 0 timeout 5 title alpine-xen-pv root (hd0,0) kernel /boot/vmlinuz-virtgrsec modules=ext4 console=hvc0 root=/dev/xvda3 initrd /boot/initramfs-virtgrsec

Unmount and power off.

umount /mnt poweroff

Adjust the domU config file to boot from fresh install

In your Dom0, edit your DomU config file to boot with pv-grub.

Contents of /etc/xen/a1.cfg

# Alpine Linux PV DomU kernel = "/usr/lib/xen/boot/pv-grub-x86_64.gz" # Path to HDD and iso file disk = [ 'format=raw, vdev=xvda, access=w, target=/data/a1.img' ] # Network configuration vif = ['bridge=br0'] # DomU settings memory = 512 name = "alpine-a1" vcpus = 1 maxvcpus = 1

Remember to unmount the loopback iso image.

umount /media/cdrom

When you next boot, you will be presented with the grub boot menu, and your VM will boot.