This post describes how to make ‘clones’ of VMs that can be booted in xhyve.
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 testrun.sh instead of xhyverun_ubuntu.sh). 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:
- 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 testrun.sh testrun-clone.sh
- 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"
PCI_DEV="-s 0:0,hostbridge -s 31,lpc"
build/xhyve $MEM $SMP $PCI_DEV $LPC_DEV $NET $IMG_CD $IMG_HDD -f kexec,$KERNEL,$INITRD,"$CMDLINE"
The one line I changed was:
- Launch the script to boot the ‘cloned’ VM:
$ sudo ./testrun-clone.sh
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.