Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Require partition names for BSD booting
Browse files Browse the repository at this point in the history
This changes the schema such that partition names are required to
boot the BSDs with grub-bhyve. These names are currently ignored on
anything that isn't OpenBSD.

Fix: #35
  • Loading branch information
io7m committed Jul 30, 2020
1 parent a94a645 commit d483f02
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 9 deletions.
Expand Up @@ -251,9 +251,10 @@ private static ArrayList<String> generateGRUBConfigLinesOpenBSD(
bootHD.ifPresent(index -> {
configLines.add(
String.format(
"kopenbsd -h com0 -r sd%da (hd%d)%s",
"kopenbsd -h com0 -r sd%da (hd%d,%s)%s",
index,
index,
openBSD.partition(),
openBSD.kernelPath()
)
);
Expand Down
Expand Up @@ -278,6 +278,16 @@ default Kind kind()

WXMDeviceSlot bootDevice();

/**
* The name of the partition within which to find the kernel. This
* is typically {@code openbsd1} if the defaults are picked in the OpenBSD
* installer.
*
* @return The name of the partition
*/

String partition();

/**
* @return The path to the kernel on the guest filesystem
*/
Expand Down
Expand Up @@ -98,7 +98,7 @@ public final class WXMEqualsTest
"kernelArguments")),
new WXMClassUnderTest(
WXMGRUBKernelOpenBSD.class,
Set.of("bootDevice", "kernelPath")),
Set.of("bootDevice", "kernelPath", "partition")),
new WXMClassUnderTest(
WXMParseError.class,
Set.of("lexical", "severity", "message")),
Expand Down
Expand Up @@ -212,6 +212,7 @@ public void exampleParses()
final var installK = (WXMGRUBKernelOpenBSD) install.kernelInstructions();
assertEquals("install", install.name().value());
assertEquals("0:4:0", installK.bootDevice().toString());
assertEquals("openbsd1", installK.partition());
assertEquals("/6.6/amd64/bsd.rd", installK.kernelPath().toString());

final var installUEFI = (WXMBootConfigurationUEFI) boots.get(1);
Expand Down
Expand Up @@ -144,6 +144,7 @@ public void openbsdSimpleAHCIHD()
WXMGRUBKernelOpenBSD.builder()
.setBootDevice(convert("0:0:0"))
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.build())
.build()
)
Expand Down Expand Up @@ -179,7 +180,7 @@ public void openbsdSimpleAHCIHD()
assertEquals(1, mapLines.size());

final var grub = evaluated.grubConfiguration();
assertEquals("kopenbsd -h com0 -r sd0a (hd0)/bsd", grub.get(0));
assertEquals("kopenbsd -h com0 -r sd0a (hd0,openbsd1)/bsd", grub.get(0));
assertEquals("boot", grub.get(1));
assertEquals(2, grub.size());

Expand Down Expand Up @@ -214,6 +215,7 @@ public void openbsdSimpleHD()
WXMGRUBKernelOpenBSD.builder()
.setBootDevice(convert("0:0:0"))
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.build())
.build()
)
Expand Down Expand Up @@ -244,7 +246,7 @@ public void openbsdSimpleHD()
assertEquals(1, mapLines.size());

final var grub = evaluated.grubConfiguration();
assertEquals("kopenbsd -h com0 -r sd0a (hd0)/bsd", grub.get(0));
assertEquals("kopenbsd -h com0 -r sd0a (hd0,openbsd1)/bsd", grub.get(0));
assertEquals("boot", grub.get(1));
assertEquals(2, grub.size());

