All of lore.kernel.org
 help / color / mirror / Atom feed
From: Molle Bestefich <molle.bestefich@gmail.com>
To: bug-grub@gnu.org, dm-devel@redhat.com
Cc: ataraid-list@redhat.com
Subject: Re: grub 0.96 bug
Date: Mon, 21 Mar 2005 15:55:02 +0100	[thread overview]
Message-ID: <62b0912f050321065558fc956@mail.gmail.com> (raw)
In-Reply-To: <62b0912f05032104052e78fd60@mail.gmail.com>

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

> grub> device (hd0) /dev/mapper/hpt37x_ehgjaggaf
> grub> device (hd0,5) /dev/mapper/hpt37x_ehgjaggaf6
> grub> root (hd0,5)/boot
> Attempt to open drive 0x80 (/dev/mapper/hpt37x_ehgjaggaf6)
> Error 5: Partition table invalid or corrupt
> grub> root (hd0,5)/boot
> Attempt to open drive 0x80 (/dev/mapper/hpt37x_ehgjaggaf6)
> Error 5: Partition table invalid or corrupt

Think it tries to read a partition table out of a logical partition, humn...
No idea where to look for this bug; hints appreciated.

> grub> root (hd0,5)/boot
> Attempt to open drive 0x80 (/dev/mapper/hpt37x_ehgjaggaf)
> Error 18: Selected cylinder exceeds maximum supported by BIOS

Examining further, GRUB thinks the disk has only 4999680 sectors.
It corresponds to about 2.441 MB, while the disk is really about 160.000 MB.

Looking through the source code, the above sector value is some insane
default in GRUB.
The code tries to use 3 different ways of getting the sector count:

1.) ioctl(fd, HDIO_GETGEO) call in lib/device.c
Fails with error -1.
Documentation/hdio.txt from kernel sources has this to say with
regards to that function:
"Not particularly useful with modern disk drives, whose geometry is a
polite fiction anyway. "

2.) fstat (fd, &st)
Fails with error 0.
No idea what this should do :-).

3.) ioctl(fd, BLKGETSIZE) call in lib/device.c
This works for device-mapped devices!
Seems to be a widely used function, there's even a 64-bit version.
Unfortunately, GRUB only attempts this approach after having
*successfully* retrieved cylinder, head and sector values through
HDIO_GETGEO.


I've gone ahead and solved my problems myself; the attached patch
fixes GRUB 0.96 to work correctly (at least for me) with device-mapped
devices.

This is my first hack ever with anything Linux-ie.
So go ahead and flame at will :-).

[-- Attachment #2: grub-0.96-devicemapper.patch --]
[-- Type: application/octet-stream, Size: 1895 bytes --]

diff -aur grub-0.96-orig/lib/device.c grub-0.96/lib/device.c
--- grub-0.96-orig/lib/device.c	2005-03-21 15:07:17.394333000 +0100
+++ grub-0.96/lib/device.c	2005-03-21 15:47:56.695502856 +0100
@@ -147,6 +147,8 @@
 
   /* XXX This is the default size.  */
   geom->sector_size = SECTOR_SIZE;
+  /* Use 0 to test later on if sector value has already been correctly retrieved. */
+  geom->total_sectors = 0;
   
 #if defined(__linux__)
   /* Linux */
@@ -154,17 +156,16 @@
     struct hd_geometry hdg;
     unsigned long nr;
     
+    if (! ioctl (fd, BLKGETSIZE, &nr))
+      geom->total_sectors = nr;
+    
     if (ioctl (fd, HDIO_GETGEO, &hdg))
       goto fail;
 
-    if (ioctl (fd, BLKGETSIZE, &nr))
-      goto fail;
-    
     /* Got the geometry, so save it. */
     geom->cylinders = hdg.cylinders;
     geom->heads = hdg.heads;
     geom->sectors = hdg.sectors;
-    geom->total_sectors = nr;
     
     goto success;
   }
@@ -236,9 +237,17 @@
        given a proper st_blocks size. */
     if (drive & 0x80)
       {
+       /* If a total sector count has been found and it exceeds CHS capacities,
+	* use large drive placeholder values. */
+       if (geom->total_sectors && (geom->total_sectors >= 255*63*1024)) {
+	geom->cylinders = 1024;
+	geom->heads = 255;
+	geom->sectors = 63;
+       } else {
 	geom->cylinders = DEFAULT_HD_CYLINDERS;
 	geom->heads = DEFAULT_HD_HEADS;
 	geom->sectors = DEFAULT_HD_SECTORS;
+       }
       }
     else
       {
@@ -247,11 +256,13 @@
 	geom->sectors = DEFAULT_FD_SECTORS;
       }
 
-    /* Set the total sectors properly, if we can. */
+   /* If total sectors hasn't been set yet, try and get a proper value. */
+   if (! geom->total_sectors) {
     if (! fstat (fd, &st) && st.st_blocks)
       geom->total_sectors = st.st_blocks;
     else
       geom->total_sectors = geom->cylinders * geom->heads * geom->sectors;
+   }
   }
 
  success:

[-- Attachment #3: oh joy it works.txt --]
[-- Type: text/plain, Size: 248 bytes --]

GNU GRUB  version 0.96  (640K lower / 3072K upper memory)
grub> device (hd0) /dev/mapper/hpt37x_ehgjaggaf

grub> root (hd0,5)
Attempt to open drive 0x80 (/dev/mapper/hpt37x_ehgjaggaf)
Filesystem type is reiserfs, partition type 0x83

grub>

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



       reply	other threads:[~2005-03-21 14:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <62b0912f05031606396a3a47db@mail.gmail.com>
     [not found] ` <20050318125120.GQ3301@redhat.com>
     [not found]   ` <62b0912f0503181112ea853a6@mail.gmail.com>
     [not found]     ` <62b0912f050318142923419b20@mail.gmail.com>
     [not found]       ` <62b0912f05031914513909bcfb@mail.gmail.com>
     [not found]         ` <62b0912f050319145547c4a7db@mail.gmail.com>
     [not found]           ` <20050320163001.GB643@percy.comedia.it>
     [not found]             ` <62b0912f05032019262c009465@mail.gmail.com>
     [not found]               ` <62b0912f0503202121607bd38a@mail.gmail.com>
     [not found]                 ` <62b0912f05032104052e78fd60@mail.gmail.com>
2005-03-21 14:55                   ` Molle Bestefich [this message]
2005-03-21 18:16                     ` Re: grub 0.96 bug Wilfried Weissmann
2005-03-22  7:53                       ` [dm-devel] " Molle Bestefich
2005-03-22 19:29                         ` Wilfried Weissmann
2005-03-22 20:11                           ` Molle Bestefich
2005-03-22 22:42                             ` Wilfried Weissmann

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=62b0912f050321065558fc956@mail.gmail.com \
    --to=molle.bestefich@gmail.com \
    --cc=ataraid-list@redhat.com \
    --cc=bug-grub@gnu.org \
    --cc=dm-devel@redhat.com \
    /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.