Skip to contentSkip to conversation

GPT on PC/BIOS computers

PATCH Robert Millan 4 participants 14 messages May 1, 2007 – May 7, 2007

lore
Share & tools
lore
#0 lore raw

Here's a patch to enable GPT support for PC/BIOS systems. Need for GPT is increasingly common due availability of > 2 TiB hard drives.

Please let me know if everything is correct.

Some testing would be welcome, too (but be careful, earlier versions of my patch had a "feature" that fucked up your partition table - hopefuly fixed now, at least Works For Me [tm]).

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

2007-05-01 Robert Millan <[email protected]>

* conf/i386-pc.rmk (grub_setup_SOURCES): Add partmap/gpt.c. (grub_probe_SOURCES): Likewise.
* conf/i386-pc.mk: Regenerate.
* util/i386/pc/biosdisk.c (grub_util_biosdisk_get_grub_dev): Detect GPT and initialize dos_part and bsd_part accordingly.
* util/i386/pc/grub-setup.c: Ditto for install_dos_part and install_bsd_part.
* util/i386/pc/grub-install.in: Add gpt module to core.img.
* util/i386/pc/grub-probe.c: Activate gpt module for use during partition identification, and deactivate it afterwards.
* util/i386/pc/grub-setup.c: Ditto.

Index: conf/i386-pc.rmk
===================================================================
RCS file: /sources/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.75

i386-pc.rmk +8 -6
diff -u -r1.75 i386-pc.rmk
@@ -65,9 +65,10 @@
 grub_setup_SOURCES = util/i386/pc/grub-setup.c util/i386/pc/biosdisk.c	\
 	util/misc.c util/i386/pc/getroot.c kern/device.c kern/disk.c	\
 	kern/err.c kern/misc.c fs/fat.c fs/ext2.c fs/xfs.c fs/affs.c	\
-	fs/sfs.c kern/parser.c kern/partition.c partmap/pc.c		\
-	fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/hfsplus.c kern/file.c	\
-	kern/fs.c kern/env.c fs/fshelp.c util/raid.c util/lvm.c
+	fs/sfs.c kern/parser.c kern/partition.c	partmap/pc.c		\
+	partmap/gpt.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c		\
+	fs/hfsplus.c kern/file.c kern/fs.c kern/env.c fs/fshelp.c	\
+	util/raid.c util/lvm.c
 
 # For grub-mkdevicemap.
 grub_mkdevicemap_SOURCES = util/i386/pc/grub-mkdevicemap.c util/misc.c
@@ -76,9 +77,10 @@
 grub_probe_SOURCES = util/i386/pc/grub-probe.c	\
 	util/i386/pc/biosdisk.c	util/misc.c util/i386/pc/getroot.c	\
 	kern/device.c kern/disk.c kern/err.c kern/misc.c fs/fat.c	\
-	fs/ext2.c kern/parser.c kern/partition.c partmap/pc.c fs/ufs.c 	\
-	fs/minix.c fs/hfs.c fs/jfs.c kern/fs.c kern/env.c fs/fshelp.c 	\
-	fs/xfs.c fs/affs.c fs/sfs.c fs/hfsplus.c disk/lvm.c disk/raid.c
+	fs/ext2.c kern/parser.c kern/partition.c partmap/pc.c		\
+	partmap/gpt.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c kern/fs.c	\
+	kern/env.c fs/fshelp.c fs/xfs.c fs/affs.c fs/sfs.c fs/hfsplus.c	\
+	disk/lvm.c disk/raid.c
 
 # For grub-emu.
 grub_emu_DEPENDENCIES = grub_script.tab.c grub_script.tab.h		\

Index: util/i386/pc/biosdisk.c
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/biosdisk.c,v retrieving revision 1.14

