All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Millan <rmh@aybabtu.com>
To: grub-devel@gnu.org
Cc: Michael Renner <robe@amd.co.at>
Subject: GPT on PC/BIOS computers
Date: Tue, 1 May 2007 21:18:08 +0200	[thread overview]
Message-ID: <20070501191808.GA19766@aragorn> (raw)

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]


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 honeypot@aybabtu.com.  Note: this address is only intended
for spam harvesters.  Writing to it will get you added to my black list.

[-- Attachment #2: gpt.diff --]
[-- Type: text/x-diff, Size: 9132 bytes --]

2007-05-01  Robert Millan  <rmh@aybabtu.com>

	* 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
diff -u -r1.75 i386-pc.rmk
--- conf/i386-pc.rmk	13 Dec 2006 22:30:19 -0000	1.75
+++ conf/i386-pc.rmk	1 May 2007 18:56:07 -0000
@@ -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
diff -u -r1.14 biosdisk.c
--- util/i386/pc/biosdisk.c	12 Dec 2006 00:13:55 -0000	1.14
+++ util/i386/pc/biosdisk.c	1 May 2007 18:56:07 -0000
@@ -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
diff -u -r1.11 grub-install.in
--- util/i386/pc/grub-install.in	10 Apr 2007 21:38:26 -0000	1.11
+++ util/i386/pc/grub-install.in	1 May 2007 18:56:07 -0000
@@ -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
diff -u -r1.3 grub-probe.c
--- util/i386/pc/grub-probe.c	10 Nov 2006 23:31:55 -0000	1.3
+++ util/i386/pc/grub-probe.c	1 May 2007 18:56:07 -0000
@@ -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
diff -u -r1.20 grub-setup.c
--- util/i386/pc/grub-setup.c	14 Oct 2006 18:59:34 -0000	1.20
+++ util/i386/pc/grub-setup.c	1 May 2007 18:56:07 -0000
@@ -1,7 +1,7 @@
 /* grub-setup.c - make GRUB usable */
 /*
  *  GRUB  --  GRand Unified Bootloader
- *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2006 Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004,2005,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
@@ -289,21 +289,32 @@
 	    *install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-2);
 	  else if (root_dev->disk->partition)
 	    {
-	      struct grub_pc_partition *pcdata =
-		root_dev->disk->partition->data;
-	      
 	      if (strcmp (root_dev->disk->partition->partmap->name,
-			  "pc_partition_map") != 0)
+			  "pc_partition_map") == 0)
+		{
+		  struct grub_pc_partition *pcdata =
+		    root_dev->disk->partition->data;
+		  *install_dos_part
+		    = grub_cpu_to_le32 (pcdata->dos_part);
+		  *install_bsd_part
+		    = grub_cpu_to_le32 (pcdata->bsd_part);
+		}
+	      else if (strcmp (root_dev->disk->partition->partmap->name,
+			       "gpt_partition_map") == 0)
+		{
+		  *install_dos_part = grub_cpu_to_le32 (root_dev->disk->partition->index);
+		  *install_bsd_part = grub_cpu_to_le32 (-1);
+		}
+	      else
 		grub_util_error ("No PC style partitions found");
-	      
-	      *install_dos_part
-		= grub_cpu_to_le32 (pcdata->dos_part);
-	      *install_bsd_part
-		= grub_cpu_to_le32 (pcdata->bsd_part);
 	    }
 	  else
 	    *install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-1);
 
+	  grub_util_info ("dos partition is %d, bsd partition is %d, prefix is %s",
+		  grub_le_to_cpu32 (*install_dos_part),
+		  grub_le_to_cpu32 (*install_bsd_part),
+		  prefix);
 	  strcpy (install_prefix, prefix);
 	  
 	  /* Write the core image onto the disk.  */
@@ -452,19 +463,27 @@
       struct grub_pc_partition *pcdata =
 	root_dev->disk->partition->data;
 
-      if (strcmp (root_dev->disk->partition->partmap->name,
-		  "pc_partition_map") != 0)
-	grub_util_error ("No PC style partitions found");
-      
-      *install_dos_part
-	= grub_cpu_to_le32 (pcdata->dos_part);
-      *install_bsd_part
-	= grub_cpu_to_le32 (pcdata->bsd_part);
+	if (strcmp (root_dev->disk->partition->partmap->name,
+		  "pc_partition_map") == 0)
+	  {
+	    *install_dos_part
+	      = grub_cpu_to_le32 (pcdata->dos_part);
+	    *install_bsd_part
+	      = grub_cpu_to_le32 (pcdata->bsd_part);
+	  }
+	else if (strcmp (root_dev->disk->partition->partmap->name,
+		  "gpt_partition_map") == 0)
+	  {
+	    *install_dos_part = grub_cpu_to_le32 (root_dev->disk->partition->index);
+	    *install_bsd_part = grub_cpu_to_le32 (-1);
+	  }
+	else
+	  grub_util_error ("No PC style partitions found");
     }
   else
     *install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-1);
-  
-  grub_util_info ("dos partition is %u, bsd partition is %u, prefix is %s",
+
+  grub_util_info ("dos partition is %d, bsd partition is %d, prefix is %s",
 		  grub_le_to_cpu32 (*install_dos_part),
 		  grub_le_to_cpu32 (*install_bsd_part),
 		  prefix);
@@ -644,6 +663,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 ();
 
   dest_dev = get_device_name (argv[optind]);
   if (! dest_dev)
@@ -745,6 +765,7 @@
   grub_hfs_fini ();
   grub_jfs_fini ();
   
+  grub_gpt_partition_map_fini ();
   grub_pc_partition_map_fini ();
   grub_util_biosdisk_fini ();
   

             reply	other threads:[~2007-05-01 19:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-01 19:18 Robert Millan [this message]
2007-05-03 13:33 ` GPT on PC/BIOS computers Javier Rodríguez Sánchez
2007-05-03 14:17   ` Robert Millan
2007-05-03 14:27     ` Javier Rodríguez Sánchez
2007-05-04 20:32       ` Javier Rodríguez Sánchez
2007-05-04 22:15         ` Robert Millan
2007-05-05 13:13         ` Marco Gerards
2007-05-06  7:02           ` Javier Rodríguez Sánchez
2007-05-04  8:40 ` Marco Gerards
2007-05-04 23:05   ` Robert Millan
2007-05-05 13:21     ` Marco Gerards
2007-05-07  9:17       ` Robert Millan
2007-05-07 19:23         ` Yoshinori K. Okuji
2007-05-07 19:58           ` Robert Millan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070501191808.GA19766@aragorn \
    --to=rmh@aybabtu.com \
    --cc=grub-devel@gnu.org \
    --cc=robe@amd.co.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.