Create Alpine Linux PV DomU: Difference between revisions

From Alpine Linux
No edit summary
m (→‎Install the guest: used pkg and path templates.)
 
(28 intermediate revisions by 9 users not shown)
Line 1: Line 1:
To create an Alpine Linux PV DomU you will need a Dom0 and an Alpine Linux iso, here we will use the "mini" iso. The first step it to mount the image and extract the kernel and initramfs:
== Obtain a copy of Alpine Linux ==


<pre>
To create an Alpine Linux paravirtualized (PV) DomU you'll need an Alpine Linux iso.
# mkdir -p /mnt/alpine_iso
 
# mount -o loop /path/to/the/iso /mnt/alpine_iso
Download the latest alpine-virt iso from https://alpinelinux.org/downloads/
# cp /mnt/alpine_iso/boot/grsec /path/to/save/kernel/
 
# cp /mnt/alpine_iso/boot/grsec.gz /path/to/save/kernel/
In this example we'll use {{path|/data/}} for the download and disk images.
# umount /mnt/alpine_iso
 
# rm -f /mnt/alpine_iso
==Mount the ISO image ==
</pre>
 
Next, mount the iso so you can read the kernel and initramfs:
 
{{cmd | mount -t iso9660 -o loop /data/alpine-virt-{{AlpineLatest}}-x86_64.iso /media/cdrom }}
 
Now you have the kernel in {{path|/media/cdrom/boot/vmlinuz-virt}} and initramfs in {{path|/media/cdrom/boot/initramfs-virt}}.
 
Alternatively you can use {{path|uniso}} or {{path|7z}} to extract the content to a temporary area.
 
== Create the disk image ==
Now you need to create an empty file to be used as the hard drive of the DomU (in this example we are using a 3GB disk):
 
{{cmd | <nowiki>dd if=/dev/zero of=/data/a1.img bs=1M count=3000</nowiki>}}


Now we have the kernel at /path/to/save/kernel/grsec and the initramfs at /path/to/save/kernel/grsec.gz. Now we should create an empty file, that will be the hard drive of the DomU, you can also use a physical partition if you like (in this example we are using a 3GB disk):
Alternatively, if an LVM volume group (e.g. vg1) with free space is available on dom0, create a logical volume for Alpine:


<pre>
{{cmd | <nowiki>sudo lvcreate -n alpine -L 10g vg1</nowiki>}}
# dd if=/dev/zero of=/path/to/disk.img bs=1M count=3000
</pre>


The next step is to create a basic configuration file, so we can launch the DomU (save it where you like, although the most common place is /etc/xen/).
== Create a DomU config file that boots the ISO image ==
Next, create a basic DomU configuration file, so you 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 = [
         'file:/path/to/disk.img,xvda,w',
         'format=raw, vdev=xvda, access=w, target=/data/a1.img',
         'file:/path/to/the/iso,xvdc:cdrom,r'
         'format=raw, vdev=xvdc, access=r, devtype=cdrom, target=/data/alpine-virt-</nowiki>{{AlpineLatest}}<nowiki>-x86_64.iso'
        ]
      ]


# Network configuration
# Network configuration
Line 36: Line 46:


# DomU settings
# DomU settings
memory = 128
memory = 512
name = "alpine"
name = "alpine-a1"
vcpus = 1
vcpus = 1
</pre>
maxvcpus = 1
</nowiki>}}
 
If using LVM, replace {{path|/data/a1.img}} with {{path|/dev/vg1/alpine}} in the disk specification.


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


<pre>
{{cmd|xl create -f /etc/xen/a1.cfg  -c}}
# xl create -c /path/to/conf
</pre>


Login into the system with user "root" and no password, and proceed with the normal install:
Log into the system with user "root" and no password.


<pre>
After configuring the basic system, you will be asked where would you like to install Alpine. Choose xvda and sys.
# setup-alpine
</pre>


After configuring the basic system, you will be asked where would you like to install Alpine, choose xvda and sys, as shown above:
That will create three partitions on your disk. xvda1 for {{path|/boot}}, xvda2 for swap and xvda3 for {{path|/}}


