Difference between revisions of "Create Alpine Linux PV DomU"

From Alpine Linux
Jump to: navigation, search
(Update menu.lst to grub.cfg)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
To create an Alpine Linux PV DomU you will need an Alpine Linux iso.
+
== Obtain a copy of Alpine Linux ==
  
Download the latest and greatest iso from the [http://alpinelinux.org/ Alpine Linux] website.
+
To create an Alpine Linux paravirtualized (PV) DomU you will need an Alpine Linux iso.
  
== Extract the xen-aware linux kernel ==
+
Download the latest alpine-virt iso from https://alpinelinux.org/downloads/
  
Next, mount the iso and extract the kernel and initramfs:
+
In this example we will use {{path|/data/}} for our download and for our disk images.
  
<pre>
+
==Mount the ISO image ==
# mkdir -p /mnt/alpine_iso
+
 
# mount -o loop /path/to/the/iso /mnt/alpine_iso
+
Next, mount the iso so we can read the kernel and initramfs:
# cp /mnt/alpine_iso/boot/grsec /path/to/save/kernel/
+
 
# cp /mnt/alpine_iso/boot/grsec.gz /path/to/save/kernel/
+
{{cmd | mount -t iso9660 -o loop /data/alpine-virt-{{AlpineLatest}}-x86_64.iso /media/cdrom }}
# umount /mnt/alpine_iso
+
 
# rmdir /mnt/alpine_iso
+
Now we have the kernel in {{path|/media/cdrom/boot/vmlinuz-virt}} and initramfs in {{path|/media/cdrom/boot/initramfs-virt}}.
</pre>
 
  
Now we have the kernel in /path/to/save/kernel/grsec and initramfs in /path/to/save/kernel/grsec.gz.
+
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>
+
Alternatively, if a LVM volume group (vg1 say) with free space is available on dom0, create a logical volume for alpine:
 +
 
 +
{{cmd | <nowiki>sudo lvcreate -n alpine -L 10g vg1</nowiki>}}
  
 
== 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/grsec"
+
kernel = "/media/cdrom/boot/vmlinuz-virt"
ramdisk = "/path/to/save/kernel/grsec.gz"
+
ramdisk = "/media/cdrom/boot/initramfs-virt"
extra="alpine_dev=xvdc:iso9660 modules=loop,squashfs,sd-mod,usb-storage modloop=/boot/grsec.modloop.squashfs 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-virt-</nowiki>{{AlpineLatest}}<nowiki>-x86_64.iso'
 
       ]
 
       ]
  
Line 47: Line 47:
 
# DomU settings
 
# DomU settings
 
memory = 512
 
memory = 512
name = "alpine"
+
name = "alpine-a1"
 
vcpus = 1
 
vcpus = 1
 
maxvcpus = 1
 
maxvcpus = 1
</pre>
+
</nowiki>}}
 +
 
 +
If using LVM, replace {{path|/data/a1.img}} with {{path|/dev/vg1/alpine}} in the disk specification.
  
 
== 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, and proceed with the normal install:
+
Login into the system with user "root" and no password.
 
 
<pre>
 
# 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 86: Line 82:
 
Installation is complete. Please reboot.
 
Installation is complete. Please reboot.
  
# halt
+
#
 +
</pre>
 +
 
 +
When you reboot, the pv bootloader, pvgrub, will look to /boot/grub/grub.cfg for its menu, so create that file first.
 +
 
 +
Mount the boot partition and create a {{path|grub/grub.cfg}} file for pvgrub. (Note that grub.cfg is for pvgrub2 which replaced pvgrub1 and its menu.lst beginning in 2013.)
 +
 
 +
{{cmd |<nowiki>mount /dev/xvda1 /mnt
 +
mkdir /mnt/grub</nowiki>}}
 +
 
 +
Install a basic text editor like nano or vim:<br/>
 +
{{cmd | apk add nano}}
 +
 
 +
If using nano, enter:<br/>
 +
{{cmd | nano /mnt/grub/grub.cfg}}
  
</pre>
+
Then add the following to create a basic grub2 configuration file:
 +
{{cat | /mnt/grub/grub.cfg |<nowiki>menuentry 'alpine-xen' {
 +
    set root=(xen/xvda,msdos1)
 +
    linux /boot/vmlinuz-virt root=/dev/xvda3 modules=ext4
 +
    initrd /boot/initramfs
 +
}</nowiki>}}
  
== Adjust the domU config file to boot from fresh install ==
+
Finally, Ctrl-S to save, Ctrl-X to exit nano.
  
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 pvgrub.
# Alpine Linux PV DomU
 
  
# Kernel paths for install
+
{{cat | /etc/xen/a1.cfg |<nowiki># Alpine Linux PV DomU
kernel = "/path/to/save/kernel/grsec"
 
ramdisk = "/path/to/save/kernel/grsec.gz"
 
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 114: Line 129:
 
# 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==
+
The name and location of pvgrub in Dom0 is distribution-specific, so you may need to change the "kernel=" line, above.
  
Now boot the VM once more to add a grub.conf file so that we may load the xen-aware kernel from within the VM.
+
For example, in Debian 10, it's {{path|'/usr/lib/grub-xen/grub-x86_64-xen.bin'}}
  
This means that upgrading the kernel will not mean copying it to the dom0.
+
Remember to unmount the loopback iso image.
 +
{{cmd | umount /media/cdrom}}
  
<pre>
+
When you next boot, you will be presented with the grub boot menu, and your VM will boot.
# xl create -f /path/to/conf -c
 
</pre>
 
 
 
Log in as root and create the file /boot/grub.conf with the following content
 
 
 
<pre>
 
 
 
#/boot/grub.conf
 
 
 
default 0
 
timeout 5
 
 
title alpine-xen-pv
 
root (hd0,0)
 
kernel /boot/grsec modules=sd-mod,usb-storage,ext4,squashfs console=hvc0 root=/dev/xvda3
 
initrd /boot/grsec.gz
 
 
 
</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"
 
extra="(hd0,0)/boot/grub.conf"
 
 
 
vif = [ 'bridge=br0' ]
 
memory = 1024
 
name = "alpine"
 
vcpus = 1
 
maxvcpus = 1
 
  
</pre>
+
== See also ==
 
+
* [https://www.linkedin.com/pulse/setting-up-alpine-linux-370-domu-vm-xenserver-72-ali-poursamadi Setting up Alpine Linux 3.7.0 as a domU VM on XenServer 7.2]
When you next boot, you will be presented with the grub boot menu, and your VM will boot.
 
  
 
[[Category:Virtualization]]
 
[[Category:Virtualization]]

Latest revision as of 17:32, 8 June 2020

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-virt 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-virt-3.8.0-x86_64.iso /media/cdrom

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

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

Alternatively, if a LVM volume group (vg1 say) with free space is available on dom0, create a logical volume for alpine:

sudo lvcreate -n alpine -L 10g vg1

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-virt" ramdisk = "/media/cdrom/boot/initramfs-virt" 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-virt-3.8.0-x86_64.iso' ] # Network configuration vif = ['bridge=br0'] # DomU settings memory = 512 name = "alpine-a1" vcpus = 1 maxvcpus = 1

If using LVM, replace /data/a1.img with /dev/vg1/alpine in the disk specification.

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.

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.

#

When you reboot, the pv bootloader, pvgrub, will look to /boot/grub/grub.cfg for its menu, so create that file first.

Mount the boot partition and create a grub/grub.cfg file for pvgrub. (Note that grub.cfg is for pvgrub2 which replaced pvgrub1 and its menu.lst beginning in 2013.)

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

Install a basic text editor like nano or vim:

apk add nano

If using nano, enter:

nano /mnt/grub/grub.cfg

Then add the following to create a basic grub2 configuration file:

Contents of /mnt/grub/grub.cfg

menuentry 'alpine-xen' { set root=(xen/xvda,msdos1) linux /boot/vmlinuz-virt root=/dev/xvda3 modules=ext4 initrd /boot/initramfs }

Finally, Ctrl-S to save, Ctrl-X to exit nano.

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 pvgrub.

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

The name and location of pvgrub in Dom0 is distribution-specific, so you may need to change the "kernel=" line, above.

For example, in Debian 10, it's '/usr/lib/grub-xen/grub-x86_64-xen.bin'

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.

See also