bug-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems installing grub (into a file)


From: Padraig
Subject: Re: problems installing grub (into a file)
Date: Tue, 22 Apr 2003 17:36:24 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20030210

address@hidden wrote:
Hi, I'm installing grub into a
virtual disk which is a file on disk
structured like:

| MBR | stage1.5 | hd0,0 (grub files here) | hd0,1 |

And the grub install is like:

losetup /dev/loop0 vd.img
echo "
device (hd0) /dev/loop0
geometry (hd0) 245 16 32
root (hd0,0)
setup (hd0)
quit" | grub --batch

This mostly works, but I've the following issues.

1. When I set the geometry above I get:

   drive 0x80: C/H/S = 245/16/32 ...
    Partition num: 0,  Filesystem type is ext2fs, partition type 0x83
    Partition num: 1,  Filesystem type unknown, partition type 0x83

   My question is, why is the filesystem on partition 1 not recognized
   (even though it's not needed for my config)

2. The setup command mostly works except for the install
   command at the end which is:

install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf

   And fails with "Error 22: No such partition"

I analysed this a bit more, and it's because grub
assumes that the partition stage2 is on is mounted (rw).
Hence since the cache for a disk and a partition are
not coherent in Linux (bug), it must use the standard
kernel interface to open the parition.
In this case since grub is being installed in /dev/loop0
it tries to open("/dev/loop01") and hence the error
above ("No such partition"). The obvious way around this
is to modify the stage2 using the filesystem interface instead,
like I discovered works below:

   Now if I mount the filesystem where stage2 is installed
   and pass --stage2=/mnt/point/grub/stage2 to the setup
   command above then it suceeeds.

Also I suppose determining whether the partition stage2
is on is mounted rw and only doing this hack if so is too
complicated and usually wouldn't help. However I'm a little
worried that in the above e.g. if I was using /dev/loop1
and /dev/loop11 was present that it would be corrupted.

I also noticed that the partition wasn't closed for
a couple of error paths. A patch is attached to fix both.

cheers,
Pádraig.
diff -Naur -Naru grub-0.93/lib/device.c grub-0.93-pb/lib/device.c
--- grub-0.93/lib/device.c      2002-05-20 09:53:46.000000000 +0000
+++ grub-0.93-pb/lib/device.c   2003-04-22 16:38:17.000000000 +0000
@@ -689,6 +689,11 @@
       if (strcmp (dev + strlen(dev) - 5, "/disc") == 0)
        strcpy (dev + strlen(dev) - 5, "/part");
     }
+  if (isdigit(dev[strlen(dev)-1])) /* in case actual erroneous partition */
+    {
+      errnum = ERR_NO_PART;
+      return 0;
+    }
   sprintf (dev + strlen(dev), "%d", ((partition >> 16) & 0xFF) + 1);
   
   /* Open the partition.  */
@@ -712,7 +717,8 @@
     offset = (loff_t) sector * (loff_t) SECTOR_SIZE;
     if (_llseek (fd, offset >> 32, offset & 0xffffffff, &result, SEEK_SET))
       {
-       errnum = ERR_DEV_VALUES;
+       close (fd);
+       errnum = ERR_DEV_VALUES;
        return 0;
       }
   }
@@ -722,7 +728,8 @@
 
     if (lseek (fd, offset, SEEK_SET) != offset)
       {
-       errnum = ERR_DEV_VALUES;
+       close (fd);
+       errnum = ERR_DEV_VALUES;
        return 0;
       }
   }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]