Manually ‘cloning’ VMs for xhyve.

This post describes how to make ‘clones’ of VMs that can be booted in xhyve.


xhyve is a hypervisor for OS X, and is a port of bhyve, the FreeBSD hypervisor. I had been using VirtualBox on my MacBook, and a friend told me about xhyve, so I decided to give it a try.

I followed this page to get my initial Ubuntu VM up and running (it went swimmingly), set it up for my test environment, etc…but then I needed copies of that VM. If I was using VirtualBox, I’d clone the VM at that point, but a quick search on Google didn’t seem to turn anything up for xhyve. So after a minute or so of playing around, the following is what I ended up with.


I didn’t stray too far from the setup in the page mentioned above, so I have an ubuntu/ directory in the root directory of my copy of the xhyve repo. In ubuntu/  are:

  • the ubuntu install iso
  • extracted kernel and initrd (vmlinuz and initrd.gz)
  • installed kernel copied to the host (the boot directory)
  • the virtual hard disk image for the VM (hdd.img)

Like in the tutorial, the script to launch the VM is in the xhyve root directory (I called it instead of What I want to now do is make copies of this VM.


Since initrd.gz, vmlinuz, and all of the contents of boot can be read-only (and are by default), the only thing that really needs to be different per VM is the hard disk image and the startup script. Sot he steps are:

  1. Copy the hard disk image (this may take a while) and the startup script, so the new hard disk image is in ubuntu and the script is in xhyve.

    $ cd ubuntu
    $ cp hdd.img hdd-clone.img
    $ cd ..
    $ cp

  2. Modify the new launch script to point to the copy of the hard disk image. The original script’s contents look like:


    CMDLINE="earlyprintk=serial console=ttyS0 acpi=off root=/dev/vda1 ro"

    MEM="-m 1G"
    #SMP="-c 2"
    NET="-s 2:0,virtio-net"
    IMG_HDD="-s 4,virtio-blk,ubuntu/hdd.img"
    PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
    LPC_DEV="-l com1,stdio"


    The one line I changed was:

    IMG_HDD="-s 4,virtio-blk,ubuntu/hdd-clone.img"

  3. Launch the script to boot the ‘cloned’ VM:

    $ sudo ./

The new VM should unsurprisingly have all of the things you had set up in your original VM. At least unlike my VirtualBox clones, the hardware addresses for the network interfaces seem to be randomized automatically, so I don’t have to manually fix them so that they acquire new IP addresses.

One issue I haven’t worked out is fixing the IP across reboots with the -U [UUID] flag – Adding that parameter seems to make xhyve silently fail and exit, though that might just be user error on my part.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s