summaryrefslogtreecommitdiff
path: root/usr/src/cmd
diff options
context:
space:
mode:
authorHans Rosenfeld <hans.rosenfeld@nexenta.com>2015-02-23 18:49:34 +0100
committerDan McDonald <danmcd@omniti.com>2015-02-26 12:09:40 -0500
commit9348d232b12debc31fa8e694c517ad8ecfd54bda (patch)
treebb69f8dff59c37873cb4696f06ea147c47420b56 /usr/src/cmd
parentda5086c104e170d3832a3e1782dc8617061c7fc6 (diff)
downloadillumos-gate-9348d232b12debc31fa8e694c517ad8ecfd54bda.tar.gz
5664 make installgrub more robust, bump grub capability version
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com> Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com> Reviewed by: Toomas Soome <tsoome@me.com> Approved by: Dan McDonald <danmcd@omniti.com>
Diffstat (limited to 'usr/src/cmd')
-rw-r--r--usr/src/cmd/boot/installgrub/installgrub.c25
-rw-r--r--usr/src/cmd/boot/installgrub/installgrub.h6
2 files changed, 24 insertions, 7 deletions
diff --git a/usr/src/cmd/boot/installgrub/installgrub.c b/usr/src/cmd/boot/installgrub/installgrub.c
index 4d29d0236e..694193d9c7 100644
--- a/usr/src/cmd/boot/installgrub/installgrub.c
+++ b/usr/src/cmd/boot/installgrub/installgrub.c
@@ -672,16 +672,18 @@ init_device(ig_device_t *device, char *path)
if (get_raw_partition_fd(device) != BC_SUCCESS)
return (BC_ERROR);
- if (fstyp_init(device->part_fd, 0, NULL, &fhdl) != 0)
- return (BC_ERROR);
+ if (is_efi(device->type)) {
+ if (fstyp_init(device->part_fd, 0, NULL, &fhdl) != 0)
+ return (BC_ERROR);
- if (fstyp_ident(fhdl, "zfs", &fident) != 0) {
+ if (fstyp_ident(fhdl, "zfs", &fident) != 0) {
+ fstyp_fini(fhdl);
+ (void) fprintf(stderr, gettext("Booting of EFI labeled "
+ "disks is only supported with ZFS\n"));
+ return (BC_ERROR);
+ }
fstyp_fini(fhdl);
- (void) fprintf(stderr, gettext("Booting of EFI labeled disks "
- "is only supported with ZFS\n"));
- return (BC_ERROR);
}
- fstyp_fini(fhdl);
if (get_start_sector(device) != BC_SUCCESS)
return (BC_ERROR);
@@ -998,7 +1000,16 @@ write_stage2(ig_data_t *install)
* For disk, write stage2 starting at STAGE2_BLKOFF sector.
* Note that we use stage2->buf rather than stage2->file, because we
* may have extended information after the latter.
+ *
+ * If we're writing to an EFI-labeled disk where stage2 lives in the
+ * 3.5MB boot loader gap following the ZFS vdev labels, make sure the
+ * size of the buffer doesn't exceed the size of the gap.
*/
+ if (is_efi(device->type) && stage2->buf_size > STAGE2_MAXSIZE) {
+ (void) fprintf(stderr, WRITE_FAIL_STAGE2);
+ return (BC_ERROR);
+ }
+
offset = STAGE2_BLKOFF(device->type) * SECTOR_SIZE;
if (write_out(device->part_fd, stage2->buf, stage2->buf_size,
diff --git a/usr/src/cmd/boot/installgrub/installgrub.h b/usr/src/cmd/boot/installgrub/installgrub.h
index 037ffad4ce..cf3f4f5a92 100644
--- a/usr/src/cmd/boot/installgrub/installgrub.h
+++ b/usr/src/cmd/boot/installgrub/installgrub.h
@@ -91,6 +91,12 @@ enum ig_devtype_t {
#define STAGE2_BLKOFF(type) \
(is_efi(type) ? 1024 : 50) /* offset from start of part */
+/*
+ * Maximum size of stage2 on EFI-labeled disks. Must not be larger than
+ * VDEV_BOOT_SIZE, defined in usr/src/uts/common/fs/zfs/sys/vdev_impl.h
+ */
+#define STAGE2_MAXSIZE (1ULL << 19)
+
#ifdef __cplusplus
}
#endif