How to make NTLDR load boot files larger than 512bytes?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
zrhbob
Posts: 5
Joined: Tue Apr 03, 2012 8:18 am

How to make NTLDR load boot files larger than 512bytes?

Post by zrhbob »

Normally, NTLDR could chainload boot files (i.e a 512 bytes boot sector file). And when the file is larger than 512bytes, NTLDR only loads the first 512bytes to memory.

But if the boot file meets some special requirements, NTLDR will load the entire file, even if it is very large. And GRUB4DOS is a good example: GRLDR.MBR is 9KB, and it could be loaded by NTLDR directly.

It is said that two of the requirements are:
1. The boot file must be larger than 8kb (16 sectors)
2. The second sector of the boot file must be a series of NOPs, follow by a JMP, to the very start of the boot file.

But still, NTLDR only loads the first 512bytes of my boot file, so there might be some other requirements to the boot file.
Any suggestions?
halofreak1990
Member
Member
Posts: 41
Joined: Thu Aug 09, 2012 5:10 am

Re: How to make NTLDR load boot files larger than 512bytes?

Post by halofreak1990 »

This may be a silly question, but why are you trying to have NTLDR load your boot file?
Is there something NTLDR can do that GRUB can't?

Otherwise, I'd say save yourself the pain and just use GRUB.
<PixelToast> but i cant mouse

Porting is good if you want to port, not if you want maximum quality. -- sortie
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: How to make NTLDR load boot files larger than 512bytes?

Post by Griwes »

And I would just save myself a pain and just write a proper bootloader from scratch, so you can just both chainload it and boot using BIOS only.

As a matter of fact, I did this before and I really like having full control over PC during boot.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
zrhbob
Posts: 5
Joined: Tue Apr 03, 2012 8:18 am

Re: How to make NTLDR load boot files larger than 512bytes?

Post by zrhbob »

halofreak1990 wrote:This may be a silly question, but why are you trying to have NTLDR load your boot file?
Is there something NTLDR can do that GRUB can't?
Actually, some of my friends decided to try my OS, and currently I use GRUB or just BIOS to load my OS. But my friends do not know what GRUB is, and refuse to install it.
So having my OS able to be loaded by NTLDR, as well as GRUB, would make it easier for users who do not use GRUB to try my OS.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to make NTLDR load boot files larger than 512bytes?

Post by egos »

zrhbob, be quiet. NTLDR loads 512 bytes in any way. grldr.mbr's starting code loads the rest of itself (using dirty trick).
zrhbob wrote:Actually, some of my friends decided to try my OS, and currently I use GRUB or just BIOS to load my OS. But my friends do not know what GRUB is, and refuse to install it.
So having my OS able to be loaded by NTLDR, as well as GRUB, would make it easier for users who do not use GRUB to try my OS.
Do you have Live CD/flash drive with your OS?
If you have seen bad English in my words, tell me what's wrong, please.
zrhbob
Posts: 5
Joined: Tue Apr 03, 2012 8:18 am

Re: How to make NTLDR load boot files larger than 512bytes?

Post by zrhbob »

I'm sorry, but please forgive my poor English, I am not going to be mad :D

According to the author of GRUB4DOS, NTLDR will load the entire file as long as the file meets the requirement

See
http://bbs.znpc.net/forum.php?mod=viewthread&tid=6176

In this page, the authors of GRUB4DOS are discussing how to make grldrstart.s smaller and stronger. The author said that NTLDR loads the first 16 sectors of GRLDR, then the first 16sectors load the rest of GRLDR. And NTLDR loads the entire 18 sectors of GRLDR.MBR to memory.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to make NTLDR load boot files larger than 512bytes?

Post by egos »

Translate, please :x If you are so mistrustful, ask your question to the authors of GRUB4DOS.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
trinopoty
Member
Member
Posts: 87
Joined: Wed Feb 09, 2011 2:21 am
Location: Raipur, India

Re: How to make NTLDR load boot files larger than 512bytes?

Post by trinopoty »

What I would suggest is:
Make NTLDR load your boot-sector and make your boot-sector load everything else. It will work like BIOS loaded you.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: How to make NTLDR load boot files larger than 512bytes?

Post by bluemoon »

Distribute a premature OS to friends and let them run on real machine may not be a good idea (You/your friend may damage something in the progress).
I would recommend let your friend try it on an emulator first, it's much more acceptable even for strangers, and zero-risk.

If you are asking your friend for testing environment, make sure they acknowledge the risk involved and do it the way you planed/supported (e.g. boot on grub).

Ok, back to the topic, NTLDR is not designed to load non-windows OS, so if you are looking for a way to have NTLDR load your boot loader it is not a reliable solution.
The usual way is have a boot manager sit before the chain, and have the boot manager chain-load "your OS" or NTLDR; note that however such boot manager not necessary resident on local harddisk, it can be on a bootable removable media (CD, USB) - I suggest you look into grub on CD/USB, or even simpler, boot your OS on USB (with BIOS HDD emulations).
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: How to make NTLDR load boot files larger than 512bytes?

Post by egos »

I have checked what NTLDR does. Additionally to first sector loaded into memory at 7C00h it loads first 16 sectors into memory at 0D000h and jumps to 0D00h:256h.
If you have seen bad English in my words, tell me what's wrong, please.
zrhbob
Posts: 5
Joined: Tue Apr 03, 2012 8:18 am

Re: How to make NTLDR load boot files larger than 512bytes?

Post by zrhbob »

Thank you, egos! I'll have a try.
Post Reply