Add an option to bhyveload(8) that allows setting a loader environment variable
from the command line. The option syntax is "-e <name=value>". It may be used multiple times to set multiple environment variables. Reviewed by: grehan Requested by: alfred
This commit is contained in:
parent
5d452cea64
commit
b6afa84b8c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=256657
@ -39,11 +39,12 @@ DEFAULT_VIRTIO_DISK="./diskdev"
|
|||||||
DEFAULT_ISOFILE="./release.iso"
|
DEFAULT_ISOFILE="./release.iso"
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage: vmrun.sh [-hai][-g <gdbport>][-m <memsize>][-d <disk file>][-I <location of installation iso>][-t <tapdev>] <vmname>"
|
echo "Usage: vmrun.sh [-hai][-g <gdbport>][-m <memsize>][-d <disk file>][-e <name=value>][-I <location of installation iso>][-t <tapdev>] <vmname>"
|
||||||
echo " -h: display this help message"
|
echo " -h: display this help message"
|
||||||
echo " -a: force memory mapped local apic access"
|
echo " -a: force memory mapped local apic access"
|
||||||
echo " -c: number of virtual cpus (default is ${DEFAULT_CPUS})"
|
echo " -c: number of virtual cpus (default is ${DEFAULT_CPUS})"
|
||||||
echo " -d: virtio diskdev file (default is ${DEFAULT_VIRTIO_DISK})"
|
echo " -d: virtio diskdev file (default is ${DEFAULT_VIRTIO_DISK})"
|
||||||
|
echo " -e: set FreeBSD loader environment variable"
|
||||||
echo " -g: listen for connection from kgdb at <gdbport>"
|
echo " -g: listen for connection from kgdb at <gdbport>"
|
||||||
echo " -i: force boot of the Installation CDROM image"
|
echo " -i: force boot of the Installation CDROM image"
|
||||||
echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})"
|
echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})"
|
||||||
@ -73,8 +74,9 @@ virtio_diskdev=${DEFAULT_VIRTIO_DISK}
|
|||||||
tapdev=${DEFAULT_TAPDEV}
|
tapdev=${DEFAULT_TAPDEV}
|
||||||
apic_opt=""
|
apic_opt=""
|
||||||
gdbport=0
|
gdbport=0
|
||||||
|
env_opt=""
|
||||||
|
|
||||||
while getopts haic:g:I:m:d:t: c ; do
|
while getopts haic:e:g:I:m:d:t: c ; do
|
||||||
case $c in
|
case $c in
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
@ -85,6 +87,9 @@ while getopts haic:g:I:m:d:t: c ; do
|
|||||||
d)
|
d)
|
||||||
virtio_diskdev=${OPTARG}
|
virtio_diskdev=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
e)
|
||||||
|
env_opt="${env_opt} -e ${OPTARG}"
|
||||||
|
;;
|
||||||
g) gdbport=${OPTARG}
|
g) gdbport=${OPTARG}
|
||||||
;;
|
;;
|
||||||
i)
|
i)
|
||||||
@ -163,7 +168,7 @@ while [ 1 ]; do
|
|||||||
installer_opt=""
|
installer_opt=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
${LOADER} -m ${memsize} -d ${BOOTDISK} ${vmname}
|
${LOADER} -m ${memsize} -d ${BOOTDISK} ${env_opt} ${vmname}
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
@ -38,6 +38,7 @@ guest inside a bhyve virtual machine
|
|||||||
.Op Fl m Ar mem-size
|
.Op Fl m Ar mem-size
|
||||||
.Op Fl d Ar disk-path
|
.Op Fl d Ar disk-path
|
||||||
.Op Fl h Ar host-path
|
.Op Fl h Ar host-path
|
||||||
|
.Op Fl e Ar name=value
|
||||||
.Ar vmname
|
.Ar vmname
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
@ -91,6 +92,14 @@ is the pathname of the guest's boot disk image.
|
|||||||
The
|
The
|
||||||
.Ar host-path
|
.Ar host-path
|
||||||
is the directory at the top of the guest's boot filesystem.
|
is the directory at the top of the guest's boot filesystem.
|
||||||
|
.It Fl e Ar name=value
|
||||||
|
Set the FreeBSD loader environment variable
|
||||||
|
.Ar name
|
||||||
|
to
|
||||||
|
.Ar value .
|
||||||
|
.Pp
|
||||||
|
The option may be used more than once to set more than one environment
|
||||||
|
variable.
|
||||||
.El
|
.El
|
||||||
.Sh EXAMPLES
|
.Sh EXAMPLES
|
||||||
To create a virtual machine named
|
To create a virtual machine named
|
||||||
|
@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/disk.h>
|
#include <sys/disk.h>
|
||||||
|
#include <sys/queue.h>
|
||||||
|
|
||||||
#include <machine/specialreg.h>
|
#include <machine/specialreg.h>
|
||||||
#include <machine/vmm.h>
|
#include <machine/vmm.h>
|
||||||
@ -498,23 +499,37 @@ cb_getmem(void *arg, uint64_t *ret_lowmem, uint64_t *ret_highmem)
|
|||||||
vm_get_memory_seg(ctx, 4 * GB, ret_highmem, NULL);
|
vm_get_memory_seg(ctx, 4 * GB, ret_highmem, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct env {
|
||||||
|
const char *str; /* name=value */
|
||||||
|
SLIST_ENTRY(env) next;
|
||||||
|
};
|
||||||
|
|
||||||
|
static SLIST_HEAD(envhead, env) envhead;
|
||||||
|
|
||||||
|
static void
|
||||||
|
addenv(const char *str)
|
||||||
|
{
|
||||||
|
struct env *env;
|
||||||
|
|
||||||
|
env = malloc(sizeof(struct env));
|
||||||
|
env->str = str;
|
||||||
|
SLIST_INSERT_HEAD(&envhead, env, next);
|
||||||
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
cb_getenv(void *arg, int num)
|
cb_getenv(void *arg, int num)
|
||||||
{
|
{
|
||||||
int max;
|
int i;
|
||||||
|
struct env *env;
|
||||||
|
|
||||||
static const char * var[] = {
|
i = 0;
|
||||||
"smbios.bios.vendor=BHYVE",
|
SLIST_FOREACH(env, &envhead, next) {
|
||||||
"boot_serial=1",
|
if (i == num)
|
||||||
NULL
|
return (env->str);
|
||||||
};
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
max = sizeof(var) / sizeof(var[0]);
|
return (NULL);
|
||||||
|
|
||||||
if (num < max)
|
|
||||||
return (var[num]);
|
|
||||||
else
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct loader_callbacks cb = {
|
static struct loader_callbacks cb = {
|
||||||
@ -553,8 +568,8 @@ usage(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: %s [-m mem-size][-d <disk-path>] [-h <host-path>] "
|
"usage: %s [-m mem-size][-d <disk-path>] [-h <host-path>] "
|
||||||
"<vmname>\n", progname);
|
"[-e <name=value>] <vmname>\n", progname);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -572,12 +587,16 @@ main(int argc, char** argv)
|
|||||||
mem_size = 256 * MB;
|
mem_size = 256 * MB;
|
||||||
disk_image = NULL;
|
disk_image = NULL;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "d:h:m:")) != -1) {
|
while ((opt = getopt(argc, argv, "d:e:h:m:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
disk_image = optarg;
|
disk_image = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
addenv(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
host_base = optarg;
|
host_base = optarg;
|
||||||
break;
|
break;
|
||||||
@ -638,5 +657,9 @@ main(int argc, char** argv)
|
|||||||
if (disk_image) {
|
if (disk_image) {
|
||||||
disk_fd = open(disk_image, O_RDONLY);
|
disk_fd = open(disk_image, O_RDONLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addenv("smbios.bios.vendor=BHYVE");
|
||||||
|
addenv("boot_serial=1");
|
||||||
|
|
||||||
func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0);
|
func(&cb, NULL, USERBOOT_VERSION_3, disk_fd >= 0);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user