2015-08-10 09:18:46 +01:00
|
|
|
## vm-bhyve
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
Management system for FreeBSD bhyve virtual machines
|
2015-08-10 09:19:21 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
Some of the main features include:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
* Simple commands to create/start/stop bhyve instances
|
|
|
|
|
* Simple configuration file format
|
|
|
|
|
* Virtual switches supporting vlans & nat (no manual tap or bridge devices needed)
|
|
|
|
|
* ZFS support
|
2015-08-06 19:31:08 +01:00
|
|
|
* FreeBSD/NetBSD/OpenBSD/Linux guest support
|
2015-08-10 09:18:46 +01:00
|
|
|
* Automatic assignment of console devices to access guest console
|
|
|
|
|
* Integreation with rc.d startup/shutdown
|
|
|
|
|
* Guest reboot handling
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
## Install
|
2015-06-30 08:37:37 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
Download the latest release from Github, or download from the following URL
|
|
|
|
|
[http://churchers.hostingspace.co.uk/vm-bhyve-latest.tgz](http://churchers.hostingspace.co.uk/vm-bhyve-latest.tgz)
|
2015-06-30 08:37:37 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
To install, just run the following command inside the vm-bhyve source directory
|
2015-07-11 11:54:22 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# make install
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
## Initial configuration
|
2015-07-11 11:54:22 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
First of all you will need a directory to store all your virtual machines and vm-bhyve configuration.
|
|
|
|
|
If you are not using ZFS, just create a normal directory:
|
2015-06-24 12:20:49 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# mkdir /somefolder/vm
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
If you are using ZFS, create a dataset to hold vm-bhyve data
|
|
|
|
|
|
|
|
|
|
# zfs create pool/vm
|
|
|
|
|
|
|
|
|
|
Now update /etc/rc.conf to enable vm-bhyve, and tell it where your directory is
|
2015-06-24 09:58:30 +01:00
|
|
|
|
|
|
|
|
vm_enable="YES"
|
2015-08-10 09:18:46 +01:00
|
|
|
vm_dir="/somefolder/vm"
|
|
|
|
|
|
|
|
|
|
Or with ZFS:
|
2015-08-06 19:31:08 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
vm_enable="YES"
|
|
|
|
|
vm_dir="zfs:pool/vm"
|
2015-08-06 19:31:08 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
This directory will be referred to as $vm_dir in the rest of this readme.
|
2015-08-07 11:03:26 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
Now run the following command to create the directories used to store vm-bhvye configuration.
|
|
|
|
|
This needs to be run once after each host reboot, which is normally handled by the rc.d script
|
2015-06-24 10:06:54 +01:00
|
|
|
|
2015-06-24 09:58:30 +01:00
|
|
|
# vm init
|
|
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
## Virtual machine templates
|
|
|
|
|
|
|
|
|
|
When creating a virtual machine, you use a template which defines how much memory to give the guest,
|
|
|
|
|
how many cpu cores and networking/disk configuration. The templates are all stored inside $vm_dir/.templates.
|
|
|
|
|
To install the sample templates, run the following command:
|
|
|
|
|
|
|
|
|
|
# cp /usr/local/share/examples/vm-bhyve/* /my/vm/path/.templates/
|
|
|
|
|
|
|
|
|
|
If you look inside the template files with a text editor, you will see they are very simple. You
|
|
|
|
|
can create as many templates as you like. For example for could have web-server.conf, containing the setting
|
|
|
|
|
for your web servers, or freebsd-large.conf for large FreeBSD guests, and so on.
|
|
|
|
|
|
|
|
|
|
You will notice that each template is set to create one network interface. You can easily add more network
|
|
|
|
|
interfaces by duplicating the two network configuration options. In general you will not want to change the
|
|
|
|
|
type from 'virtio-net', but you will notice the first interface is set to connect to a switch called 'public'.
|
|
|
|
|
See the next section for details on how to configure virtual switches.
|
|
|
|
|
|
|
|
|
|
## Virtual Switches
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
When a guest is started, each network interface is automatically connected to the virtual switch specified
|
|
|
|
|
in the configuration file. By default all the sample templates connect to a switch called 'public', although
|
|
|
|
|
you can use any name. The following section shows how to create a switch called 'public', and configure various
|
|
|
|
|
settings:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
|
|
|
|
# vm switch create public
|
2015-08-10 09:18:46 +01:00
|
|
|
|
|
|
|
|
If you just want to bridge guests to your physical network, add the appropriate real interface to the switch.
|
|
|
|
|
Obviously you will need to replace em0 here with the correct interface name:
|
|
|
|
|
|
2015-06-24 09:58:30 +01:00
|
|
|
# vm switch add public em0
|
2015-08-10 09:18:46 +01:00
|
|
|
|
|
|
|
|
If you want to use NAT, do not add a physical interface to the switch, as the switch will be on the private
|
|
|
|
|
side of the NAT network. Just enable NAT on the switch:
|
|
|
|
|
|
|
|
|
|
# vm switch nat public on
|
|
|
|
|
|
|
|
|
|
This will automatically create a private network on the switch, enable DHCP for it, and forward guest traffic
|
|
|
|
|
via your default gateway. Please note that NAT functionality requires the dnsmasq package to be installed,
|
|
|
|
|
and both dnsmasq & pf must be enabled in /etc/rc.conf. See the man page for more details.
|
|
|
|
|
|
|
|
|
|
If you want guest traffic to be on a specific VLAN when leaving the host, specify a vlan number. To turn
|
|
|
|
|
off vlans, just set the vlan number to 0:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
|
|
|
|
# vm switch vlan public 10
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm switch vlan public 0
|
|
|
|
|
|
|
|
|
|
You can view current switch configuration using the list command:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
|
|
|
|
# vm switch list
|
2015-08-07 16:52:07 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
## Creating virtual machines
|
2015-08-07 16:52:07 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
Use one of the following command to create a new virtual machine:
|
2015-08-07 16:52:07 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm create testvm
|
|
|
|
|
# vm create -t templatename -s 50G testvm
|
2015-08-07 16:52:07 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
The first example uses the default.conf template, and will create a 20GB disk image. The second
|
|
|
|
|
example specifies the templatename.conf template, and tells vm-bhyve to create a 50GB disk.
|
2015-08-08 12:21:01 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
You will need an ISO to install the guest with, so download one using the iso command:
|
2015-08-07 16:52:07 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm iso ftp://ftp.freebsd.org/pub/FreeBSD/releases/ISO-IMAGES/10.1/FreeBSD-10.1-RELEASE-amd64-disc1.iso
|
2015-08-07 16:52:07 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
To start a guest install, run the following command. vm-bhyve will run the machine in the background,
|
|
|
|
|
so use the console command to connect to it and finish installation.
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm install testvm FreeBSD-10.1-RELEASE-amd64-disc1.iso
|
|
|
|
|
# vm console testvm
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
Once installation has finished, you can reboot the guest from inside the console and it will boot up into
|
|
|
|
|
the new OS as expected (assuming installation was successful). Further reboots will work as expected and
|
|
|
|
|
the guest can be shutdown in the normal way. As the console uses the cu command, type ~+Ctrl-D to exit
|
|
|
|
|
back to your host.
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
The following commands start and stop virtual machines:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm start testvm
|
|
|
|
|
# vm stop testvm
|
2015-06-24 10:21:48 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
The basic configuration of each machine and state can be viewed using the list command:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm list
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
All running machines can be stopped using the stopall command
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm stopall
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
On host boot, vm-bhyve will use the 'vm startall' command to start all machines. You can
|
|
|
|
|
control which guests start automatically using the following variables in /etc/rc.conf:
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
vm_list="vm1 vm2"
|
|
|
|
|
vm_delay="5"
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
The first defines the list of machines to start on boot, and the order to start them. The second
|
|
|
|
|
is the number of seconds to wait between starting each one. 5 seconds is the recommended setting,
|
|
|
|
|
although a longer delay is useful if you have disk intensive guests and don't want them all booting
|
|
|
|
|
at the same time.
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
There's also a command which opens a guest's confiuration file in your default text editor, allowing
|
|
|
|
|
you to easily make changes to the configuration. Please note that changes only take effect after
|
|
|
|
|
a full shutdown and restart of the guest
|
2015-06-24 09:58:30 +01:00
|
|
|
|
2015-08-10 09:18:46 +01:00
|
|
|
# vm configure testvm
|