mirror of
https://github.com/churchers/vm-bhyve.git
synced 2025-12-11 09:20:17 +01:00
Allow multiple disks in templates
We now allow a template to specify multiple disk, which will all be created automatically when provisioning a new guest. The template can also specify the size of each disk, using diskX_size settings. These settings are removed from the guest configuration file as they serve no purpose and would become misleading if a disk were resized manually.
This commit is contained in:
58
lib/vm-core
58
lib/vm-core
@@ -81,19 +81,13 @@ __vm_check_name(){
|
||||
#
|
||||
__vm_create(){
|
||||
local _name _template _opt _size _vmdir _disk _disk_dev _uuid
|
||||
local _zfs_opts
|
||||
local _zfs_opts _num=0 _disk_size
|
||||
|
||||
while getopts t:s: _opt ; do
|
||||
case $_opt in
|
||||
t)
|
||||
_template=${OPTARG}
|
||||
;;
|
||||
s)
|
||||
_size=${OPTARG}
|
||||
;;
|
||||
*)
|
||||
__usage
|
||||
;;
|
||||
t) _template=${OPTARG} ;;
|
||||
s) _size=${OPTARG} ;;
|
||||
*) __usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -103,7 +97,7 @@ __vm_create(){
|
||||
[ -z "${_name}" ] && __usage
|
||||
__vm_check_name "${_name}"
|
||||
|
||||
: ${_size:=20G}
|
||||
# use default.conf template if none specified
|
||||
: ${_template:=default}
|
||||
|
||||
[ ! -f "${vm_dir}/.templates/${_template}.conf" ] && \
|
||||
@@ -113,8 +107,10 @@ __vm_create(){
|
||||
__config_load "${vm_dir}/.templates/${_template}.conf"
|
||||
__config_get "_disk" "disk0_name"
|
||||
__config_get "_disk_dev" "disk0_dev"
|
||||
__config_get "_disk_size" "disk0_size" "20G"
|
||||
__config_get "_zfs_opts" "zfs_dataset_opts"
|
||||
|
||||
# make sure template has a disk before we start creating anything
|
||||
[ -z "${_disk}" ] && __err "template is missing disk0_name specification"
|
||||
|
||||
# get the directory to store our vm data in
|
||||
@@ -138,19 +134,33 @@ __vm_create(){
|
||||
# get any zvol options
|
||||
__config_get "_zfs_opts" "zfs_zvol_opts"
|
||||
|
||||
# create the disk
|
||||
case "${_disk_dev}" in
|
||||
zvol)
|
||||
__zfs_make_zvol "${_name}/${_disk}" "${_size}" "0" "${_zfs_opts}"
|
||||
;;
|
||||
sparse-zvol)
|
||||
__zfs_make_zvol "${_name}/${_disk}" "${_size}" "1" "${_zfs_opts}"
|
||||
;;
|
||||
*)
|
||||
truncate -s "${_size}" "${_vmdir}/${_disk}"
|
||||
[ $? -ne 0 ] && __err "failed to create sparse file for disk image"
|
||||
;;
|
||||
esac
|
||||
# use cmd line size for disk 0 if specified
|
||||
[ -n "${_size}" ] && _disk_size="${_size}"
|
||||
|
||||
# create each disk
|
||||
while [ -n "${_disk}" ]; do
|
||||
case "${_disk_dev}" in
|
||||
zvol)
|
||||
__zfs_make_zvol "${_name}/${_disk}" "${_disk_size}" "0" "${_zfs_opts}"
|
||||
;;
|
||||
sparse-zvol)
|
||||
__zfs_make_zvol "${_name}/${_disk}" "${_disk_size}" "1" "${_zfs_opts}"
|
||||
;;
|
||||
*)
|
||||
truncate -s "${_disk_size}" "${_vmdir}/${_disk}"
|
||||
[ $? -ne 0 ] && __err "failed to create sparse file for disk image"
|
||||
;;
|
||||
esac
|
||||
|
||||
# scrap size option from guest template
|
||||
sysrc -inxqf "${_vmdir}/${_name}.conf" "disk${_num}_size"
|
||||
|
||||
# look for another disk
|
||||
_num=$((_num + 1))
|
||||
__config_get "_disk" "disk${_num}_name"
|
||||
__config_get "_disk_dev" "disk${_num}_dev"
|
||||
__config_get "_disk_size" "disk${_num}_size" "20G"
|
||||
done
|
||||
}
|
||||
|
||||
# 'vm add'
|
||||
|
||||
@@ -52,8 +52,7 @@ __vm_set_rctl_limits(){
|
||||
|
||||
# see if rctl works
|
||||
/usr/bin/rctl >/dev/null 2>&1
|
||||
_exit=$?
|
||||
[ ${_exit} -ne 0 ] && \
|
||||
[ $? -ne 0 ] && \
|
||||
__log "guest" "${_name}" "RCTL support requested but RCTL not available" && return 1
|
||||
|
||||
__log "guest" "${_name}" "applying rctl limits"
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
# This is a sample configuration file containing all supported options
|
||||
# Please do not try and use this for a guest
|
||||
# For any option that contains a number in the name, such as "disk0_name",
|
||||
# For any option that contains a number in the name, such as "network0_type",
|
||||
# you can add additional devices of that type by creating a new set of
|
||||
# variables using the next number in sequence, e.g "disk1_name"
|
||||
# variables using the next number in sequence, e.g "network1_type"
|
||||
# The only exception to this is that only one disk device is supported
|
||||
# in templates. If additional disks are required, they will need to be
|
||||
# added once the guest has been created.
|
||||
#
|
||||
# Please make sure all option names are specified in lowercase and
|
||||
# at the beginning of the line. If there is any whitespace before
|
||||
@@ -160,6 +163,22 @@ disk0_name="disk0.img"
|
||||
#
|
||||
disk0_opts=""
|
||||
|
||||
# disk0_size
|
||||
# When a new guest is created, vm will create a 20G disk image by
|
||||
# default. This option can be used to specify a different size
|
||||
# for this disk.
|
||||
#
|
||||
# The size of the first disk (disk0) can also be overridden
|
||||
# using the -s option to 'vm create'.
|
||||
#
|
||||
# NOTE: This option is only supported in template files. This
|
||||
# setting serves no purpose in real guests and would become
|
||||
# misleading if a disk were resized manually. When provisioning
|
||||
# a new guest, all 'diskX_size' options are stripped from
|
||||
# its configuration file.
|
||||
#
|
||||
disk0_size="50"
|
||||
|
||||
# network0_type
|
||||
# This specifies the emulation type to use for the first network interface.
|
||||
# Networking is not required, although this field is mandatory if you do want
|
||||
@@ -189,8 +208,12 @@ network0_device=""
|
||||
|
||||
# network0_mac
|
||||
# This allows you to specify a fixed mac address for this interface inside the guest.
|
||||
# Without this option, bhyve will automatically assign a mac address to the
|
||||
# interface.
|
||||
# When a guest is run, vm-bhyve will automatically assign a mac address for each
|
||||
# interface if one is not specified. This mac address is then written to the
|
||||
# configuration file using this option. If we didn't do this guests might get
|
||||
# a different mac if the tap device changes (very possible in vm-bhyve as all
|
||||
# tap devices are dynamic by default). Guests like Windows treat an interface
|
||||
# with a different mac as a new interface, with a new set of default settings.
|
||||
#
|
||||
network0_mac=""
|
||||
|
||||
@@ -203,6 +226,10 @@ network0_mac=""
|
||||
# Please note that in order to stop the bhyve host from attaching to the device,
|
||||
# there are some steps required to reserve the device in /boot/loader.conf.
|
||||
#
|
||||
# The 'vm passthru' command provides a convinient way of seeing the BSF of each
|
||||
# device in your system, and whether any have been reserved ready for use
|
||||
# in bhyve
|
||||
#
|
||||
# More details can be found in the FreeBSD bhyve wiki pages
|
||||
#
|
||||
passthru0=""
|
||||
@@ -227,11 +254,6 @@ grub_install1="..."
|
||||
# use this to specify grub commands to run when starting the guest
|
||||
# normally
|
||||
#
|
||||
# As with the install commands, 'boot' needs to be specified if it
|
||||
# is required. (I'm not aware of any situation where it isn't, but
|
||||
# have decided to require it rather than hardcode it in the vm-bhyve
|
||||
# source, just in case there are any exceptions)
|
||||
#
|
||||
grub_run0="linux ..."
|
||||
grub_run1="initrd ..."
|
||||
|
||||
|
||||
12
vm.8
12
vm.8
@@ -866,6 +866,18 @@ Any additional options to use for this disk device. Multiple options can be spec
|
||||
separated by a comma. Please see the
|
||||
.Xr bhyve 8
|
||||
man page for more details on supported options.
|
||||
.It disk0_size
|
||||
This setting can be specified in templates to set the size of this disk.
|
||||
When creating a guest,
|
||||
.Nm
|
||||
will default to creating a 20G image for each disk, unless an alternative size is
|
||||
specified using this option. The size of the first disk can be overridden using
|
||||
the
|
||||
.Sy -s
|
||||
command line option.
|
||||
.Pp
|
||||
NOTE: This setting is only supported in templates. It has no function in
|
||||
real guest configuration, and is not copied over when a new machine is provisioned
|
||||
.It uuid
|
||||
This option allows you to specify a fixed UUID for the guests SMBIOS. Normally, the
|
||||
UUID is generated by
|
||||
|
||||
Reference in New Issue
Block a user