<pre>
<pre>
Line 71: Line 81:


Installation is complete. Please reboot.
Installation is complete. Please reboot.
#
</pre>
</pre>


As the installation suggests, halt the DomU machine and edit the config file, to remove the xvdc disk, and change the "extra" line, since pygrub and extlinux doesn't seem to get along, we will have to boot with the same kernel and ramdisk. At the end it should look similar to this:
When you reboot, the pv bootloader pvgrub, will look to {{path|/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 {{pkg|nano}} or {{pkg|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:
# Alpine Linux PV DomU
{{cat | /mnt/grub/grub.cfg |<nowiki>menuentry 'alpine-xen' {
    set root=(xen/xvda,msdos1)
    linux /boot/vmlinuz-virt root=/dev/xvda3 modules=ext4 console=hvc0
    initrd /boot/initramfs
}</nowiki>}}
 
Finally, Ctrl-S to save, Ctrl-X to exit nano.
 
Unmount and power off.
{{cmd |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.
 
{{cat | /etc/xen/a1.cfg |<nowiki># Alpine Linux PV DomU


# Kernel paths for install
kernel = "/usr/lib/grub-xen/grub-x86_64-xen.bin"
kernel = "/path/to/save/kernel/grsec"
ramdisk = "/path/to/save/kernel/grsec.gz"
extra="root=/dev/xvda3 modules=sd-mod,usb-storage,ext4 xen"


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


# Network configuration
# Network configuration
Line 92: Line 128:


# DomU settings
# DomU settings
memory = 128
memory = 512
name = "alpine"
name = "alpine-a1"
vcpus = 1
vcpus = 1
</pre>
maxvcpus = 1
</nowiki>}}
 
Make sure that grub-xenhost is installed.
{{cmd | apk add grub-xenhost}}
 
Remember to unmount the loopback iso image.
{{cmd | umount /media/cdrom}}
 
The next time you boot, you'll be presented with the grub boot menu, and your VM will boot.
 
== Using Legacy pvgrub ==
 
To use Legacy pvgrub you need to use a {{path|/boot/grub/menu.lst}} instead of {{path|/boot/grub/grub.cfg}}.
 
{{cat | /etc/xen/a1.cfg |<nowiki>default 0
timeout 2
title alpine-xen-pv
root (hd0,0)
kernel /boot/vmlinuz-virt root=/dev/xvda3 modules=ext4 console=hvc0
initrd /boot/initramfs-virt
</nowiki>}}
 
And in {{path|/etc/xen/a1.cfg}} you need to change the 'kernel' loader to
{{cat | /etc/xen/a1.cfg |<nowiki>...
kernel = "/usr/lib/xen/boot/pv-grub-x86_64.gz"
...
</nowiki>}}


So now you are good to go, you can boot into your new Alpine Linux DomU:
== 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]


<pre>
[[Category:Virtualization]]
# xl create -c /path/to/conf
</pre>

Latest revision as of 20:02, 18 August 2023

Obtain a copy of Alpine Linux

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

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

In this example we'll use /data/ for the download and disk images.

Mount the ISO image

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

mount -t iso9660 -o loop /data/alpine-virt-3.20.3-x86_64.iso /media/cdrom

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

Alternatively you can use uniso or 7z to extract the content to a temporary area.

Create the disk image

Now you need to create an empty file to be used as 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 an LVM volume group (e.g. vg1) 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

Next, create a basic DomU configuration file, so you 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.20.3-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 you have the necessary files, you can start the DomU to proceed with the install:

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

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

That 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 console=hvc0 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/grub-xen/grub-x86_64-xen.bin" # 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

Make sure that grub-xenhost is installed.

apk add grub-xenhost

Remember to unmount the loopback iso image.

umount /media/cdrom

The next time you boot, you'll be presented with the grub boot menu, and your VM will boot.

Using Legacy pvgrub

To use Legacy pvgrub you need to use a /boot/grub/menu.lst instead of /boot/grub/grub.cfg.

Contents of /etc/xen/a1.cfg

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

And in /etc/xen/a1.cfg you need to change the 'kernel' loader to

Contents of /etc/xen/a1.cfg

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

See also