From owner-freebsd-virtualization@freebsd.org Sat Nov 11 15:45:06 2017
Return-Path:
Delivered-To: freebsd-virtualization@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
[IPv6:2001:1900:2254:206a::19:1])
by mailman.ysv.freebsd.org (Postfix) with ESMTP id 05E6CE6DB5B
for ;
Sat, 11 Nov 2017 15:45:06 +0000 (UTC) (envelope-from me@cschwarz.com)
Received: from orion.uberspace.de (orion.uberspace.de [95.143.172.79])
(using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client did not present a certificate)
by mx1.freebsd.org (Postfix) with ESMTPS id 73E0C647CC
for ; Sat, 11 Nov 2017 15:45:04 +0000 (UTC)
(envelope-from me@cschwarz.com)
Received: (qmail 1257 invoked from network); 11 Nov 2017 15:38:19 -0000
Received: from localhost (HELO csarch) (127.0.0.1)
by orion.uberspace.de with SMTP; 11 Nov 2017 15:38:19 -0000
Message-ID: <1510414698.13439.8.camel@cschwarz.com>
Subject: grub-bhyve: support overriding just --root flag
From: Christian Schwarz
To: freebsd-virtualization@freebsd.org
Date: Sat, 11 Nov 2017 16:38:18 +0100
Content-Type: text/plain; charset="UTF-8"
X-Mailer: Evolution 3.26.2
Mime-Version: 1.0
Content-Transfer-Encoding: 7bit
X-BeenThere: freebsd-virtualization@freebsd.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: "Discussion of various virtualization techniques FreeBSD supports."
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
X-List-Received-Date: Sat, 11 Nov 2017 15:45:06 -0000
(Disclaimer: also submitted this to the libvirt mailing list, but this list
seems more appropriate)
Hi,
I was trying to get a GPT-formatted VM boot on FreeBSD using the bhyve driver
and the grub-bhyve bootloader.
Turns out that libvirt 3.9.0 hardcodes the boot partition to (hd0,msdos1)
or allows overriding it completly using .
I hacked together a patch that allows overring just the --root argument to
grub-bhyve and updated the documentation:
https://github.com/problame/libvirt/commit/5fd1265c05987d907d9f1d9913dbee832a227889
Obviously, this does not meet quality standards and should not be merged as is,
but maybe spawn some discussion (if anyone is actually using bhyve + libvirt).
Cheers,
Christian
---
commit 5fd1265c05987d907d9f1d9913dbee832a227889
Author: Christian Schwarz
Date: Sat Nov 11 16:15:05 2017 +0100
bhyve: grub-bhyve: support overriding just the --root argument in domain config
diff --git a/docs/drvbhyve.html.in b/docs/drvbhyve.html.in
index 63260afae..2583bfa01 100644
--- a/docs/drvbhyve.html.in
+++ b/docs/drvbhyve.html.in
@@ -300,17 +300,26 @@ are omitted, libvirt will try and infer boot ordering from user-supplied
<boot order='N'> configuration in the domain. Failing that, it will boot
the first disk in the domain (either cdrom
- or
disk
-type devices). If the disk type is disk
, it will
-attempt to boot from the first partition in the disk image.
+attempt to boot from the first partition in the disk image, assuming
+an msdos
partitioning scheme
+(i.e. grub-bhyve --root hd0,msdos1
).
+You can override this behavior using bootloader_args
or bootloader_grub_root
.
+
...
<bootloader>/usr/local/sbin/grub-bhyve</bootloader>
+<!-- the following tag overrides all args to grub-bhyve -->
<bootloader_args>...</bootloader_args>
+<!-- the following tag overrides just the --root argument to grub-bhyve -->
+<bootloader_grub_root>hd0,gpt1</bootloader_grub_root>
...
-Caveat: bootloader_args
does not support any quoting.
-Filenames, etc, must not have spaces or they will be tokenized incorrectly.
+Caveats when using bootloader_args
: it does not support any quoting.
+Filenames, etc, must not have spaces or they will be tokenized incorrectly.
+Additionally, you will have to maintain your own --device-map
+file and keep it in sync with the domain XML.
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 55032ae1d..6cab6e516 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -774,15 +774,21 @@ virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
}
virCommandAddArg(cmd, "--root");
- if (userdef != NULL) {
- if (userdef->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+ if (def->os.bootloaderGrubRoot != NULL) {
+ virCommandAddArg(cmd, def->os.bootloaderGrubRoot);
+ } else {
+
+ if (userdef != NULL) {
+ if (userdef->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+ virCommandAddArg(cmd, "cd");
+ else
+ virCommandAddArg(cmd, "hd0,msdos1");
+ } else if (cd != NULL) {
virCommandAddArg(cmd, "cd");
- else
+ } else {
virCommandAddArg(cmd, "hd0,msdos1");
- } else if (cd != NULL) {
- virCommandAddArg(cmd, "cd");
- } else {
- virCommandAddArg(cmd, "hd0,msdos1");
+ }
+
}
virCommandAddArg(cmd, "--device-map");
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7dfd7b54e..ecd1f71dd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -18141,6 +18141,7 @@ virDomainDefParseXML(xmlDocPtr xml,
def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
+ def->os.bootloaderGrubRoot = virXPathString("string(./bootloader_grub_root)", ctxt);
tmp = virXPathString("string(./os/type[1])", ctxt);
if (!tmp) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e3f060b12..f969e9195 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1884,6 +1884,7 @@ struct _virDomainOSDef {
char *slic_table;
virDomainLoaderDefPtr loader;
char *bootloader;
+ char *bootloaderGrubRoot;
char *bootloaderArgs;
int smbios_mode;