Oct 022018
 

bhyve is a hypervisor/virtual machine manager developed on FreeBSD.

xhyve is port of bhyve to OS X. It is built on top of Hypervisor.framework in OS X 10.10 Yosemite and higher, runs entirely in userspace, and has no other dependencies.

I usually use MacPorts, but ran into trouble with xhyve, so this morning I tried Homebrew instead.

Installing Homebew (often referred to as brew) is outside scope, so please refer to their documentation.

Installing xhyve

To install xhyve, I did this:

[dan@pro02:~] $ brew install --HEAD xhyve
==> Cloning https://github.com/mist64/xhyve.git
Cloning into '/Users/dan/Library/Caches/Homebrew/xhyve--git'...
==> Checking out branch master
Already on 'master'
Your branch is up to date with 'origin/master'.
==> make
  /usr/local/Cellar/xhyve/HEAD-1f1dbe3: 11 files, 11.2MB, built in 11 seconds
[dan@pro02:~] $

Some background information

We will create two scripts:

  1. an install script – this will run xhyve and install FreeBSD
  2. a run script – to run the installed instance of FreeBSD

Where will FreeBSD be installed? Into a file-based filesystem. Yes, we will create a file and FreeBSD will be installed into that. In the bhyve documentation, this is referred to as the virtual disk.

You will need to obtain a copy of install media for FreeBSD. I grabbed FreeBSD-11.2-RELEASE-amd64-disc1.iso

Creating the virtual disk

I wanted a 50G drive. I will be installing a copy of the FreshPorts database within this FreeBSD instance. I have, just now, considered running PostgreSQL natively on OSX itself. I would prefer to keep everything within FreeBSD if I can.

It was FreeBSD running on xhyve tutorial which showed me how to create the virtual disk. Based on that, I used this command:

[dan@pro02:~/xhyve] $ mkfile -nv 50g cuppy.img
cuppy.img 53687091200 bytes

I am putting all my xhyve work in ~/xhyve, but your choice should suit whatever you want to choose.

The install script

You don’t have to create an install script, but it makes it easier than typing everything into one command.

This is xhyve-cuppy-install.sh, based upon what I found in the xhyve tutorial mentioned above.

#!/bin/sh

UUID="-U deaddead-dead-dead-dead-deaddeaddead"

USERBOOT="/usr/local/Cellar/xhyve/HEAD-1f1dbe3/share/xhyve/test/userboot.so"
BOOTVOLUME="/Users/dan/FreeBSD-11.2-RELEASE-amd64-disc1.iso"

IMG="/Users/dan/xhyve/cuppy.img"
KERNELENV=""

MEM="-m 2G"
SMP="-c 2"
PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
#NET="-s 2:0,virtio-net"
IMG_CD="-s 3:0,ahci-cd,/Users/dan/FreeBSD-11.2-RELEASE-amd64-disc1.iso"
IMG_HDD="-s 4:0,virtio-blk,$IMG"
LPC_DEV="-l com1,stdio"
ACPI="-A"

xhyve $ACPI $MEM $SMP $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_HDD $UUID -f fbsd,$USERBOOT,$BOOTVOLUME,"$KERNELENV"

These are my notes on the above, and I’m not 100% positive that my descriptions are correct.

  • Line 3 – I am not sure why we need a UUID
  • Line 5 – USERBOOT points to the userboot.so file supplied by your xhyve installation. It may vary from what I have.
  • Line 6 – BOOTVOLUME indicates the image we will boot from. In this case, it is the FreeBSD install image.
  • Line 8 – IMG – the virtual disk we will install into. This is what I created using mkfile above. IMG is used within the IMG_HDD parameter (see below).
  • Line 11 – MEM – this system will have 2GB of RAM.
  • Line 12 – SMP – this system will have two CPUs.
  • Line 15 – IMG_CD – The image to be presented as a CD.
  • Line 16 – IMG_HDD – The definition of the hard drive image of the virtual disk.

    I do not know why both IMG_CD and USERBOOT both need to be specified.

    Running the script

    When I run this script, I am immediately presented with the FreeBSD splash screen.

    FreeBSD Splash Screen

    FreeBSD Splash Screen

    Shortly thereafter, you should get to select the console type. I pressed ENTER.

    Console Type

    Console Type

    Now you can begin the FreeBSD Install process. Details of this step are outside scope of this post.

    FreeBSD Installer

    FreeBSD Installer

    When the install script completes, you will back at the command line:

    Install completed

    Install completed

    Running the installed instance

    To create the run script, I copied the install script and modified it slightly.

    cp xhyve-cuppy-install.sh xhyve-cuppy.sh

    I commented out the IMG_CD parameter and changed BOOTVOLUME

    [dan@pro02:~/xhyve] $ cat xhyve-cuppy.sh
    #!/bin/sh
    
    UUID="-U deaddead-dead-dead-dead-deaddeaddead"
    
    IMG="/Users/dan/xhyve/cuppy.img"
    USERBOOT="/usr/local/Cellar/xhyve/HEAD-1f1dbe3/share/xhyve/test/userboot.so"
    BOOTVOLUME=$IMG
    
    KERNELENV=""
    
    MEM="-m 2G"
    SMP="-c 2"
    PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
    #NET="-s 2:0,virtio-net"
    #IMG_CD="-s 3:0,ahci-cd,/Users/dan/FreeBSD-11.2-RELEASE-amd64-disc1.iso"
    IMG_HDD="-s 4:0,virtio-blk,$IMG"
    LPC_DEV="-l com1,stdio"
    ACPI="-A"
    
    xhyve $ACPI $MEM $SMP $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_HDD $UUID -f fbsd,$USERBOOT,$BOOTVOLUME,"$KERNELENV"

    As you can see, I moved IMG up above BOOTVOLUME.

    To start my newly-installed FreeBSD service, I ran this command:

    ~/xhyve/xhyve-cuppy.sh

    The splash screen starts, and soon you have a login prompt. Here is what my installed instance looks like:

    zpool details

    zpool details

    More to do

    If you have more insight into the parameters for the scripts, please let me know and I will update this post.

    Now I have to install jails and get this instance up to speed.

    Thank you to those that helped.

    Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive