Does anybody have a code fragment to read the boot sector of a PC running Linux (Red Hat 6.2 if it matters)?
Martin Liddle wrote:
Does anybody have a code fragment to read the boot sector of a PC running Linux (Red Hat 6.2 if it matters)?
Linux by itself does not use a boot sector. It can be loaded by various boot loaders like LILO, grub or loadlin. While the latter one is a Dos executable, the former two contain their own boot sectors. You may want to look into their source code (C, of course) to find out more.
Frank
In article 200105151140.NAA09220@goedel.fjf.gnu.de, Frank Heckenbach frank@g-n-u.de writes
Martin Liddle wrote:
Does anybody have a code fragment to read the boot sector of a PC running Linux (Red Hat 6.2 if it matters)?
Linux by itself does not use a boot sector. It can be loaded by various boot loaders like LILO, grub or loadlin. While the latter one is a Dos executable, the former two contain their own boot sectors. You may want to look into their source code (C, of course) to find out more.
I think my terminology may be faulty. What I am after is the Master Boot Record (MBR) which I think will be present on a PC, almost irrespective of the operating system. I have downloaded the source for grub but there is a lot to plough through. I just hoped somebody had done it before.
Martin Liddle wrote:
In article 200105151140.NAA09220@goedel.fjf.gnu.de, Frank Heckenbach frank@g-n-u.de writes
Martin Liddle wrote:
Does anybody have a code fragment to read the boot sector of a PC running Linux (Red Hat 6.2 if it matters)?
Linux by itself does not use a boot sector. It can be loaded by various boot loaders like LILO, grub or loadlin. While the latter one is a Dos executable, the former two contain their own boot sectors. You may want to look into their source code (C, of course) to find out more.
I think my terminology may be faulty. What I am after is the Master Boot Record (MBR) which I think will be present on a PC, almost irrespective of the operating system. I have downloaded the source for grub but there is a lot to plough through. I just hoped somebody had done it before.
Yep, on a Linux system, usually lilo or grub is stored in the MBR (though they can also be stored elsewhere).
Frank
On Tue, 15 May 2001, Frank Heckenbach wrote:
Martin Liddle wrote:
In article 200105151140.NAA09220@goedel.fjf.gnu.de, Frank Heckenbach frank@g-n-u.de writes
Martin Liddle wrote:
Does anybody have a code fragment to read the boot sector of a PC running Linux (Red Hat 6.2 if it matters)?
Linux by itself does not use a boot sector. It can be loaded by various boot loaders like LILO, grub or loadlin. While the latter one is a Dos executable, the former two contain their own boot sectors. You may want to look into their source code (C, of course) to find out more.
I think my terminology may be faulty. What I am after is the Master Boot Record (MBR) which I think will be present on a PC, almost irrespective of the operating system. I have downloaded the source for grub but there is a lot to plough through. I just hoped somebody had done it before.
Yep, on a Linux system, usually lilo or grub is stored in the MBR (though they can also be stored elsewhere).
Frank
I do not know whether this will be of any help, but on FreeBSD-Systems you will find a command # boot0cfg -f file ad0 which will print the content of the MBR on disk ad0 into file . Perhaps you will find something similar for Linux? Have a look at # man boot !?
Uli.
################################################### # # # www.pukruppa.de www.2000d.de # # # ###################################################
In article gIy68SAOfTA7EwBO@tcs02.demon.co.uk, Martin Liddle martin@tcs02.demon.co.uk writes
In article 200105151140.NAA09220@goedel.fjf.gnu.de, Frank Heckenbach frank@g-n-u.de writes
Martin Liddle wrote:
Does anybody have a code fragment to read the boot sector of a PC running Linux (Red Hat 6.2 if it matters)?
Linux by itself does not use a boot sector. It can be loaded by various boot loaders like LILO, grub or loadlin. While the latter one is a Dos executable, the former two contain their own boot sectors. You may want to look into their source code (C, of course) to find out more.
I think my terminology may be faulty. What I am after is the Master Boot Record (MBR) which I think will be present on a PC, almost irrespective of the operating system. I have downloaded the source for grub but there is a lot to plough through. I just hoped somebody had done it before.
To answer my own question, I finally managed to start to think and came up with this, which seems to do what I want:
Var InBuffer: Array[0..511] of Byte; InFile:File;
Reset(InFile,'/dev/hda',512); Blockread(Infile,InBuffer,1);
Martin Liddle wrote:
To answer my own question, I finally managed to start to think and came up with this, which seems to do what I want:
Var InBuffer: Array[0..511] of Byte; InFile:File;
Reset(InFile,'/dev/hda',512); Blockread(Infile,InBuffer,1);
OK, if you only want the raw data, sure, you can just read them from the device. I was thinking more complicated -- to get some more readable information or something ...
Frank
Martin Liddle wrote:
To answer my own question, I finally managed to start to think and came up with this, which seems to do what I want:
Var InBuffer: Array[0..511] of Byte; InFile:File;
Reset(InFile,'/dev/hda',512); Blockread(Infile,InBuffer,1);
OK, if you only want the raw data, sure, you can just read them from the device. I was thinking more complicated -- to get some more readable information or something ...
The format of the MBR is probably in the Interrupt List, and surely in the so called "Tech Help" series of hyperlinked dos programmer helpfiles.
On Tue, 15 May 2001, Frank Heckenbach wrote:
Martin Liddle wrote:
To answer my own question, I finally managed to start to think and came up with this, which seems to do what I want:
Var InBuffer: Array[0..511] of Byte; InFile:File;
Reset(InFile,'/dev/hda',512); Blockread(Infile,InBuffer,1);
OK, if you only want the raw data, sure, you can just read them from the device. I was thinking more complicated -- to get some more readable information or something ...
In case someone later wants to write something there it would be safer to think in terms of a record. Otherwise messing with that last 66 bytes is an invitation to disaster.
type PartitionRec : array[ 1..16 ] of byte;
TMBR = record bootcode : array[ 1..446 ] of byte; PartitionTable : array[ 1..4 ] of PartitionRec; validsig : shortcard; { = AA55h } end;