Guest example: Alpine Linux - churchers/vm-bhyve GitHub Wiki

It took me a little while to figure out how to do this, so in case it helps anyone else, including my future self, I wrote this guide.

First follow the instructions on https://github.com/churchers/vm-bhyve.

All commands must be run as root, so either log in as root or run su initially.

If you have lagg (network failover) set up, use e.g. lagg0 as interface: vm switch add public lagg0

Note however that guests can only access internet through wired connection when you use lagg failover for wired/wireless connections.

In order for internet access to work, make sure the following is set:

sysctl net.link.tap.up_on_open=1
sysctl net.link.bridge.ipfw=0
sysctl net.link.bridge.pfil_bridge=0
sysctl net.link.bridge.pfil_member=0

In my case, the first two are set automatically (probably by vm-bhyve), so I only need to set the last two. Note that this applies if you're using ipfw/firewall as firewall; other settings may apply if you're using pf. Got this from FreeBSD forum.

To set this at boot time, append needed values to your /etc/sysctl.conf, but omit the sysctl part. So in my case, I add this:

# Disable filtering of packages transmitted over network bridges:
net.link.bridge.pfil_bridge=0
net.link.bridge.pfil_member=0

Then, in order to be able to install/run alpine linux, create a vm with template alpine: vm create -t alpine -s 5G alpine

This will fail to run, but allows you to run grub command line. From there, you can determine the actual name of the linux kernel provided with your chosen alpine iso; name differs between distributions. The template provided with vm-bhyve uses vmlinuz-vanilla and initramfs-vanilla; this is the bit that is distribution-specific.

Still, start the installation, e.g.: vm install alpine alpine-virt-3.13.2-x86_64.iso

Connect to it: vm console alpine

On boot, it will tell you:

error: file `/boot/vmlinuz-vanilla' not found.
error: you need to load the kernel first.

Press any key to continue...

So, press any key, and then from GRUB menu, press c to enter grub command-line. Press ls to see available devices, in case of alpine-virt-3.13.2-x86_64.iso these are: (cd0) (cd0,msdos2) (hd0) (host) "Digg" through the tree until you find a linux kernel located in /boot: ls (cd0)/ (/ must be included) gives you: apks/ boot/ efi/, so we continue:

grub> ls (cd0)/boot/
config-virt dtbs-virt/ grub/ initramfs-virt modloop-virt syslinux/ System.map-v
irt vmlinuz-virt

So here you find that for this particular iso, the kernel files are named initramfs-virt and vmlinuz-virt. You can now exit the console by entering reboot. Wait a couple of seconds and then enter ~+Ctrl+d to get back into your host's terminal.

Next, either edit the configuration for this particular vm by entering vm config alpine (replace alpine with the name you gave your vm), or by copying the template file and create your own template. For the iso in this particular example, you want to replace all occurrences of vanilla with virt; so that all /boot/vmlinuz-vanilla is replaced with /boot/vmlinuz-virt, and all /boot/initramfs-vanilla is replaced with /boot/initramfs-virt.

Next, if you ran vm config alpine you simply re-run: vm install alpine alpine-virt-3.13.2-x86_64.iso followed by vm console alpine or if you created a new template, you create a new vm and then run the install on that.

Login with root as username (no password), and then you'll hopefully notice the system message telling you to run setup-alpine. This command is what actually installs alpine. Before this is done, networking won't work.