i386/pc/biosdisk.c +14 -1
diff -u -r1.14 biosdisk.c
@@ -1,7 +1,7 @@
 /* biosdisk.c - emulate biosdisk */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 1999,2000,2001,2002,2003,2004,2006  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2006,2007  Free Software Foundation, Inc.
  *
  *  GRUB is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -743,9 +743,12 @@
 			const grub_partition_t partition)
       {
  	struct grub_pc_partition *pcdata = 0;
+	int gpt = 0;
 	
 	if (strcmp (partition->partmap->name, "pc_partition_map") == 0)
 	  pcdata = partition->data;
+	else if (strcmp (partition->partmap->name, "gpt_partition_map") == 0)
+	  gpt = 1;
 	  
 	if (pcdata)
 	  {
@@ -757,6 +760,11 @@
 			      pcdata->dos_part, pcdata->bsd_part + 'a',
 			      partition->start);
 	  }
+	else if (gpt)
+	  {
+	      grub_util_info ("GPT partition %d starts from %lu",
+			      partition->index, partition->start);
+	  }
 	
 	if (hdg.start == partition->start)
 	  {
@@ -765,6 +773,11 @@
 		dos_part = pcdata->dos_part;
 		bsd_part = pcdata->bsd_part;
 	      }
+	    else if (gpt)
+	      {
+		dos_part = grub_cpu_to_le32 (partition->index);
+		bsd_part = grub_cpu_to_le32 (-1);
+	      }
 	    else
 	      {
 		dos_part = 0;

Index: util/i386/pc/grub-install.in
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/grub-install.in,v retrieving revision 1.11

i386/pc/grub-install.in +2 -2
diff -u -r1.11 grub-install.in
@@ -216,8 +216,8 @@
     exit 1
 fi
 
-# Typically, _chain and pc are required.
-modules="$modules $fs_module _chain pc"
+# Typically, _chain, pc and gpt are required.
+modules="$modules $fs_module _chain pc gpt"
 
 $grub_mkimage --output=${grubdir}/core.img $modules || exit 1
 

Index: util/i386/pc/grub-probe.c
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/grub-probe.c,v retrieving revision 1.3

i386/pc/grub-probe.c +2 -0
diff -u -r1.3 grub-probe.c
@@ -244,6 +244,7 @@
   /* Initialize the emulated biosdisk driver.  */
   grub_util_biosdisk_init (dev_map ? : DEFAULT_DEVICE_MAP);
   grub_pc_partition_map_init ();
+  grub_gpt_partition_map_init ();
   grub_raid_init ();
   grub_lvm_init ();
   
@@ -268,6 +269,7 @@
   
   grub_lvm_fini ();
   grub_raid_fini ();
+  grub_gpt_partition_map_fini ();
   grub_pc_partition_map_fini ();
   grub_util_biosdisk_fini ();
   

Index: util/i386/pc/grub-setup.c
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/grub-setup.c,v retrieving revision 1.20

i386/pc/grub-setup.c +41 -20

100 lines not on this page · raw message

#1 lore raw

Hello Robert,

I have applied the patch to the latest CVS rev. but when I compile grub2 I get this error:

grub_setup-util_i386_pc_grub_setup.o: In function `main':
/usr/src/grub2/util/i386/pc/grub-setup.c:666: undefined reference to grub_gpt_partition_map_init' /usr/src/grub2/util/i386/pc/grub-setup.c:768: undefined reference to grub_gpt_partition_map_fini'
collect2: ld returned 1 exit status
make: *** [grub-setup] Error 1

I think that both functions are not declared, it is?

If you want I can test with the new versions you made.

Thanks

2007/5/1, Robert Millan <[email protected]>:

Quoted 24 lines

Here's a patch to enable GPT support for PC/BIOS systems. Need for GPT is increasingly common due availability of > 2 TiB hard drives.

Please let me know if everything is correct.

Some testing would be welcome, too (but be careful, earlier versions of my patch had a "feature" that fucked up your partition table - hopefuly fixed now, at least Works For Me [tm]).

--
Robert Millan

My spam trap is [email protected]. Note: this address is only intended for spam harvesters. Writing to it will get you added to my black list.

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

#2 lore raw
Quoted 5 lines · Javier Rodríguez Sánchez

Hello Robert,

I have applied the patch to the latest CVS rev. but when I compile grub2 I get this error:

Quoted 7 lines

grub_setup-util_i386_pc_grub_setup.o: In function `main':
/usr/src/grub2/util/i386/pc/grub-setup.c:666: undefined reference to grub_gpt_partition_map_init' /usr/src/grub2/util/i386/pc/grub-setup.c:768: undefined reference to grub_gpt_partition_map_fini'
collect2: ld returned 1 exit status
make: *** [grub-setup] Error 1

Did you regenerate conf/i386-pc.mk ?

ruby genmk.rb < conf/i386-pc.rmk > conf/i386-pc.mk

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#3 lore raw

Great!, now It compile, when I return to home, I will try it on my MacBookPro. When I have the results I will post them here.

Thanks

2007/5/3, Robert Millan <[email protected]>:

Quoted 32 lines · Javier Rodríguez Sánchez
Quoted 3 lines

Hello Robert,

I have applied the patch to the latest CVS rev. but when I compile grub2

I

Quoted 9 lines

get this error:

grub_setup-util_i386_pc_grub_setup.o: In function `main':
/usr/src/grub2/util/i386/pc/grub-setup.c:666: undefined reference to grub_gpt_partition_map_init' /usr/src/grub2/util/i386/pc/grub-setup.c:768: undefined reference to grub_gpt_partition_map_fini'
collect2: ld returned 1 exit status
make: *** [grub-setup] Error 1

Did you regenerate conf/i386-pc.mk ?

ruby genmk.rb < conf/i386-pc.rmk > conf/i386-pc.mk

--
Robert Millan

My spam trap is [email protected]. Note: this address is only intended for spam harvesters. Writing to it will get you added to my black list.

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

#8 lore raw
In reply to Robert Millan
Quoted 8 lines · Robert Millan

Here's a patch to enable GPT support for PC/BIOS systems. Need for GPT is increasingly common due availability of > 2 TiB hard drives.

Please let me know if everything is correct.

Some testing would be welcome, too (but be careful, earlier versions of my patch had a "feature" that fucked up your partition table - hopefuly fixed now, at least Works For Me [tm]).

Have you tested it on MBR?

Quoted 11 lines
Signature · 10 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

2007-05-01  Robert Millan  <[email protected]>

	* conf/i386-pc.rmk (grub_setup_SOURCES): Add partmap/gpt.c.
	(grub_probe_SOURCES): Likewise.
	* conf/i386-pc.mk: Regenerate.

No need to mention this.

Quoted 8 lines

* util/i386/pc/biosdisk.c (grub_util_biosdisk_get_grub_dev): Detect GPT and initialize dos_part and bsd_part accordingly.
* util/i386/pc/grub-setup.c: Ditto for install_dos_part and install_bsd_part.
* util/i386/pc/grub-install.in: Add gpt module to core.img.
* util/i386/pc/grub-probe.c: Activate gpt module for use during partition identification, and deactivate it afterwards.
* util/i386/pc/grub-setup.c: Ditto.

You don't mention in which function you do these things, just the files. Can you correct this? I personally would prefer if you do not split up the changelog entries for one file, perhaps it is not even allowed by the GCS.

Quoted 8 lines

Index: util/i386/pc/grub-install.in
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/grub-install.in,v retrieving revision 1.11
diff -u -r1.11 grub-install.in

i386/pc/grub-install.in line 220

Quoted 7 lines
i386/pc/grub-install.in +2 -2
@@ -216,8 +216,8 @@
     exit 1
 fi
 
-# Typically, _chain and pc are required.
-modules="$modules $fs_module _chain pc"
+# Typically, _chain, pc and gpt are required.
+modules="$modules $fs_module _chain pc gpt"

It would be nice if we were able to use grub-probe to determine this... But for now this is fine, I think.

--
Marco

#4 lore raw
In reply to Javier Rodríguez Sánchez

Hello, I have tried the patch and it works well, but I have one question. It's necessary to be a MBR partition scheme? because I need a MBR emulation from the GPT scheme to Grub2 loader works. If I only let the GPT scheme with the EFI protective partition on MBR, grub doesn't find any bootable device.

Bye

2007/5/3, Javier Rodríguez Sánchez <[email protected]>:

Quoted 43 lines

Great!, now It compile, when I return to home, I will try it on my MacBookPro. When I have the results I will post them here.

Thanks

2007/5/3, Robert Millan < [email protected]>:

Quoted 34 lines
Quoted 3 lines · Javier Rodríguez Sánchez

Hello Robert,

I have applied the patch to the latest CVS rev. but when I compile

grub2 I

Quoted 9 lines

get this error:

grub_setup-util_i386_pc_grub_setup.o: In function `main':
/usr/src/grub2/util/i386/pc/grub- setup.c:666: undefined reference to grub_gpt_partition_map_init' /usr/src/grub2/util/i386/pc/grub-setup.c:768: undefined reference to grub_gpt_partition_map_fini'
collect2: ld returned 1 exit status
make: *** [grub-setup] Error 1

Did you regenerate conf/i386-pc.mk ?

ruby genmk.rb < conf/i386-pc.rmk > conf/i386-pc.mk

--
Robert Millan

My spam trap is [email protected]. Note: this address is only intended
for spam harvesters. Writing to it will get you added to my black list.

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

#5 lore raw
Quoted 5 lines · Javier Rodríguez Sánchez

Hello, I have tried the patch and it works well, but I have one question. It's necessary to be a MBR partition scheme? because I need a MBR emulation from the GPT scheme to Grub2 loader works. If I only let the GPT scheme with the EFI protective partition on MBR, grub doesn't find any bootable device.

This patch is intended for systems using PC/BIOS/MBR boot system, whose "standard" partition layout is msdos-style, but have opted to use GPT instead for the partitions.

GPT is the standard in EFI, but this patch shouldn't have any effect on EFI systems (these already have GPT support).

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#9 lore raw
In reply to Marco Gerards
Quoted 5 lines · Marco Gerards
Quoted 3 lines · Robert Millan

Here's a patch to enable GPT support for PC/BIOS systems. Need for GPT is increasingly common due availability of > 2 TiB hard drives.

Quoted 7 lines
Quoted 5 lines

Please let me know if everything is correct.

Some testing would be welcome, too (but be careful, earlier versions of my patch had a "feature" that fucked up your partition table - hopefuly fixed now, at least Works For Me [tm]).

Have you tested it on MBR?

Good idea. I have now, and seems to work fine.

Quoted 3 lines
Quoted 1 line

* conf/i386-pc.mk: Regenerate.

No need to mention this.

Ok, removed.

Quoted 4 lines

You don't mention in which function you do these things, just the files. Can you correct this? I personally would prefer if you do not split up the changelog entries for one file, perhaps it is not even allowed by the GCS.

The later adds a bit of redundancy, but as you prefer. All these are corrected.

Quoted 7 lines

i386/pc/grub-install.in line 220

Quoted 4 lines
i386/pc/grub-install.in +2 -2
-# Typically, _chain and pc are required.
-modules="$modules $fs_module _chain pc"
+# Typically, _chain, pc and gpt are required.
+modules="$modules $fs_module _chain pc gpt"

It would be nice if we were able to use grub-probe to determine this... But for now this is fine, I think.

I've looked into this, but I need some advice. What's the simplest way to obtain the corresponding grub_partition_t structure for a partition by knowing its drive name?

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.
#6 lore raw
In reply to Javier Rodríguez Sánchez
Quoted 5 lines · Javier Rodríguez Sánchez

Hello, I have tried the patch and it works well, but I have one question. It's necessary to be a MBR partition scheme? because I need a MBR emulation from the GPT scheme to Grub2 loader works. If I only let the GPT scheme with the EFI protective partition on MBR, grub doesn't find any bootable device.

What do you mean? You do not need MBR emulation or so. I assume you mean that there are a few partitions in the MBR that match the GPT partitions? Or can you be more precise?

--
Marco

#10 lore raw
In reply to Robert Millan

Robert Millan <[email protected]> writes:

[...]

Quoted 3 lines

I've looked into this, but I need some advice. What's the simplest way to obtain the corresponding grub_partition_t structure for a partition by knowing its drive name?

You can use grub_partition_iterate. Or open the disk and use ->partition. You can read the name of the partitioning scheme. The is also done in grub-setup.c, in the code you altered.

--
Marco

#7 lore raw
In reply to Marco Gerards

Hello, curently to make grub2 works, I need a MBR emulation with the same partition as GPT scheme.
If grub2 doesn't found any partition in MBR table it doesn't. Then, It's necessary to be in MBR the
partitions that match with GPT scheme?

Thx

PD:Sorry for my english

2007/5/5, Marco Gerards <[email protected]>:

Quoted 26 lines
Quoted 1 line · Javier Rodríguez Sánchez

Hello, I have tried the patch and it works well, but I have one

question.

Quoted 2 lines

It's necessary to be a MBR partition scheme? because I need a MBR emulation from the GPT scheme to Grub2 loader works. If I only let the

GPT

Quoted 2 lines

scheme with the EFI protective partition on MBR, grub doesn't find any bootable device.

What do you mean? You do not need MBR emulation or so. I assume you mean that there are a few partitions in the MBR that match the GPT partitions? Or can you be more precise?

--
Marco

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

#11 lore raw
In reply to Marco Gerards
Quoted 7 lines · Marco Gerards
Quoted 3 lines

I've looked into this, but I need some advice. What's the simplest way to obtain the corresponding grub_partition_t structure for a partition by knowing its drive name?

You can use grub_partition_iterate. Or open the disk and use ->partition. You can read the name of the partitioning scheme. The is also done in grub-setup.c, in the code you altered.

Patch attached. Let me know if it's correct (I had my doubts about hardcoding the the whole partition_map list in grub-probe.c, but then again I think safety is more important).

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

2007-05-07 Robert Millan <[email protected]>

* util/i386/pc/grub-probe.c: Add `grub-probe -t ptable' parameter to determine partition table module.
* util/i386/pc/grub-install.in: Use this feature to decide which partition module to load, instead of hardcoding pc and gpt.

util/i386/pc/grub-install.in +10 -2
diff -ur grub2-1.95+20070505.1.old/util/i386/pc/grub-install.in grub2-1.95+20070505.1/util/i386/pc/grub-install.in
@@ -216,8 +216,16 @@
     exit 1
 fi
 
-# Typically, _chain, pc and gpt are required.
-modules="$modules $fs_module _chain pc gpt"
+# Then the partition table module.
+ptable_module=`$grub_probe --target=ptable --device-map=${device_map} ${grubdir}`
+if test "x$ptable_module" = x -a "x$modules" = x; then
+    echo "Auto-detection of a partition table module failed." 1>&2
+    echo "Please specify the module with the option \`--modules' explicitly." 1>&2
+    exit 1
+fi
+
+# _chain is often useful
+modules="$modules $fs_module $ptable_module _chain"
 
 $grub_mkimage --output=${grubdir}/core.img $modules || exit 1
 
util/i386/pc/grub-probe.c +22 -1
diff -ur grub2-1.95+20070505.1.old/util/i386/pc/grub-probe.c grub2-1.95+20070505.1/util/i386/pc/grub-probe.c
@@ -50,6 +50,7 @@
 #define PRINT_FS	0
 #define PRINT_DRIVE	1
 #define PRINT_DEVICE	2
+#define PRINT_PTABLE	3
 
 int print = PRINT_FS;
 
@@ -123,6 +124,23 @@
   if (! dev)
     grub_util_error ("%s", grub_errmsg);
 
+  if (print == PRINT_PTABLE)
+    {
+      if (strcmp (dev->disk->partition->partmap->name, "amiga_partition_map") == 0)
+        printf ("amiga\n");
+      else if (strcmp (dev->disk->partition->partmap->name, "apple_partition_map") == 0)
+        printf ("apple\n");
+      else if (strcmp (dev->disk->partition->partmap->name, "gpt_partition_map") == 0)
+        printf ("gpt\n");
+      else if (strcmp (dev->disk->partition->partmap->name, "pc_partition_map") == 0)
+        printf ("pc\n");
+      else if (strcmp (dev->disk->partition->partmap->name, "sun_partition_map") == 0)
+        printf ("sun\n");
+      else
+        grub_util_error ("Unknown partition table %s", dev->disk->partition->partmap->name);
+      goto end;
+    }
+
   fs = grub_fs_probe (dev);
   if (! fs)
     grub_util_error ("%s", grub_errmsg);
@@ -160,7 +178,8 @@
 Probe device information for a given path.\n\
 \n\
   -m, --device-map=FILE     use FILE as the device map [default=%s]\n\
-  -t, --target=(fs|drive|device)  print filesystem module, GRUB drive or system device [default=fs]\n\
+  -t, --target=(fs|drive|device|ptable)\n\
+                            print filesystem module, GRUB drive, system device or partition table module [default=fs]\n\
   -h, --help                display this message and exit\n\
   -V, --version             print version information and exit\n\
   -v, --verbose             print verbose messages\n\
@@ -204,6 +223,8 @@
 	      print = PRINT_DRIVE;
 	    else if (!strcmp (optarg, "device"))
 	      print = PRINT_DEVICE;
+	    else if (!strcmp (optarg, "ptable"))
+	      print = PRINT_PTABLE;
 	    else
 	      usage (1);
 	    break;
#12 lore raw
Quoted 5 lines · Robert Millan
Quoted 4 lines · Marco Gerards
Quoted 3 lines

I've looked into this, but I need some advice. What's the simplest way to obtain the corresponding grub_partition_t structure for a partition by knowing its drive name?

Quoted 7 lines
Quoted 3 lines

You can use grub_partition_iterate. Or open the disk and use ->partition. You can read the name of the partitioning scheme. The is also done in grub-setup.c, in the code you altered.

Patch attached. Let me know if it's correct (I had my doubts about hardcoding the the whole partition_map list in grub-probe.c, but then again I think safety is more important).

The naming is not good. In GRUB, we call "partmap" but not "ptable".

Okuji

#13 lore raw
Quoted 10 lines · Yoshinori K. Okuji
Quoted 9 lines · Robert Millan
Quoted 7 lines · Marco Gerards
Quoted 3 lines

I've looked into this, but I need some advice. What's the simplest way to obtain the corresponding grub_partition_t structure for a partition by knowing its drive name?

You can use grub_partition_iterate. Or open the disk and use ->partition. You can read the name of the partitioning scheme. The is also done in grub-setup.c, in the code you altered.

Quoted 5 lines
Quoted 3 lines

Patch attached. Let me know if it's correct (I had my doubts about hardcoding the the whole partition_map list in grub-probe.c, but then again I think safety is more important).

The naming is not good. In GRUB, we call "partmap" but not "ptable".

Ok, fixed and committed.

Thanks,

Signature · 4 lines
Robert Millan

My spam trap is [email protected].  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.