标题: Why does it work wrong? [打印本页] 作者: 2011bigbarry 时间: 2012-5-3 18:54 标题: Why does it work wrong? According to the specification as following:
******************************************************************************
*** grldr.mbr - How to write it to Master Boot Track of the hard disk ***
******************************************************************************
grldr.mbr contains code that can be used as Master Boot Record. The code is
responsible for searching all partitions for grldr and when found, loading it.
Currently supported partition types are: FAT12/FAT16/FAT32, NTFS, EXT2/EXT3.
Logical partitions in the extended partition are supported, provided that the
extended partition type is Microsoft-compatible. In fact, the Linux extended
partition type(0x85) is not fully tested for the search mechanism.
How to write GRLDR.MBR to the Master Boot Track of a hard disk?
First, read the Windows disk signature and partition information bytes
(72 bytes in total, from offset 0x01b8 to 0x01ff of the MBR sector), and put
them on the same range from offset 0x01b8 to 0x01ff of the beginning sector of
GRLDR.MBR.
Optionally, if the MBR in the hard disk is a single sector MBR created by
Microsoft FDISK, it may be copied onto the second sector of GRLDR.MBR.
The second sector of GRLDR.MBR is called "previous MBR". When GRLDR not found,
"previous MBR" will be started.
No other steps needed, after all necessary changes stated above have been made,
now simply write GRLDR.MBR on to the Master Boot Track. That's all.
I write the grldr.mbr to the disk mbr, but it looks wrong. The error information displays as "Missing helper...".
My code looks like this:
===code===
//buffer[], read from grldr.mbr
//c[],read the first sector from harddisk
for(int x=0x01b8;x<0x0200;x++)
{
buffer[x] = c[x];
}
//Then write buffer to disk.
===code===
Who can answer me why?
[ 本帖最后由 2011bigbarry 于 2012-5-3 18:57 编辑 ]作者: 不点 时间: 2012-5-3 19:39
Your buffer is too small to hold the whole grldr.mbr.
Or you only write the first sector of buffer to MBR.作者: 2011bigbarry 时间: 2012-5-3 19:46
OK.
My buffer size is 12288.
Let me enlarge it and try again.作者: 2011bigbarry 时间: 2012-5-3 19:55
Now, the size is enlarged to 20480, but it also says 'Missing MBR-helper'.作者: 2011bigbarry 时间: 2012-5-3 19:59
The writing statement just like this:
========code========
WriteFile(hDevice, buffer, mbrActualLenth, &dwBytesWritten, NULL);
========code========
Where,
mbrActualLenth is the length of the file grldr.mbr.作者: 2011bigbarry 时间: 2012-5-3 20:03
Relative information:
grldr.mbr version is 0.4.6a
dwBytesWritten returned 8192.
[ 本帖最后由 2011bigbarry 于 2012-5-3 21:11 编辑 ]作者: 不点 时间: 2012-5-3 20:31
For certainty, please try grldr.mbr of 0.4.5c first.作者: 2011bigbarry 时间: 2012-5-3 21:05
When using grldr.mbr version was 0.4.6a, the writing statement told me that 8192 bytes was written successfully.
Otherwise, the writing statement told me that 9216 bytes was written successfully while using the version 0.4.5c.
And they all returned 'Missing MBR-helper'.
Oh, my god. Where the wrong took place?作者: 不点 时间: 2012-5-3 21:11
Did the bootlace.com work?
You might have made a mistake somewhere.
Emm.. Did you use it for your USB/CF card device? If yes, then the failure should be considered "normal". I recommend you use fbinst to build your bootable USB/CF card.
[ 本帖最后由 不点 于 2012-5-3 21:23 编辑 ]作者: 2011bigbarry 时间: 2012-5-3 21:19
I use the bootice to write grub to disk. And I find that content of the second sector (sector 1) is not equal to that of the grldr.mbr.
For example(version 0.4.5c),
The content of the grldr.mbr is '90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90' (begin with 0x0200).
The content of the sector 1 is 'EB 5E 90 00 00 00 00 00 00 00 00 00 00 00 00 00' (also begin with 0x0200)
Why have this difference?作者: 2011bigbarry 时间: 2012-5-3 21:26
I write the all bytes in one time.
I guess if it must write only 512 bytes a time. If so, why did it tell me that 9216 bytes was written?作者: 不点 时间: 2012-5-3 21:30
The second sector, i.e., sector 1, is not important. It can be placed by your previous MBR(512 bytes in total, ending at offset 0x3FF).
It cannot fail on real internal hard disk. So you must be trying to do it on your USB/CF storage device.作者: 2011bigbarry 时间: 2012-5-3 21:36
Tinny Bit, your eyes are so bright. I do use USB-Flash.
But the flash is displayed as a usb harddisk.
Is it different from a real harddisk?
[ 本帖最后由 2011bigbarry 于 2012-5-4 21:09 编辑 ]作者: 2011bigbarry 时间: 2012-5-3 21:43
Because Pauly has not upgraded his bootice for a long time, I want to write a program to write the new version of grub onto disk. But I meet a great problem.
[ 本帖最后由 2011bigbarry 于 2012-5-3 21:45 编辑 ]作者: 不点 时间: 2012-5-3 21:45
It was because of the BIOS bugs. There are tons of BIOS bugs.
So you have to seek other ways:
1. Use fbinst as mentioned above, and run grldr secondly.
2. Use the WEE boot loader(wee63.mbr), and run grub4dos secondly.
3. Use syslinux and run grub4dos secondly.
4. Use NTLDR/BOOTMGR, and boot grldr secondly
5. Use DOS, and run grub.exe.作者: 2011bigbarry 时间: 2012-5-3 21:48
OK. Thanks.作者: 2011bigbarry 时间: 2012-5-4 21:14
Tinny Bit, are you here?
I got some clue that when writing to MBR,the contents of rang 0x200 to 5F0 was missing, but I wrote the same buffer to a file, the file was complete. Meanwhile, there is nothing else between the two writing functions.
Why?作者: 2011bigbarry 时间: 2012-5-5 15:14 标题: Tinny Bit, are you here? The mistake reason was found out.
I wrote the buffer to a file and to a disk, real harddisk and usb flash were also verified.
The error is described graphically as follows:
contents in file contents in disk ========= every letter represent one sector below
A A
B Z
C Y
D C
E D
F E
G F
...
and so on.
Now, it conclded that:
Sector 0 of disk == sector 0 of file
sector i of disk == sector i-1 of file (i>2)
sector 1 and sector 2 of disk was strangerly inserted.作者: 2011bigbarry 时间: 2012-5-5 17:21
Worked out.
Address located wrong!