bhyve: grub-bhyve: support overriding just --root flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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 <me@xxxxxxxxxxxx>
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
 &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 <code>bootloader_grub_root</code>.
+</p>
 
 <pre>
 ...
 &lt;bootloader&gt;/usr/local/sbin/grub-bhyve&lt;/bootloader&gt;
+&lt;!-- the following tag overrides all args to grub-bhyve --&gt;
 &lt;bootloader_args&gt;...&lt;/bootloader_args&gt;
+&lt;!-- the following tag overrides just the --root argument to grub-bhyve --&gt;
+&lt;bootloader_grub_root&gt;hd0,gpt1&lt;/bootloader_grub_root&gt;
 ...
 </pre>
 
-<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 quoting.
+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;
 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux