Skip to contentSkip to conversation

Fix chainloding + Chainloading into logical partitions

PATCH In review Lucas Gadani 4 participants 6 messages Jun 30, 2008 – Jul 10, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix chainloding + Chainloading into logical partitions

Hello,

This is my first patch for GRUB, and I haven't found any coding styles/formatting, nor developer documentation, so, if there's something wrong, please, forgive me and point me to the right direction.

Current implementation of the chainloading code does not work, cause it reads the partition table from the first sector of the root device, and the root device does not contain partition information. I've changed the way partition table are loaded, keeping a copy of the partition entry in grub_partition_t structs data field, and just loading this information in the correct address when chainloading. I've also changed the logical partitions start address to point to the actual disk sector, instead of pointing to the sector relative to the beginning of the extended partition, so we can now boot into logical partitions (for example, syslinux doesn't boot if the partition table doesn't map to the correct disk sector).

Any comments are appreciated.

Signature · 1 line
Lucas
include/grub/pc_partition.h +3 -0
diff -ru grub2.org/include/grub/pc_partition.h grub2/include/grub/pc_partition.h
@@ -182,6 +182,9 @@
 
   /* The offset of the extended partition.  */
   unsigned long ext_offset;
+
+  /* Partition entry. */
+  struct grub_pc_partition_entry e;
 };
 
 static inline int
loader/i386/pc/chainloader.c +6 -4
diff -ru grub2.org/loader/i386/pc/chainloader.c grub2/loader/i386/pc/chainloader.c
@@ -31,6 +31,7 @@
 #include <grub/machine/memory.h>
 #include <grub/rescue.h>
 #include <grub/dl.h>
+#include <grub/pc_partition.h>
 
 static grub_dl_t my_mod;
 static int boot_drive;
@@ -103,10 +104,11 @@
 
 	  if (p)
 	    {
-	      grub_disk_read (disk, p->offset, 446, 64,
-			      (char *) GRUB_MEMORY_MACHINE_PART_TABLE_ADDR);
-	      part_addr = (void *) (GRUB_MEMORY_MACHINE_PART_TABLE_ADDR
-				    + (p->index << 4));
+	      struct grub_pc_partition *pcdata = p->data;
+	      grub_memcpy((void *) GRUB_MEMORY_MACHINE_PART_TABLE_ADDR,
+			  (void *) &pcdata->e,
+			  sizeof(struct grub_pc_partition_entry));
+	      part_addr = (void *) (GRUB_MEMORY_MACHINE_PART_TABLE_ADDR);
 	    }
 	}
 
partmap/pc.c +2 -0
diff -ru grub2.org/partmap/pc.c grub2/partmap/pc.c
@@ -135,6 +135,8 @@
 	  pcdata.bsd_part = -1;
 	  pcdata.dos_type = e->type;
 	  pcdata.bsd_type = -1;
