Some questions about 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.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Some questions about MBR

Post by Jeko »

I have windows XP installed in the first partition of the first hard-disk. If I write my MBR to the first sector, I'll overwrite also some informations for the NTFS. How can I do?
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

If you want to write some boot code try using emulators.Qemu, Bochs, Virtual PC are good.If you want to try it on a real PC use a floppy disk or USB flash(if you have a new PC).Mesing with you primary HDD is a very dangerous job.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

muisei wrote:If you want to write some boot code try using emulators.Qemu, Bochs, Virtual PC are good.If you want to try it on a real PC use a floppy disk or USB flash(if you have a new PC).Mesing with you primary HDD is a very dangerous job.
I know this. My question is: how to write a MBR to boot windows and my system without using a boot manager like GRUB and without corrupt NTFS's informations.
Maybe I can change bytes of the bootcode in the NTFS structure, but if I change these bytes how can I boot windows?
In few words I want to write a simple boot manager. GRUB and GAG are too much complex.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

MarkOS wrote: GRUB and GAG are too much complex.
:?: More complex than writing your own boot manager?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Some questions about MBR

Post by Combuster »

MarkOS wrote:I have windows XP installed in the first partition of the first hard-disk. If I write my MBR to the first sector, I'll overwrite also some informations for the NTFS. How can I do?
You can replace the MBR with GRUB without breaking windows, if you have a separate partition to put it on. Writing your chainloader for common usage is more trouble than its worth.
I use grub as well to multiboot between windows, linux, and my own os without trouble, and it was installed after windows.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

I've got W2k installed on this box a few years AFTER I installed GRUB on it. I guess Windows must have looked at MBR, thought "seems that's not quite the standard thing out there" and just left it alone. :)
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

If you are sure you want to mess with the boot process, I know two ways:
1.If you are using LINUX/UNIX system and you are root then you can have full access to the HDD.The command for read/write is 'dd'.First of all you MUST copy the MBR's partition table from your HDD which is placed from the 466th byte to the 510th byte.Then copy that partition table to your MBR and then copy your MBR to the first block of the HDD.
2.The second way is a little more complex.You can write a program which boots from a floppy/USB flash/CD.This program should do the following in this order:store the MBR's partition table from your HDD, then copy the partiotion table to your MBR, then copy your modified MBR to the first block of the HDD.

If something goes wrong, don't blame me!

Be exremely cautious with this.You can LOOSE ALL the data!
My suggestion is to spare some time learning how to use grub.This will save you a lot of headaches.By the way GAG is very easy to use.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

sorry double post
Last edited by Jeko on Thu Mar 22, 2007 8:30 am, edited 1 time in total.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

muisei wrote:My suggestion is to spare some time learning how to use grub.This will save you a lot of headaches.By the way GAG is very easy to use.
I don't want to use GRUB or GAG.
I want to write a simple boot manager not as complex as GAG or GRUB.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

In which case, you really need to read up on NTFS, FAT and any other partitions you may want to install on. Can I suggest reading http://www.osdev.org/wiki/NTFS, particularly the links at the bottom of the page.

Cheers,
Adam
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

I have another very important question:

Code: Select all

struct partition_table
{
	unsigned char active;
	unsigned char start_head;
	unsigned char start_sector;
	unsigned char start_cylinder;
	unsigned char type;
	unsigned char end_head;
	unsigned char end_sector;
	unsigned char end_cylinder;
	unsigned int start_lba;
	unsigned int end_lba;
} __attribute__((packed));

struct _mbr_t
{
	uunsigned char useless_data[446];
	struct partition_table partitions[4];
	unsigned short signature;
} __attribute__((packed));

If I read the MBR and print these values, all (including LBA values) are correct except CHS values. Why?
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

I'm not sure about this but I think this is because of CHS you can address maximum 8GB and with LBA you can address 2TB.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

muisei wrote:I'm not sure about this but I think this is because with CHS you can address maximum 8GB and with LBA you can address 2TB.
But the partition's utility included in yast says to me corrects cylinders values of all partitions. Maybe the values must be written in a different way? I print like this: printf("End Cylinder: %d\n", mbr.partitions[0].end_cylinder);
User avatar
muisei
Member
Member
Posts: 79
Joined: Sat Sep 23, 2006 2:10 pm
Location: Bulgaria
Contact:

Post by muisei »

It's quite possible taht 'yast' reads only LBA values and then generate the CHS.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

muisei wrote:It's quite possible taht 'yast' reads only LBA values and then generate the CHS.
how can I generate CHS values from LBA values?
Post Reply