ports/158362: sysutils/grub [patch] allow GRUB to boot FreeBSD from an extended partition

Gyrd Thane Lange gyrd-se at thanelange.no
Tue Jun 28 02:00:30 UTC 2011


>Number:         158362
>Category:       ports
>Synopsis:       sysutils/grub [patch] allow GRUB to boot FreeBSD from an extended partition
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 28 02:00:26 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Gyrd Thane Lange
>Release:        FreeBSD 9.0-CURRENT amd64
>Organization:
>Environment:
FreeBSD parvati.thanelange.no 9.0-CURRENT FreeBSD 9.0-CURRENT #7 r221413M: Thu May 5 00:22:25 CEST 2011 root at parvati.thanelange.no:/usr/obj/usr/src/sys/PARVATI amd64
>Description:
Partitions created with bsdlabel(8) are not created with absolute sector values (but are instead relative to the container slice.)

This patch looks for common offset values (i.e. 0 and 16), and if found assumes they are relative and computes absolute values.

Also it resolves start sectors for partitions created in "extended partions (aka slices)" by adding the original offset (start sector) found in the containing primary slice.

This PR overlaps with:
http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/152389

>How-To-Repeat:
Create labels (FreeBSD partition) within an "MBR extended partition".
Create a UFS 1/2 file system.

Boot with GRUB, try to find file system.

>Fix:
Drop patch file into /usr/ports/sysutils/grub/files
http://parvati.thanelange.no/freebsd/grub/patch-ufs-in-logical-partition




Patch attached with submission follows:

--- stage2/disk_io.c.orig	Sun Aug 13 04:12:55 2006
+++ stage2/disk_io.c	Sat Aug 19 20:11:12 2006
@@ -561,6 +561,19 @@
 #endif /* STAGE1_5 */
 
 
+/* The following variables are placed here in order to survive 
+   successive calls to the 'next_partition' function.
+   (Ideally they should be added to the parameter list of the 
+   function, but, since this is a hack to the legacy version 
+   of GRUB, refactoring is not a priority...) */
+
+/* Need this to compensate for offsets in extended partitions */
+unsigned long bsd_label_start;    
+
+/* Indicates that the bsdlabel on disk
+   is missing the usual primary partition offset */
+int bsd_label_is_missing_offset;  
+
 /* Get the information on next partition on the drive DRIVE.
    The caller must not modify the contents of the arguments when
    iterating this function. The partition representation in GRUB will
@@ -611,6 +624,9 @@
 	      return 0;
 	    }
 	  
+	  bsd_label_start = *start;
+	  bsd_label_is_missing_offset = 0;
+	  
 	  bsd_part_no = -1;
 	}
 
@@ -626,6 +642,24 @@
 	      *len = BSD_PART_LENGTH (buf, i);
 	      *partition = (*partition & 0xFF00FF) | (i << 8);
 
+	      /* Hopefully, the start is already an absolute sector,
+	         but in some cases it is not, so we have to compensate. */
+
+	      /* Check for common values. If any of these are found
+	         it is a sure sign the offset is missing */ 
+	      if (*start == 0 || *start == 16) {
+	        bsd_label_is_missing_offset = 1;
+	      }
+	      if (bsd_label_is_missing_offset) {
+	        *start += bsd_label_start;
+	      } else {
+	        /* Check if we are inside an extended partition, if so, 
+	           we must add the missing offset to the primary partition */
+	        if (*ext_offset > 0) { 
+	          *start += (bsd_label_start - *ext_offset);
+	        }	
+	      }		
+	      
 #ifndef STAGE1_5
 	      /* XXX */
 	      if ((drive & 0x80) && BSD_LABEL_DTYPE (buf) == DTYPE_SCSI)


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list