Partition tables and 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
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Partition tables and MBR

Post by lopidas »

Nearly everywhere I read that partition tables are always part of MBR.
What will happen, if I overwrite these tables by executable code?
madanra
Member
Member
Posts: 149
Joined: Mon Sep 07, 2009 12:01 pm

Re: Partition tables and MBR

Post by madanra »

You will no longer have any partitions on your disk.
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Re: Partition tables and MBR

Post by lopidas »

Which calls will be affected by doing this? I think drive tables of int 0x13. Anything else?
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Partition tables and MBR

Post by Antti »

lopidas wrote:What will happen, if I overwrite these tables by executable code?
I do not recommend using executable code there. If there are no partitions, fill it with zeros.

In fact, I always keep that area filled with zeros even in FAT12 floppy images (that do not contain partitions anyway). If I copy the image to a USB stick, it is definitely interpreted as a floppy. On the contrary, for my "HD images" with partitions I always leave the Bios Parameter Block filled with zeros (except the first short jump, of course).
lopidas
Member
Member
Posts: 65
Joined: Sun May 26, 2013 10:12 am

Re: Partition tables and MBR

Post by lopidas »

Why do you not recommend it?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Partition tables and MBR

Post by Brendan »

Hi,
lopidas wrote:Why do you not recommend it?
If you're unlucky (e.g. the "random" bytes in the partition table happen to look valid) any other OS can think there's valid partitions when there are none (possibly asking the user if the partitions it sees should be formatted, destroying data if the user says "yes").

If you're lucky (e.g. the "random" bytes in the partition table don't look valid) any other OS will assume the hard drive isn't partitioned properly yet and wipe the partition table in an attempt to install partitions/file systems (corrupting your code, but not trashing file system/s and user data).

Note: There is one and only one case where not having a partition table (and putting executable code there) is safe; and that's floppy disks (where no OS expects to see partitions). For all other cases you break the expectations of every other OSs that the user may have installed or may want to install later.

[EDIT: Actually, I forgot about CDs, which are also never partitioned but boot very differently anyway.[/EDIT]


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Partition tables and MBR

Post by Love4Boobies »

lopidas wrote:Which calls will be affected by doing this? I think drive tables of int 0x13. Anything else?
No BIOS functions will be affected; not even INT 13h, which is for controlling drives rather than file systems.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
Post Reply