bug-grub
[Top][All Lists]
Advanced

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

Re: problem installing grub in a hard disk image


From: Nick Brown
Subject: Re: problem installing grub in a hard disk image
Date: Thu, 27 Jan 2005 21:10:46 +0000
User-agent: KMail/1.7.1

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




reply via email to

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