bugGNU GRUB - Bugs: bug #11771, bad work around for partitions on...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #11771: bad work around for partitions on linux

Submitted by:  None
Submitted on:  Fri 28 Jan 2005 05:09:28 PM UTC  
Votes:  50  
 
Category:  Disk & Partition Severity:  Major
Priority:  5 - Normal Item Group:  Software Error
Status:  None Privacy:  Public
Assigned to:  None Originator Name: 
Originator Email:  -email is unavailable- Open/Closed:  Closed
Release:  0.95 Release:  None
Reproducibility:  Every Time Planned Release:  None

Sat 15 Dec 2007 04:55:31 PM UTC, comment #3: 

We've moved to GRUB 2 as a development platform. Please can you check if this bug still applies there, and if it does, reopen it?

Thanks

Robert Millan <robertmh>
Project Administrator
Tue 24 Oct 2006 09:50:05 PM UTC, comment #2: 

I have had the same problem.
I think you can get round it quite easily by, intead of "device (hd0) /dev/loop0", using "device (hd0) /path/disk.img", anod not worrying about using loopback devices at all.

Gavin D. Smith <gavin>
Mon 21 Aug 2006 02:48:10 AM UTC, comment #1: 

I used the following workaround successfully:

strace to identify the device node name grub was trying to open - in my case "/dev/loop0p0".

Assuming the state at the end of the above failed grub run, with $offset still set appropriately and /dev/loop0 associated with the $image:

(cd /dev && ln -s loop1 loop0p0)
losetup -o$offset /dev/loop1 $image

then run the above grub commands again -> success

Sarah Smith <sarahsmith>
Fri 28 Jan 2005 05:09:28 PM UTC, original submission:  

running strace on grub reveals this;

stat64("/dev/loop0", {st_mode=S_IFBLK|0660, st_rdev=makedev(7, 0), ...}) = 0
open("/dev/loop01", O_RDWR|O_LARGEFILE) = -1 ENOENT (No such file or
directory)

from code inspection this call is being made in;
write_to_partition():lib/device.c
which is called from;
devwrite():stage2/disk_io.c

It would appear to me that the check (which apparently is to allow for broken
linux) assumes that its working with real harddisk devices and not a disk
images, and specifically that partitions on the harddisk device will be
associated, and /dev/loop0 appears as a block device so the call to
is_disk_device passes. It also seems wrong to assume that partitions are
simply called [devicefile]n particluarly with the advent of devfs and udev,
which allows the partition device files to be called anything.
A fix is needed here to allow for this.
Or can this alternative code path now be removed? (ie has linux been fixed in
relation to caching?)

Cheers,
Nick

int
devwrite (int sector, int sector_count, char *buf)
{
#if defined(GRUB_UTIL) && defined(_linux_)
  if (current_partition != 0xFFFFFF
      && is_disk_device (device_map, current_drive))
    {
      /* If the grub shell is running under Linux and the user wants to
         embed a Stage 1.5 into a partition instead of a MBR, use system
         calls directly instead of biosdisk, because of the bug in
         Linux. sigh  */
      return write_to_partition (device_map, current_drive, current_partition,
                                 sector, sector_count, buf);
    }
  else
#endif /* GRUB_UTIL && _linux_ */
    {
      int i;
      
      for (i = 0; i < sector_count; i++)
        {
          if (! rawwrite (current_drive, part_start + sector + i, 
                          buf + (i << SECTOR_BITS)))
              return 0;

        }
      return 1;
    }
}

On Wednesday 26 Jan 2005 23:51, Nick Brown wrote:

> Hi,
>
> I'm trying to install grub into a hard disk image, however I'm encountering
> a problem.
> Below are the steps I've taken to create the disk image, partition it,
> create the file system, and copy the grub images into it. At the end are
> the grub commands I use to attempt to install grub into the image.
> There should be enough info to reproduce what I did.
> All of this was done on Mandrake 10.1 (important detail; 2.6.8.1-20mdk
> kernel, grub 0.95)
> The error message I get from grub is shown below the last command I use.
>
> Can anyone offer any help or suggestion?
>
> Thanks,
> Nick
>
>
>
> #
> # Building a raw disk image
> #
>
> # bytes per sector
> bytes=512
> # sectors per track
> sectors=63
> # heads per track
> heads=16
> # bytes per cylinder is bytes*sectors*head
> bpc=$(( bytes*sectors*heads ))
> # number of cylinders
> # For a image of $size MB, cylinders = (($size*1024*1024)/$bpc)
> size=200
> cylinders=$(( ($size*1024*1024) / $bpc ))
>
> # Path to disk image
> image="/home/nicbrown/Software/disk.img"
> # Path to location to mount image
> mount="/home/nicbrown/Software/dev-partition"
>
> # Create raw disk image
> dd if=/dev/zero of=$image bs=$bpc count=$cylinders
>
> # Attach image as raw device and partition it
> losetup /dev/loop0 $image
> fdisk -u -C$cylinders -S$sectors -H$heads /dev/loop0
> # Create a ext2 partition
> # With commands like these;
> # o n p 1 <return> <return> a 1 p w
> # Note the start sector and block count of partition
> # start=63
> # count=204592
> losetup -d /dev/loop0
>
> # Mount a specfic parition
> offset=$(( start*bytes ))
> losetup -o$offset /dev/loop0 $image
>
> # Format the partition
> mke2fs -o hurd -b1024 /dev/loop0 $count
>
> # Mount the partition
> mount -tauto /dev/loop0 $mount
>
> # Unmount the partition
> umount /dev/loop0
> losetup -d /dev/loop0
>
> #
> # Installing GRUB into the raw disk image
> #
>
> # Easy mounting
> mount -tauto -oloop=/dev/loop0,offset=$offset $image $mount
>
> # Copy across needed grub images
> cd $mount
> mkdir -p boot/grub
> cd /boot/grub
> cp stage1 stage2 e2fs_stage1_5 $mount/boot/grub
> cd
> sync
> umount -d $mount
>
> # Install grub
> losetup /dev/loop0 $image
> grub
> # Commands like this;
> # device (hd0) /dev/loop0
> # geometry (hd0) $cylinders $heads $sectors
> # root (hd0,0)
> # setup (hd0)
>
> grub> setup (hd0)
>  Checking if "/boot/grub/stage1" exists... yes
>  Checking if "/boot/grub/stage2" exists... yes
>  Checking if "/boot/grub/e2fs_stage1_5" exists... yes
>  Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  22 sectors are
> embedded. succeeded
>  Running "install /boot/grub/stage1 (hd0) (hd0)1+22 p
> (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"... failed
>
> Error 22: No such partition

Anonymous

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by robertmh (Posted a comment)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 50 encouragements so far.

    Only logged-in users can vote.

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2007-12-15 robertmh Open/ClosedOpen => Closed
    2006-10-24 gavin Carbon-Copy- => Added gavin

    Back to the top


    Powered by Savane 3.6