Page 1 of 2
Some questions about MBR
Posted: Wed Mar 21, 2007 11:34 am
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?
Posted: Wed Mar 21, 2007 12:04 pm
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.
Posted: Wed Mar 21, 2007 12:18 pm
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.
Posted: Wed Mar 21, 2007 1:52 pm
by AJ
MarkOS wrote: GRUB and GAG are too much complex.
More complex than writing your own boot manager?
Re: Some questions about MBR
Posted: Wed Mar 21, 2007 3:08 pm
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.
Posted: Wed Mar 21, 2007 3:48 pm
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.
Posted: Wed Mar 21, 2007 4:21 pm
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.
Posted: Thu Mar 22, 2007 8:27 am
by Jeko
sorry double post
Posted: Thu Mar 22, 2007 8:27 am
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.
Posted: Thu Mar 22, 2007 9:13 am
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
Posted: Fri Mar 23, 2007 9:30 am
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?
Posted: Fri Mar 23, 2007 9:53 am
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.
Posted: Fri Mar 23, 2007 10:04 am
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);
Posted: Fri Mar 23, 2007 11:29 am
by muisei
It's quite possible taht 'yast' reads only LBA values and then generate the CHS.
Posted: Sat Mar 24, 2007 11:42 am
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?