I decided that to truly understand GRUB, I have to study the source code. The documentation was too imprecise. So I started with stage1.S which is the only file that generates the small stage 1 and asm.S and stage1_5.c which are part of stage 1.5. It seems that the booted drive comes into the code in stage1.S with %dl set to the drive. If in the grub install command, you use the 'd' option, if will put a drive number into 'bootdrive:' which happens to be at address 0x40 of the first sector. Ah ha! But alas, it is 0xff on my dd'ed image of my USB stick, so there is no forcing of a load of the wrong stage 1.5.
Also, using GRUB installer, dd, and ghex2, I'm getting a better handle on the whole process. If I set:
root (hd2)grub will use my USB key, and then if I use the --prefix=/boot/mark in the setup command, grub has everything look in (hd2,0)/boot/mark both during the install (i.e. when grub copies and modifies the stage1 and stage1.5 files to the USB key. Note that it only embeds the stage1.5 file when the device is the whole drive and not a partition. That is:
setup --prefix=/boot/mark (hd2)will cause a stage1.5 to get installed, but
setup --prefix=/boot/mark (hd2,0)will not because stage 1.5 on goes from the master boot record and not a volume boot record.
Anyway changing the GRUB to MARK in stage1.S and stage1_5.c, I can see whose stage1 is getting used and whose stage 1.5 is used. So far, it's looking like my stage 1 is pulling in the HDD stage 1.5.
But if it isn't the MBR that's causing it, but the first partition on the USB where there is no stage 1.5, then I'm not sure what's going on.
Another confusing this is that I saw one website that said that the booting drive is always (hd0). Is %dl 0 instead of 2 when it is passed to stage1? And if so, whose stage 1.5 should it be getting: (hd0)'s or (hd2)'s?
Maybe I should make a test stage1.S that writes to screen which drive number it thinks it is. That means Intel assembly language programming. Yuck! I think I'll also make sure that my MBR stage 1 and partition 0 stage 1 show different notifications.
OK, so I got an MBR stage 1 with a notification of "MBRu" and the first partition volume boot record with a stage 1 notification of "MARK". Time to reboot and see what's up... See you on the other side.
Back. OK, I saw "MBRu", so I have confirmed that it is using the MBR stage1. But it is still loading stage 1.5 from the HDD. Time to check into the 'd' option on grub's 'install command'. The d option lets you force it load stuff from a specific disk. OK, I used it by doing a 'setup' to get the string for 'install' (it does the install for you and shows it to you), and then added a d. Then I dd'ed and ghex2'ed the USB drive to confirm that the bootdrive is 0x82 instead of 0xff. And it was. Yay! Time to reboot and see what happens....
Two steps forward, one step back. It went to MBRu and froze. Now I'll try it by pulling my 1TB USB drive and see how it likes a bootdrive of 0x81. Confirmed with dd and ghex2. Ready to try again....
...and no-go. Doesn't work. Still sits there at MBRu blinking a cursor at me. /sigh It's not loading the wrong stage1.5 anymore, but now I have to figure out what's happening when all I have is a blasted cursor.
I'm hungry, so that'll be for part IV, (hopefully) A New Hope.
No comments:
Post a Comment