Skip to contentSkip to conversation

Use ZFS embedding area

RFC In review Vladimir 'φ-coder/phcoder' Serbinenko 2 participants 3 messages Nov 6, 2011 – Nov 10, 2011

lore
Share & tools
lore
#0 lore raw

RFC 1/1 Use ZFS embedding area

Attached patch makes it possible to install GRUB into ZFS partition or whole-disk ZFS sanely. May be dangerous so I recommend a VM and/or backup.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

=== modified file 'grub-core/fs/zfs/zfs.c'

fs/zfs/zfs.c +33 -0
@@ -3760,6 +3760,35 @@
   return grub_errno;
 }
 
+#ifdef GRUB_UTIL
+static grub_err_t
+grub_zfs_embed (grub_device_t device __attribute__ ((unused)),
+		unsigned int *nsectors,
+		grub_embed_type_t embed_type,
+		grub_disk_addr_t **sectors)
+{
+  unsigned i;
+
+  if (embed_type != GRUB_EMBED_PCBIOS)
+    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+		       "ZFS curently supports only PC-BIOS embedding");
+
+ if ((VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS) < *nsectors)
+    return grub_error (GRUB_ERR_OUT_OF_RANGE,
+		       "Your core.img is unusually large.  "
+		       "It won't fit in the embedding area.");
+
+  *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS);
+  *sectors = grub_malloc (*nsectors * sizeof (**sectors));
+  if (!*sectors)
+    return grub_errno;
+  for (i = 0; i < *nsectors; i++)
+    (*sectors)[i] = i + (VDEV_BOOT_OFFSET >> GRUB_DISK_SECTOR_BITS);
+
+  return GRUB_ERR_NONE;
+}
+#endif
+
 static struct grub_fs grub_zfs_fs = {
   .name = "zfs",
   .dir = grub_zfs_dir,
@@ -3769,6 +3798,10 @@
   .label = zfs_label,
   .uuid = zfs_uuid,
   .mtime = zfs_mtime,
+#ifdef GRUB_UTIL
+  .embed = grub_zfs_embed,
+  .reserved_first_sector = 1,
+#endif
   .next = 0
 };
 
#1 lore raw

Hi,

Aside from a typo ("curently" -> "currently"), it looks great! I vote for a commit :).

--S

Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko

Attached patch makes it possible to install GRUB into ZFS partition or whole-disk ZFS sanely. May be dangerous so I recommend a VM and/or backup.

Signature · 7 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

<zfsembed.diff>_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw
Quoted 4 lines · Seth Goldberg

Hi,

Aside from a typo ("curently" -> "currently"), it looks great! I vote for a commit :).

Have you tested it?

Quoted 20 lines

--S

Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko

Attached patch makes it possible to install GRUB into ZFS partition or whole-disk ZFS sanely. May be dangerous so I recommend a VM and/or backup.

Signature · 7 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

<zfsembed.diff>_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko