(Disclaimer: also submitted this to the libvirt mailing list, but this list
 seems more appropriate)


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 <bootloader_args>.

I hacked together a patch that allows overring just the --root argument to
grub-bhyve and updated the documentation:


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).




commit 5fd1265c05987d907d9f1d9913dbee832a227889
Author: Christian Schwarz <m...@cschwarz.com>
Date:   Sat Nov 11 16:15:05 2017 +0100

    bhyve: grub-bhyve: support overriding just the --root argument in domain 

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
 &lt;boot order='N'&gt; configuration in the domain. Failing that, it will boot
 the first disk in the domain (either <code>cdrom</code>- or
 <code>disk</code>-type devices). If the disk type is <code>disk</code>, it will
-attempt to boot from the first partition in the disk image.</p>
+attempt to boot from the first partition in the disk image, assuming
+an <code>msdos</code> partitioning scheme
+(i.e. <code>grub-bhyve --root hd0,msdos1</code>).
+You can override this behavior using <code>bootloader_args</code> or 
+&lt;!-- the following tag overrides all args to grub-bhyve --&gt;
+&lt;!-- the following tag overrides just the --root argument to grub-bhyve 
-<p>Caveat: <code>bootloader_args</code> does not support any quoting.
-Filenames, etc, must not have spaces or they will be tokenized incorrectly.</p>
+<p>Caveats when using <code>bootloader_args</code>: it  does not support any 
+Filenames, etc, must not have spaces or they will be tokenized incorrectly.
+Additionally, you will have to maintain your own <code>--device-map</code>
+file and keep it in sync with the domain XML.</p>
 <h3><a id="uefi">Using UEFI bootrom, VNC, and USB tablet</a></h3>
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;
freebsd-virtualization@freebsd.org mailing list
To unsubscribe, send any mail to 

Reply via email to