Expand Down Expand Up @@ -286,6 +288,7 @@ public void openbsdSimpleCD()
WXMGRUBKernelOpenBSD.builder()
.setBootDevice(convert("0:1:0"))
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.build())
.build()
)
Expand Down Expand Up @@ -363,6 +366,7 @@ public void openbsdSimpleCDUnused()
WXMGRUBKernelOpenBSD.builder()
.setBootDevice(convert("0:1:0"))
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.build())
.build()
)
Expand Down Expand Up @@ -438,6 +442,7 @@ public void openbsdSimpleCDMissingAttachment()
WXMGRUBKernelOpenBSD.builder()
.setBootDevice(convert("0:1:0"))
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.build())
.build()
)
Expand Down
Expand Up @@ -128,6 +128,7 @@ public void deleteOK()
.setKernelInstructions(
WXMGRUBKernelOpenBSD.builder()
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.setBootDevice(
WXMDeviceSlot.builder()
.setBusID(0)
Expand Down
Expand Up @@ -273,6 +273,7 @@ public void deleteBootReferenced()
.setKernelInstructions(
WXMGRUBKernelOpenBSD.builder()
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.setBootDevice(
WXMDeviceSlot.builder()
.setBusID(0)
Expand Down
Expand Up @@ -129,6 +129,7 @@ public void addOK()
.setKernelInstructions(
WXMGRUBKernelOpenBSD.builder()
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.setBootDevice(
WXMDeviceSlot.builder()
.setBusID(0)
Expand Down Expand Up @@ -226,6 +227,7 @@ public void addConflict()
.setKernelInstructions(
WXMGRUBKernelOpenBSD.builder()
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.setBootDevice(
WXMDeviceSlot.builder()
.setBusID(0)
Expand Down Expand Up @@ -325,6 +327,7 @@ public void replaceOK()
.setKernelInstructions(
WXMGRUBKernelOpenBSD.builder()
.setKernelPath(Paths.get("/bsd"))
.setPartition("openbsd1")
.setBootDevice(
WXMDeviceSlot.builder()
.setBusID(0)
Expand Down
Expand Up @@ -137,7 +137,7 @@
</BootDiskAttachment>
</BootDiskAttachments>
<GRUBBhyveKernelOpenBSD>
<BSDBootDevice kernelPath="/6.6/amd64/bsd.rd">
<BSDBootDevice kernelPath="/6.6/amd64/bsd.rd" partition="openbsd1">
<DeviceSlot bus="0"
slot="4"
function="0"/>
Expand Down
Expand Up @@ -137,7 +137,7 @@
</BootDiskAttachment>
</BootDiskAttachments>
<GRUBBhyveKernelOpenBSD>
<BSDBootDevice kernelPath="/6.6/amd64/bsd.rd">
<BSDBootDevice kernelPath="/6.6/amd64/bsd.rd" partition="openbsd1">
<DeviceSlot bus="0"
slot="4"
function="0"/>
Expand Down
Expand Up @@ -81,6 +81,7 @@ public void onElementStart(
this.builder.setKernelPath(
this.fileSystem.getPath(attributes.getValue("kernelPath"))
);
this.builder.setPartition(attributes.getValue("partition"));
} catch (final Exception e) {
throw context.parseException(e);
}
Expand Down
Expand Up @@ -28,5 +28,7 @@ public interface WXM1BSDBootDeviceType
{
WXMDeviceSlot deviceSlot();

String partition();

Path kernelPath();
}
Expand Up @@ -148,19 +148,26 @@ private static void serializeGRUBKernelOpenBSD(
{
final var namespaceURI = WXMSchemas.vmSchemaV1p0NamespaceText();
writer.writeStartElement(namespaceURI, "GRUBBhyveKernelOpenBSD");
serializeBSDBootDevice(kernel.kernelPath(), kernel.bootDevice(), writer);
serializeBSDBootDevice(
kernel.kernelPath(),
kernel.partition(),
kernel.bootDevice(),
writer
);
writer.writeEndElement();
}

private static void serializeBSDBootDevice(
final Path kernelPath,
final String partition,
final WXMDeviceSlot bootDevice,
final XMLStreamWriter writer)
throws XMLStreamException
{
final var namespaceURI = WXMSchemas.vmSchemaV1p0NamespaceText();
writer.writeStartElement(namespaceURI, "BSDBootDevice");
writer.writeAttribute("kernelPath", kernelPath.toString());
writer.writeAttribute("partition", partition);
WXM1DeviceSlots.serializeDeviceSlot(bootDevice, GUEST, writer);
writer.writeEndElement();
}
Expand Down
Expand Up @@ -66,6 +66,7 @@ public void onChildValueProduced(
final var bootDevice = (WXM1BSDBootDevice) result;
this.builder.setBootDevice(bootDevice.deviceSlot());
this.builder.setKernelPath(bootDevice.kernelPath());
this.builder.setPartition(bootDevice.partition());
} else {
throw new UnreachableCodeException();
}
Expand Down
Expand Up @@ -354,9 +354,7 @@ private void serializeDeviceAHCIDisk(
GUEST,
this.writer);
WXM1Comments.serializeComment(device.comment(), this.writer);

WXM1StorageBackends.serializeStorageBackend(device.backend(), this.writer);

this.writer.writeEndElement();
}

Expand Down
Expand Up @@ -1190,6 +1190,17 @@
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>

<xsd:attribute name="partition"
type="xsd:string"
use="required">
<xsd:annotation>
<xsd:documentation>
The partition that will be inspected for the kernel. This may be ignored depending on which BSD
operating system is being booted.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Expand Down

0 comments on commit d483f02

Please sign in to comment.