-1

Good evening everyone! I have been working on this for sometime, but can't figure it out. I am simply trying to get the working bootcode of a bootloader installed on an attached media, but can't figure this out!!! I have tried grub legacy, lilo, and grub2... The host system has it's drive listed as /dev/sda* and the target attached media is listed as /dev/sdb* and is mounted to /mnt/target.

With grub legacy, I was attempting to work with another media (/dev/sdc*, /mnt/source) that already had it installed and tried dirty hacks like:

dd if=/mnt/source/boot/grub/stage1 of=/dev/sdb bs=446 count=1
dd if=/mnt/source/boot/grub/stage2 of=/dev/sdb bs=512 seek=1

This will actually boot into a grub interface where you can enter things like:

root (hd0,0)
setup (hd0)

I get no error messages, but grub will boot to garbage on the screen and then stop.

With lilo, I actually had the package installed and tried to setup (after creating a lilo.conf):

default=Test1
timeout=10
compact
prompt
lba32
backup=/mnt/target/boot/lilo/MBR.hda.990428
map=/mnt/target/boot/lilo/map
install=/mnt/target/boot/lilo/boot.b
image=/mnt/target/boot/vmlinuz
    label=Test1
    append="quiet ... settime"
    initrd=/mnt/target/boot/ramdisks/working.gz

And then from the prompt execute the following:

$ lilo -C /mnt/target/boot/lilo/lilo.conf -b /dev/sdb
Warning: /dev/sdb is not on the first disk
Fatal: Sorry, don't know how to handle device 0x0701

With grub2, I tried something like:

grub-mkconfig -o /mnt/target/boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.11.0-12-generic
Found initrd image: /boot/initrd.img-3.11.0-12-generic
Found memtest86+ image: /boot/memtest86+.bin
  No volume groups found
done

I couldn't even get the above to generate a grub.cfg correctly or in the right spot so I gave up on this one... The entries listed above are for the host system, not the target system.

I can provide any additional information that you guys need to help resolve this problem.

-UPDATE-

After working with the media a bit longer, I decided to run an 'fdisk -l' and was presented with the following info:

Partition 1 has different physical/logical beginnings (non-Linux?):
phys(0,32,33) logical(0,37,14)
Partition 1 has different physical/logical endings:
phys(62,53,55) logical(336,27,19)

I should also note that when I try to mount the partition I always get a message that states:

EXT4-fs (sdb1): couldn't mount as ext3 due to feature incompatibilities

Not sure if that is just specific to busybox, or if that is related to the fdisk output. Anyhow, I don't know if the fdisk info is indicating that there may be a problem with the disk geometry that could be causing all these bootloaders to not work.

user1646428
  • 179
  • 2
  • 12

1 Answers1

-1

First stage boot sector code for grub legacy is in "stage1", for grub(2) in "boot.img". Fist stage code contains the address of next stage to be loaded on same disk.

On some other disk the address of next stage to be loaded could be (and is maybe) different.

I think using chroot and grub-install would be a better way to go. See Grub2/Installing.

As for disk/partition structure:

dd if=/mnt/source/boot/grub/stage2 of=/dev/sdb bs=512 seek=1

maybe has overwritten partition table in MBR of sdb.

snayob
  • 311
  • 2
  • 11
  • thanks for the reply, but it looks like your dd command matches the one already in use. And it doesn't overwrite the partition table since it skips the first 512 bytes (via the seek=1 switch). Any other thoughts? – user1646428 Sep 21 '15 at 12:42
  • "My" dd command is a copy of yours. You are right, seek count starts from 0 not 1. – snayob Sep 22 '15 at 11:23
  • Good morning snayob and thanks for the reply. Seek does not start at 0, but does in fact start at 1. If I seeked to 0, then the math would be 0*whatever=0 effectively not skipping anything. Any other thoughts? – user1646428 Sep 22 '15 at 13:24
  • Good evening user1646428, seek=0 does indeed place us at start of file. seeking!=skipping. What about your problem, tried chroot+grub-install already? – snayob Sep 22 '15 at 21:14
  • Thanks for the continued help snayob. If I set 'bs=512 seek=1', then that means that writing will start after the first 512 bytes - skipping the first 512 bytes (512*1=512). If I were to use 'bs=512 seek=0', then that means that I start at the beginning of the disk/partition (512*0=0). At this point I know that the dd calls work correctly because I can boot the media into the grub legacy console and run commands like "root (hd0,0)" and "setup (hd0)" and everything runs without error, but then boots to gibberish. Not sure where the problem lies. – user1646428 Sep 23 '15 at 13:03
  • I would have to create a grub legacy package before doing a grub-install with legacy grub. I tried doing a grub-install for grub2 from an existing system, but I couldn't get that to work right. Also tried lilo, etc. All this is specified in the OP. I might try something else like extlinux, but I'm not sure if that will work either due to the drive geometry issues. – user1646428 Sep 23 '15 at 13:04