Author Topic: Acessing the Master Boot Record!  (Read 32210 times)

laskar01

  • Guest
Acessing the Master Boot Record!
« 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?

Kindest regards,

Lasse

Gunther

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Acessing the Master Boot Record!
« Reply #1 on: July 11, 2012, 07:02:04 AM »
Hi laskar01,

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

Gunther
Get your facts first, and then you can distort them.

laskar01

  • Guest
Re: Acessing the Master Boot Record!
« Reply #2 on: July 11, 2012, 07:30:13 AM »
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

  • Member
  • *****
  • Posts: 3515
  • Forgive your enemies, but never forget their names
Re: Acessing the Master Boot Record!
« Reply #3 on: July 11, 2012, 09:23:21 AM »
Hi Lasse,

Quote
Is 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
Get your facts first, and then you can distort them.

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Acessing the Master Boot Record!
« Reply #4 on: July 11, 2012, 09:44:59 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 4807
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Acessing the Master Boot Record!
« Reply #5 on: July 11, 2012, 10:34:29 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

dedndave

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Acessing the Master Boot Record!
« Reply #6 on: July 11, 2012, 12:00:57 PM »
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
« Last Edit: July 13, 2012, 02:33:43 AM by dedndave »

P1

  • Global Moderator
  • Member
  • *****
  • Posts: 63
Re: Acessing the Master Boot Record!
« Reply #7 on: July 11, 2012, 01:40:54 PM »
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

  • Member
  • *****
  • Posts: 1704
Re: Acessing the Master Boot Record!
« Reply #8 on: July 11, 2012, 05:33:33 PM »
Hi laskar01,

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

digelo

  • Regular Member
  • *
  • Posts: 24
  • I HATE C!!!
Re: Acessing the Master Boot Record!
« Reply #9 on: July 11, 2012, 06:19:24 PM »
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

  • Member
  • *****
  • Posts: 8734
  • Still using Abacus 2.0
    • DednDave
Re: Acessing the Master Boot Record!
« Reply #10 on: July 11, 2012, 07:24:53 PM »
MbrWizard is good for making and restoring backups of the MBR

sinsi

  • Member
  • ****
  • Posts: 996
Re: Acessing the Master Boot Record!
« Reply #11 on: July 11, 2012, 08:11:13 PM »
You can access any drive and read any sector in normal use.

Here is a simple mbr backup, no error checking, run as administrator
Code: [Select]
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...
I can walk on water but stagger on beer.

Vortex

  • Member
  • *****
  • Posts: 1704
Re: Acessing the Master Boot Record!
« Reply #12 on: July 11, 2012, 08:35:42 PM »
Hi laskar01,

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

laskar01

  • Guest
Re: Acessing the Master Boot Record!
« Reply #13 on: July 11, 2012, 10:14:50 PM »
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

  • Member
  • ****
  • Posts: 944
Re: Acessing the Master Boot Record!
« Reply #14 on: July 12, 2012, 12:28:51 AM »
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.