News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Acessing the Master Boot Record!

Started by laskar01, July 11, 2012, 06:38:23 AM

Previous topic - Next topic

laskar01

Hi again! Excuse a beginner!

Can anybody give me a pointer on how to find, understand and acess the Master Boot Record.

I want to have the choice either boot XP, or jump to a place where I can have my own minimalistic OS, based only on BIOS-functions.

How should I proceed to accomplish this?

Kindest regards,

Lasse

Gunther

Hi laskar01,

you should use a boot manager like grub to start different operating systems. That would be my advice.

Gunther
You have to know the facts before you can distort them.

laskar01

Thank you Gunther, but I want to learn to do this by hand. I want to acess the MBR by myself. Is it a too big bite for a beginner? :icon_confused:

Gunther

Hi Lasse,

QuoteIs it a too big bite for a beginner? :icon_confused:

That might be. Playing with the MBR can lead not only to a complete data loss, but also to serious hardware damage. You should know, what is the purpose of every entry. For a good overview, you should have a look into the grub sources. Such things are really complicated.

Gunther
You have to know the facts before you can distort them.

MichaelW

I doubt that recent versions of Windows would allow an app to do anything with the MBR other than read it.
Well Microsoft, here's another nice mess you've gotten us into.

hutch--

Lasse,

It sound like from the questions you have been asking that your real interest is in OS development or at least a bootable disk where you write the startup code yourself to get he computer going. Trying to do this on any late model Windows box is more or less impossible but writing boot disk code is something that various members have done here and know something about.

Now what you can learn doing this type of stuff is booting in real mode, switching to protected mode and accessing any hardware you like, its just that you will not succeed trying to do this type of stuff in a protected mode operating system that specifically excludes hardware access by design.

Now if you can find yourself an old box to play with you can experiment with this style of low level stuff without having to try and digest the sheer complexity of a 32 bit or 64 bit protected mode OS.

dedndave

#6
it would appear that it can be done - programs like MbrWizard do it
i imagine there is a myriad of IOCTL and access/permissions stuff to wade through

P1

Quote from: laskar01 on July 11, 2012, 06:38:23 AM
Hi again! Excuse a beginner!

Can anybody give me a pointer on how to find, understand and acess the Master Boot Record.

I want to have the choice either boot XP, or jump to a place where I can have my own minimalistic OS, based only on BIOS-functions.

How should I proceed to accomplish this?
Add another older hard drive, use F12 to boot to it.

The ONLY reason to have a MBR access is to co-exist with M$.  AND the possibility of ruining your existing M$ drive, due to your learning process.  Not to mention, the lost of your development files.

If you MUST do this, use canned MBR software, the risk to your existing partition is not worth it.

Go from scratch, you learn more.  Or go with a boot loader off of floppy to start yourself off, instead of F12.  Start out like DOS did.

F12 technique will let you boot from USB drive and you will have more space to develop on.

Building on top of M$, is not a "minimalistic OS".

Please excuse me, but I just got over an encrypting File System virus using the MBR.

Regards,  P1   8)


Vortex

Hi laskar01,

You can check the grub4dos project. With this boot manager, you can boot Windows, Linux or another OS.

digelo

You can make a back up of your Boot Sector, with Diskedit.exe an Old Dos Norton Utility (NU) , If something goes wrong u can Boot ur system with a DOS bootable disk and restore ur Boot Sector .

dedndave

MbrWizard is good for making and restoring backups of the MBR

sinsi

You can access any drive and read any sector in normal use.

Here is a simple mbr backup, no error checking, run as administrator

include \masm32\include\masm32rt.inc

.data
volume  db '\\.\PhysicalDrive0',0
fname   db 'mbr.bin',0

.data?
buffer  db 512 dup (?)

.code

start:  invoke CreateFile,offset volume,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
        mov esi,eax
        invoke CreateFile,offset fname,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
        mov edi,eax

        push eax
        mov eax,esp
        invoke ReadFile,esi,offset buffer,512,eax,0
        mov eax,esp
        invoke WriteFile,edi,offset buffer,512,eax,0
        pop edx
 
finish: invoke ExitProcess,0

end start


In combination with some ioctl calls you can read an entire disk sector by sector.
For a quick and dirty cloner, this will do the job.

Haven't tested this by writing sectors, for obvious reasons...

Vortex

Hi laskar01,

Here is a simple application to backup the MBR. Source code is included.

laskar01

Thank you all for your kind help. :t
I have an old Win98 computer at my old father! I'll start with dusting off old knowledge about booting from a 1.44MB disc, then I'll install MASM on it to run the code's you´ve supplied me with and I'll also look up grub4dos :biggrin:

/Lasse

FORTRANS

Hi,

   In the 16-bit DOS Programming subforum there
were some code to boot from floppies.  Search the
old forum.

   For boot managers, look at Grub and AirBoot.

   The newsgroup alt.os.development has some
discussion of boot code.  Look for some threads
by Mike Gonta there.  There is some good discussion
of using the BIOS by him as well.

Regards,

Steve N.