Add option -l for specifying which OS loader to dlopen(3). By default

this is /boot/userboot.so. This option allows for the development and
use of other OS loaders.
This commit is contained in:
Marcel Moolenaar 2015-10-08 02:28:22 +00:00
parent 6cc056de26
commit 8c96dcc166
3 changed files with 52 additions and 14 deletions

View File

@ -48,8 +48,8 @@ usage() {
echo "Usage: vmrun.sh [-ahi] [-c <CPUs>] [-C <console>] [-d <disk file>]"
echo " [-e <name=value>] [-g <gdbport> ] [-H <directory>]"
echo " [-I <location of installation iso>] [-m <memsize>]"
echo " [-t <tapdev>] <vmname>"
echo " [-I <location of installation iso>] [-l <loader>]"
echo " [-m <memsize>] [-t <tapdev>] <vmname>"
echo ""
echo " -h: display this help message"
echo " -a: force memory mapped local APIC access"
@ -61,6 +61,7 @@ usage() {
echo " -H: host filesystem to export to the loader"
echo " -i: force boot of the Installation CDROM image"
echo " -I: Installation CDROM image location (default is ${DEFAULT_ISOFILE})"
echo " -l: the OS loader to use (default is /boot/userboot.so)"
echo " -m: memory size (default is ${DEFAULT_MEMSIZE})"
echo " -p: pass-through a host PCI device at bus/slot/func (e.g. 10/0/0)"
echo " -t: tap device for virtio-net (default is $DEFAULT_TAPDEV)"
@ -92,7 +93,7 @@ loader_opt=""
bhyverun_opt="-H -A -P"
pass_total=0
while getopts ac:C:d:e:g:hH:iI:m:p:t: c ; do
while getopts ac:C:d:e:g:hH:iI:l:m:p:t: c ; do
case $c in
a)
bhyverun_opt="${bhyverun_opt} -a"
@ -125,6 +126,9 @@ while getopts ac:C:d:e:g:hH:iI:m:p:t: c ; do
I)
isofile=${OPTARG}
;;
l)
loader_opt="${loader_opt} -l ${OPTARG}"
;;
m)
memsize=${OPTARG}
;;

View File

@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd January 7, 2012
.Dd October 7, 2015
.Dt BHYVELOAD 8
.Os
.Sh NAME
@ -40,6 +40,7 @@ guest inside a bhyve virtual machine
.Op Fl d Ar disk-path
.Op Fl e Ar name=value
.Op Fl h Ar host-path
.Op Fl l Ar os-loader
.Op Fl m Ar mem-size
.Ar vmname
.Sh DESCRIPTION
@ -56,6 +57,7 @@ is based on
and will present an interface identical to the
.Fx
loader on the user's terminal.
This behavior can be changed by specifying a different OS loader.
.Pp
The virtual machine is identified as
.Ar vmname
@ -78,7 +80,9 @@ The
.Ar disk-path
is the pathname of the guest's boot disk image.
.It Fl e Ar name=value
Set the FreeBSD loader environment variable
Set the
.Fx
loader environment variable
.Ar name
to
.Ar value .
@ -89,6 +93,15 @@ variable.
The
.Ar host-path
is the directory at the top of the guest's boot filesystem.
.It Fl l Ar os-loader
Specify a different OS loader.
By default
.Nm
will use
.Pa /boot/userboot.so ,
which presents a standard
.Fx
loader.
.It Fl m Ar mem-size Xo
.Sm off
.Op Cm K | k | M | m | G | g | T | t

View File

@ -639,6 +639,7 @@ usage(void)
int
main(int argc, char** argv)
{
char *loader;
void *h;
void (*func)(struct loader_callbacks *, void *, int, int);
uint64_t mem_size;
@ -646,13 +647,15 @@ main(int argc, char** argv)
progname = basename(argv[0]);
loader = NULL;
memflags = 0;
mem_size = 256 * MB;
consin_fd = STDIN_FILENO;
consout_fd = STDOUT_FILENO;
while ((opt = getopt(argc, argv, "Sc:d:e:h:m:")) != -1) {
while ((opt = getopt(argc, argv, "Sc:d:e:h:l:m:")) != -1) {
switch (opt) {
case 'c':
error = altcons_open(optarg);
@ -674,6 +677,14 @@ main(int argc, char** argv)
host_base = optarg;
break;
case 'l':
if (loader != NULL)
errx(EX_USAGE, "-l can only be given once");
loader = strdup(optarg);
if (loader == NULL)
err(EX_OSERR, "malloc");
break;
case 'm':
error = vm_parse_memsize(optarg, &mem_size);
if (error != 0)
@ -726,26 +737,36 @@ main(int argc, char** argv)
exit(1);
}
tcgetattr(consout_fd, &term);
oldterm = term;
cfmakeraw(&term);
term.c_cflag |= CLOCAL;
tcsetattr(consout_fd, TCSAFLUSH, &term);
h = dlopen("/boot/userboot.so", RTLD_LOCAL);
if (loader == NULL) {
loader = strdup("/boot/userboot.so");
if (loader == NULL)
err(EX_OSERR, "malloc");
}
h = dlopen(loader, RTLD_LOCAL);
if (!h) {
printf("%s\n", dlerror());
free(loader);
return (1);
}
func = dlsym(h, "loader_main");
if (!func) {
printf("%s\n", dlerror());
free(loader);
return (1);
}
tcgetattr(consout_fd, &term);
oldterm = term;
cfmakeraw(&term);
term.c_cflag |= CLOCAL;
tcsetattr(consout_fd, TCSAFLUSH, &term);
addenv("smbios.bios.vendor=BHYVE");
addenv("boot_serial=1");
func(&cb, NULL, USERBOOT_VERSION_3, ndisks);
free(loader);
return (0);
}