<p>It's possible to boot non-FreeBSD guests by specifying an explicit
bootloader, e.g. <code>grub-bhyve(1)</code>. Arguments to the bootloader may be
specified as well. If the bootloader is <code>grub-bhyve</code> and arguments
-are omitted, libvirt will try and 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>
+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 <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>
<pre>
...
return true;
}
+static void
+virBhyveFormatGrubDevice(virBufferPtr devicemap, virDomainDiskDefPtr def)
+{
+
+ if (def->device == VIR_DOMAIN_DISK_DEVICE_CDROM)
+ virBufferAsprintf(devicemap, "(cd) %s\n",
+ virDomainDiskGetSource(def));
+ else
+ virBufferAsprintf(devicemap, "(hd0) %s\n",
+ virDomainDiskGetSource(def));
+}
+
static virCommandPtr
virBhyveProcessBuildGrubbhyveCmd(virDomainDefPtr def,
virConnectPtr conn,
const char *devmap_file,
char **devicesmap_out)
{
- virDomainDiskDefPtr disk, cd;
+ virDomainDiskDefPtr hdd, cd, userdef, diskdef;
virBuffer devicemap;
virCommandPtr cmd;
+ int best_idx;
size_t i;
if (def->os.bootloaderArgs != NULL)
return virBhyveProcessBuildCustomLoaderCmd(def);
+ best_idx = INT_MAX;
devicemap = (virBuffer)VIR_BUFFER_INITIALIZER;
- /* Search disk list for CD or HDD device. */
- cd = disk = NULL;
+ /* Search disk list for CD or HDD device. We'll respect <boot order=''> if
+ * present and otherwise pick the first CD or failing that HDD we come
+ * across. */
+ cd = hdd = userdef = NULL;
for (i = 0; i < def->ndisks; i++) {
if (!virBhyveUsableDisk(conn, def->disks[i]))
continue;
+ diskdef = def->disks[i];
+
+ if (diskdef->info.bootIndex && diskdef->info.bootIndex < best_idx) {
+ userdef = diskdef;
+ best_idx = userdef->info.bootIndex;
+ continue;
+ }
+
if (cd == NULL &&
def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
- cd = def->disks[i];
- VIR_INFO("Picking %s as boot CD", virDomainDiskGetSource(cd));
+ cd = diskdef;
+ VIR_INFO("Picking %s as CD", virDomainDiskGetSource(cd));
}
- if (disk == NULL &&
+ if (hdd == NULL &&
def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
- disk = def->disks[i];
- VIR_INFO("Picking %s as HDD", virDomainDiskGetSource(disk));
+ hdd = diskdef;
+ VIR_INFO("Picking %s as HDD", virDomainDiskGetSource(hdd));
}
}
if (devicesmap_out != NULL) {
/* Grub device.map (just for boot) */
- if (disk != NULL)
- virBufferAsprintf(&devicemap, "(hd0) %s\n",
- virDomainDiskGetSource(disk));
+ if (userdef != NULL) {
+ virBhyveFormatGrubDevice(&devicemap, userdef);
+ } else {
+ if (hdd != NULL)
+ virBhyveFormatGrubDevice(&devicemap, hdd);
- if (cd != NULL)
- virBufferAsprintf(&devicemap, "(cd) %s\n",
- virDomainDiskGetSource(cd));
+ if (cd != NULL)
+ virBhyveFormatGrubDevice(&devicemap, cd);
+ }
*devicesmap_out = virBufferContentAndReset(&devicemap);
}
- if (cd != NULL) {
- virCommandAddArg(cmd, "--root");
+ virCommandAddArg(cmd, "--root");
+ 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 {
- virCommandAddArg(cmd, "--root");
virCommandAddArg(cmd, "hd0,msdos1");
}
--- /dev/null
+/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-hd,/tmp/freebsd1.img \
+-s 2:0,ahci-hd,/tmp/freebsd2.img \
+-s 2:0,ahci-hd,/tmp/freebsd3.img \
+bhyve
--- /dev/null
+(hd0) /tmp/freebsd3.img
--- /dev/null
+/usr/local/sbin/grub-bhyve --root hd0,msdos1 --device-map '<device.map>' \
+--memory 214 bhyve
--- /dev/null
+<domain type='bhyve'>
+ <name>bhyve</name>
+ <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+ <memory>219136</memory>
+ <vcpu>1</vcpu>
+ <bootloader>/usr/local/sbin/grub-bhyve</bootloader>
+ <os>
+ <type>hvm</type>
+ </os>
+ <devices>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd1.img'/>
+ <target dev='hda' bus='sata'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </disk>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd2.img'/>
+ <target dev='hda' bus='sata'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </disk>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd3.img'/>
+ <target dev='hda' bus='sata'/>
+ <boot order='1'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </disk>
+ <interface type='bridge'>
+ <model type='virtio'/>
+ <source bridge="virbr0"/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ </devices>
+</domain>
--- /dev/null
+/usr/sbin/bhyve -c 1 -m 214 -H -P -s 0:0,hostbridge \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:00:00:00 \
+-s 2:0,ahci-hd,/tmp/freebsd1.img \
+-s 2:0,ahci-hd,/tmp/freebsd2.img \
+-s 2:0,ahci-hd,/tmp/freebsd3.img \
+bhyve
--- /dev/null
+(hd0) /tmp/freebsd3.img
--- /dev/null
+/usr/local/sbin/grub-bhyve --root hd0,msdos1 --device-map '<device.map>' \
+--memory 214 bhyve
--- /dev/null
+<domain type='bhyve'>
+ <name>bhyve</name>
+ <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+ <memory>219136</memory>
+ <vcpu>1</vcpu>
+ <bootloader>/usr/local/sbin/grub-bhyve</bootloader>
+ <os>
+ <type>hvm</type>
+ </os>
+ <devices>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd1.img'/>
+ <target dev='hda' bus='sata'/>
+ <boot order='111'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </disk>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd2.img'/>
+ <target dev='hda' bus='sata'/>
+ <boot order='22'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </disk>
+ <disk type='file'>
+ <driver name='file' type='raw'/>
+ <source file='/tmp/freebsd3.img'/>
+ <target dev='hda' bus='sata'/>
+ <boot order='3'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </disk>
+ <interface type='bridge'>
+ <model type='virtio'/>
+ <source bridge="virbr0"/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </interface>
+ </devices>
+</domain>
DO_TEST("serial");
DO_TEST("console");
DO_TEST("grub-defaults");
+ DO_TEST("grub-bootorder");
+ DO_TEST("grub-bootorder2");
DO_TEST("bhyveload-explicitargs");
DO_TEST("custom-loader");
DO_TEST("disk-cdrom-grub");