Re: Install Grub to a HDD image?



On Sat, 04 Nov 2006 12:52:15 -0800, Tim wrote:

Hey Douglas,
sorry for my late answer. Thank you for your detailed description of
installing grub onto a virtual disk. Unfortunately, I get the following
error during your install method:

grub> root (fd0)Unknown partition table signature
grub> device (fd0) /mnt/test
grub> setup (fd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... no

Error 16: Inconsistent file system structure

I'm using the following commands to create the hdd image:

dd if=/dev/zero of=test.img bs=1000 count=10000
losetup /dev/loop0 test.img
mkfs -t ext3 /dev/loop0
mount -t ext3 /dev/loop0 test.img
grub --no-floppy

I have no idea, why the file system should be inconsistent or why the
partition table signature is unknown. Have you any suggestions how I
can solve this problem? Thank you for any advice.

Best regards,
Tim

You have to completely model the disk's layout. This can be difficult, and
is why my initial description focused on modelling floppy disks (which
have a simpler layout than hard disks.) The response by Robert Nichols
explains this correctly.

VMWare...
Really, the easiest way to model entire virtual hard disks is to use
virtualization. Do you have any interest in using VMWare as your test
platform? VMWare makes these nitty-gritty details disappear. Basically,
VMWare allows building both the development and test platform on the same
physical computer. The final step is to verify your hdd image is usable as
intended by testing with VMWare.

Manually...
There are quite a few hurdles to modelling disks manually (without
VMWare.) Understanding what you're modelling is key. I did some tests to
attempt installing grub to a complete hdd image. I came close, but no
cigar. There may be a way through the minefield, but I couldn't find it-
even though I tried hard. VMWare solves the same problem in two seconds,
because it is not constrained to using the "device" statements within the
grub shell.

Some details of my _unsucessful_ test...

Steps that I followed:
1. Allocated some file space to use as the hdd image (600M).

dd if=/dev/zero of=master.img bs=512 count=$val

2. Setup a loopback pointing at the entire disk.

losetup /dev/loop0 master.img

3. Setup partition tables (start fdisk using -H and -S switches)

example: fdisk /dev/loop0 -H 16 -S 63 -H 1220

I created partition entries for a boot and and swap partition. Use of
fdisk not shown.

4. Create separate files which match the size of the boot and swap
partitions. (450M for root, 150M for swap). This step is necessary
because simple loopbacks use all of the space available in the file; we
need a separate file which matches the partition size only. The file
master.img will contain copies of these duplications when finished. This
command is useful for getting the size of partitions:

fdisk -lu -H 16 -S 63 /dev/loop0

Use this output to allocate duplicate partitions (and compute values for
$c and $d, below).

dd if=/dev/zero of=vp1 bs=512 count=$c
dd if=/dev/zero of=vp2 bs=512 count=$d

5. Setup loopbacks to duplicate partitions.

losetup /dev/loop1 vp1
losetup /dev/loop2 vp2

6. Format copies of virtual partitions

mke2fs /dev/loop1
mkswap /dev/loop2

7. Mount and install root filesystem to /dev/loop1 (not shown). Include
the grub loader. Unmount when finished:

umount /dev/loop1

8. Copy virtual partition images to "master" disk image; master was
assigned to /dev/loop0 in step 2.

dd if=/dev/loop1 of=/dev/loop0 bs=512 seek=63

Similarly for the virtual swap:

dd if=/dev/loop2 of=/dev/loop0 bs=512 seek=$offset

9. Setup the grub loader using the grub loader. I tried using device
statements which specied the loopback, but failed.

grub>device (hd0) /dev/loop0
grub>geometry (hd0) 1220 16 63
grub>

I'll omit various tricks I tried without success, for now. I could not
produce a bootable virtual hd image using this method.

10. Clean up by removing all loopbacks.

losetup -d /dev/loop0
losetup -d /dev/loop1
losetup -d /dev/loop2

Close, but no cigar.

--
Douglas Mayne
.



Relevant Pages

  • Re: [opensuse] RAID questions
    ... I created one small partition for /boot, ... disks for / and a 2nd RAID for swap. ... /boot partition across all 4 drives and add them to GRUB. ... you can boot from any of the four disks. ...
    (SuSE)
  • Re: Help... Cant boot!
    ... Partition type 0x5 is an 'Extended' partition. ... root ... get as far as the grub countdown/menu. ... I had a similar issue with the installer seeing my disks in a different order to what I expected. ...
    (Fedora)
  • Re: Grub boot problem ofter FC4 -> FC5 upgrade
    ... My server has two IDE disks hda and hdc. ... I think that means that grub is ... Filesystem type is ext2fs, partition type 0xfd ...
    (Fedora)
  • Re: Howto fix grub after converting to reiserfs
    ... The initial load of grub is done by the BIOS, which reads the boot sectors for additional information for the boot process. ... If you still have problems, and can come up with a small bit of additional disk space, near the beginning of the disk, create a separate partition for /boot and format it as ext3, move all the files from your existing subdirectory into this new partition, edit the menu.lst file to remove all references to '/boot', edit fstab to do a mount of this partition on /boot, and reboot. ... it will perform a full install presuming the Stage 2 or Stage 1.5^10 is in its final install location. ... 0, Filesystem type is fat, partition type 0x16 ...
    (Debian-User)
  • fixing grub : mbr fix when windows install after linux
    ... "There is not a boot manager screen at all, ... windows but GRUB boot window does not appear. ... "I forgot to install GRUB, I didn't install GRUB in the MBR, I chose ... Fedora but that was not an active primary partition". ...
    (comp.os.linux.misc)