无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站投放广告、加入VIP会员,请联系 微信:wuyouceo
查看: 3833|回复: 18
打印 上一主题 下一主题

[求助] Why does it work wrong?

[复制链接]
跳转到指定楼层
1#
发表于 2012-5-3 18:54:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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 编辑 ]
2#
发表于 2012-5-3 19:39:48 | 只看该作者
Your buffer is too small to hold the whole grldr.mbr.

Or you only write the first sector of buffer to MBR.
回复

使用道具 举报

3#
 楼主| 发表于 2012-5-3 19:46:27 | 只看该作者
OK.
My buffer size is 12288.
Let me enlarge it and try again.
回复

使用道具 举报

4#
 楼主| 发表于 2012-5-3 19:55:47 | 只看该作者
Now, the size is enlarged to 20480, but it also says 'Missing MBR-helper'.
回复

使用道具 举报

5#
 楼主| 发表于 2012-5-3 19:59:48 | 只看该作者
The writing statement just like this:
========code========
        WriteFile(hDevice, buffer, mbrActualLenth, &dwBytesWritten, NULL);
========code========
Where,
mbrActualLenth is the length of the file grldr.mbr.
回复

使用道具 举报

6#
 楼主| 发表于 2012-5-3 20:03:52 | 只看该作者
Relative information:
grldr.mbr version is 0.4.6a
dwBytesWritten returned 8192.

[ 本帖最后由 2011bigbarry 于 2012-5-3 21:11 编辑 ]
回复

使用道具 举报

7#
发表于 2012-5-3 20:31:07 | 只看该作者
For certainty, please try grldr.mbr of 0.4.5c first.
回复

使用道具 举报

8#
 楼主| 发表于 2012-5-3 21:05:06 | 只看该作者
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?
回复

使用道具 举报

9#
发表于 2012-5-3 21:11:12 | 只看该作者
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 编辑 ]
回复

使用道具 举报

10#
 楼主| 发表于 2012-5-3 21:19:20 | 只看该作者
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?
回复

使用道具 举报

11#
 楼主| 发表于 2012-5-3 21:26:06 | 只看该作者
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?
回复

使用道具 举报

12#
发表于 2012-5-3 21:30:48 | 只看该作者
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.
回复

使用道具 举报

13#
 楼主| 发表于 2012-5-3 21:36:40 | 只看该作者
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 编辑 ]
回复

使用道具 举报

14#
 楼主| 发表于 2012-5-3 21:43:26 | 只看该作者
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 编辑 ]
回复

使用道具 举报

15#
发表于 2012-5-3 21:45:57 | 只看该作者
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.
回复

使用道具 举报

16#
 楼主| 发表于 2012-5-3 21:48:48 | 只看该作者
OK. Thanks.
回复

使用道具 举报

17#
 楼主| 发表于 2012-5-4 21:14:19 | 只看该作者
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?
回复

使用道具 举报

18#
 楼主| 发表于 2012-5-5 15:14:58 | 只看该作者

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.
回复

使用道具 举报

19#
 楼主| 发表于 2012-5-5 17:21:10 | 只看该作者
Worked out.
Address located wrong!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-11-16 21:55

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表