+	  grub_memcpy(&pcdata.e, e, sizeof(struct grub_pc_partition_entry));
+	  pcdata.e.start = grub_cpu_to_le32(p.offset + grub_le_to_cpu32 (e->start));
 
 	  grub_dprintf ("partition",
 			"partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n",
#1 lore raw

2008/6/30 Lucas Gadani <[email protected]>:

Quoted 19 lines

Hello,

This is my first patch for GRUB, and I haven't found any coding styles/formatting, nor developer documentation, so, if there's something wrong, please, forgive me and point me to the right direction.

Current implementation of the chainloading code does not work, cause it reads the partition table from the first sector of the root device, and the root device does not contain partition information. I've changed the way partition table are loaded, keeping a copy of the partition entry in grub_partition_t structs data field, and just loading this information in the correct address when chainloading. I've also changed the logical partitions start address to point to the actual disk sector, instead of pointing to the sector relative to the beginning of the extended partition, so we can now boot into logical partitions (for example, syslinux doesn't boot if the partition table doesn't map to the correct disk sector).

Quoted 5 lines

Any comments are appreciated.

--
Lucas

Thank you so much for this. I've been having problem for weeks trying to boot some syslinux-bootable partitions on a usb stick. I knew of the problem but lacked the necessary knowledge to contribute myself. I've just begun to try the patched grub, but until now performs as expected. Something that might be related: I've created a stick with a GPT label, and I get partitions to boot using syslinux, or rather, they all boot until the fourth. The fifth and the following ones don't, even when I clone the contents of another partition which does boot.
I suspect a similar problem to the one you've addressed.
Thanks again for the effort.

#2 lore raw
In reply to Lucas Gadani
Quoted 19 lines · Lucas Gadani

Hello,

This is my first patch for GRUB, and I haven't found any coding styles/formatting, nor developer documentation, so, if there's something wrong, please, forgive me and point me to the right direction.

Current implementation of the chainloading code does not work, cause it reads the partition table from the first sector of the root device, and the root device does not contain partition information. I've changed the way partition table are loaded, keeping a copy of the partition entry in grub_partition_t structs data field, and just loading this information in the correct address when chainloading. I've also changed the logical partitions start address to point to the actual disk sector, instead of pointing to the sector relative to the beginning of the extended partition, so we can now boot into logical partitions (for example, syslinux doesn't boot if the partition table doesn't map to the correct disk sector).

Quoted 1 line

Any comments are appreciated.

Looks like it increases pc.mod code to store information that is only useful to the chainloader. Is there a reason for not having the chainloader retrieve it? (note that for disk access we have a cache)

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What good is a phone call… if you are unable to speak?
(as seen on /.)
#3 lore raw
Quoted 4 lines · Robert Millan

Looks like it increases pc.mod code to store information that is only useful to the chainloader. Is there a reason for not having the chainloader retrieve it? (note that for disk access we have a cache)

We would need to duplicate the code that iterates through the logical partitions in the chainloader or we can change pc_partition_map_iterate hook function to also receive grub_pc_partition (we can't use the pc_partition_map_iterate cause the hook function only receives a grub_disk_t and grub_partition_t, but not the grub_pc_partition that's necessary to reconstruct the partition info).

Signature · 1 line
Lucas
#4 lore raw
Quoted 6 lines · Lucas Gadani
Quoted 4 lines · Robert Millan

Looks like it increases pc.mod code to store information that is only useful to the chainloader. Is there a reason for not having the chainloader retrieve it? (note that for disk access we have a cache)

Quoted 7 lines

We would need to duplicate the code that iterates through the logical partitions in the chainloader or we can change pc_partition_map_iterate hook function to also receive grub_pc_partition (we can't use the pc_partition_map_iterate cause the hook function only receives a grub_disk_t and grub_partition_t, but not the grub_pc_partition that's necessary to reconstruct the partition info).

What would be the best patch to get accepted into grub? I'm willing to code the patch, but first I'd like to know the best way to get comitted to grub.

Signature · 1 line
Lucas
#5 lore raw
Quoted 15 lines · Lucas Gadani
Quoted 6 lines · Lucas Gadani
Quoted 4 lines · Robert Millan

Looks like it increases pc.mod code to store information that is only useful to the chainloader. Is there a reason for not having the chainloader retrieve it? (note that for disk access we have a cache)

Quoted 7 lines

We would need to duplicate the code that iterates through the logical partitions in the chainloader or we can change pc_partition_map_iterate hook function to also receive grub_pc_partition (we can't use the pc_partition_map_iterate cause the hook function only receives a grub_disk_t and grub_partition_t, but not the grub_pc_partition that's necessary to reconstruct the partition info).

Quoted 3 lines

What would be the best patch to get accepted into grub? I'm willing to code the patch, but first I'd like to know the best way to get comitted to grub.

Hi,

I don't know how many fields of partition table is actually used by syslinux. But from your code, I get the sense that only the start sector is used. If that's the case, there is no need to save the partition entry, we can just set the value in chainloader.

Signature · 1 line
Bean