Obtain partition table for my MBR

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
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Obtain partition table for my MBR

Post by mangaluve »

As far as I understand, the MBR holds the partition table for the disk. But suppose I want to write my own MBR to start other operating systems. Can I obtain the partition table in some way (is it stored somewhere else on the hard drive or something).
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Re: Obtain partition table for my MBR

Post by mangaluve »

So I have to use the current MBR to obtain a table and then put that partition table in my own MBR?
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Obtain partition table for my MBR

Post by xenos »

When you write a new MBR to your hard disk, you have to restore the original partition table, otherwise you will lose the information about partitioning. To write an own MBR, you have to read the old MBR, put your new code section together with the old partition table and write both to disk.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Re: Obtain partition table for my MBR

Post by mangaluve »

Okey, thanks! So this is something I do when I actually "build" the MBR? In reality, exactly when do I "copy" the old partition table?

Just a quick thought..what if I have a hard drive which is not bootable? Right now I have two hard drives, and only one of them contains operating systems..or they still need a MBR?
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Obtain partition table for my MBR

Post by Solar »

  • Read old MBR;
  • Extract partition table from old MBR;
  • Write partition table into your new MBR;
  • Write new MBR to disk.
Personally, I would do this in one step (i.e., when you "install" the new MBR).

Yes, non-bootable disks also have an MBR, as they also have to have a partition table. The MBR could be empty except for the partition table, though.
Every good solution is obvious once you've found it.
mangaluve
Member
Member
Posts: 110
Joined: Mon Feb 23, 2009 6:53 am

Re: Obtain partition table for my MBR

Post by mangaluve »

Thanks for all the replies!

What I really want to do right now (for fun), is to be able to boot my operating systems (win/linux) from a USB stick. So I want to put a MBR / simple "kernel" on an USB stick. Then I want to read the MBR from my hard drive, extract the partition table, and then be able to start from the different partitions.
Post Reply