MBR issues
MBR issues
Hello,
I am working on developing a bootloader that works with multiple partitions of a hard disk. It use BootProg. I was wondering how I go about writing out a bootloader to a partition. Also, does fdisk or parted write a bootstrap program for me?
I am working on developing a bootloader that works with multiple partitions of a hard disk. It use BootProg. I was wondering how I go about writing out a bootloader to a partition. Also, does fdisk or parted write a bootstrap program for me?
Re: MBR issues
You can write sectors to the disk with dd.nexos wrote:I was wondering how I go about writing out a bootloader to a partition.
I'm not sure what you mean, but I suspect the answer is no. I thought you said you were using BootProg to boot the computer.does fdisk or parted write a bootstrap program for me?
Are you quite sure that you understand enough about hard disks, partitions, etc. to reinvent the wheel?
Re: MBR issues
Hi,
I don't get it, are you using BootProg or are you developing your own? Not really important, just asking. By the way, the Standard MBR, embedded in "FDISK.EXE /MBR", is capable of handling multiple partitions. I feel you are sieging an open gate.
Don't use "dd" on MBR. Although it will install the boot code fine, it will also destroy all your data (which includes the partitioning table). Here is a small (ca. 100 SLoC in C) tool that I wrote for my boot loader. It reads the MBR (or VBR) from the disk at line 75. Then it copies the code from _binary____boot_bin_start and the data from the original boot sector onto a new buffer at line 82. (Then it will locate stage2 and save it's starting sector too, irrelevant to you). Finally it saves the new MBR buffer at line 103.
Cheers,
bzt
I don't get it, are you using BootProg or are you developing your own? Not really important, just asking. By the way, the Standard MBR, embedded in "FDISK.EXE /MBR", is capable of handling multiple partitions. I feel you are sieging an open gate.
Don't use "dd" on MBR. Although it will install the boot code fine, it will also destroy all your data (which includes the partitioning table). Here is a small (ca. 100 SLoC in C) tool that I wrote for my boot loader. It reads the MBR (or VBR) from the disk at line 75. Then it copies the code from _binary____boot_bin_start and the data from the original boot sector onto a new buffer at line 82. (Then it will locate stage2 and save it's starting sector too, irrelevant to you). Finally it saves the new MBR buffer at line 103.
Cheers,
bzt
Re: MBR issues
Are you developing on Linux (there you have dd) or Windows?nexos wrote:Hello,
I am working on developing a bootloader that works with multiple partitions of a hard disk. It use BootProg. I was wondering how I go about writing out a bootloader to a partition. Also, does fdisk or parted write a bootstrap program for me?
Partitioning software doesn't write bootcode to the disk. EDIT: Ok, you got me on that, fdisk can be explicitely told to do so.
Greetings
Peter
Last edited by PeterX on Thu Jun 18, 2020 12:08 pm, edited 1 time in total.
Re: MBR issues
Not neccesarily! If you write only the first 446 bytes and the last two bytes, it's ok.bzt wrote:Don't use "dd" on MBR. Although it will install the boot code fine, it will also destroy all your data (which includes the partitioning table).
Code: Select all
dd if=mbr.bin of=/dev/sda bs=1 count=446
dd if=mbr.bin of=/dev/sda bs=1 seek=510 skip=510
Peter
Re: MBR issues
I am using BootProg, but I am talking about the code that loads the active partition. Does fdisk write that out? And I am using Linux.
Re: MBR issues
Additional comment: When writing to a VBR (partition boot sector) you must use a different dd-command:
Replace the "?" with the offset directly after the BPB (BIOS Parameter Block), assuming you want to use the FAT file system.
It is still unclear if you want to write your own loader or use Alexej's BootProg (or both, one in MBR other in VBR).
The generic MBR (see above for a link) chainloads a partition bootsector (VBR) and if that is BootProg, it loads your DOS-program file.
Greetings
Peter
Code: Select all
dd if=vbr.bin of=/dev/sda1 bs=1 count=3
dd if=vbr.bin of=/dev/sda1 bs=1 seek=? skip=?
It is still unclear if you want to write your own loader or use Alexej's BootProg (or both, one in MBR other in VBR).
The generic MBR (see above for a link) chainloads a partition bootsector (VBR) and if that is BootProg, it loads your DOS-program file.
Greetings
Peter
Re: MBR issues
I see. That's the original MBR boot code from IBM, but also any Microsoft boot code (from MS-DOS 1.0 to Win 98) will do. In short, they look for the boot flag in the partition records (0x80), and they chainload the VBR for the partition which has it. THe page I've linked has a VERY detailed description on the asm code how it's done.nexos wrote:I am using BootProg, but I am talking about the code that loads the active partition.
I'm afraid not, only fdisk under Win supports that. On Linux, you'll need the ms-sys package. If it's not provided by your distro's repo, just get it from sourceforge, it is trivial to compile.nexos wrote:Does fdisk write that out? And I am using Linux.
@PeterX: yes, but it's easy to mess up. Your dd commands won't work either, btw, because you've forgot the "conv=notrunc" option
Cheers,
bzt
Re: MBR issues
On my PC it works. I never used "notrunc" simply because I was not aware of it. I will check that option in the man page or on the web.bzt wrote:nexos wrote:Your dd commands won't work either, btw, because you've forgot the "conv=notrunc" option
EDIT:Here they say:
https://stackoverflow.com/questions/205 ... sk-with-dd
Greetingsnotrunc is only important to prevent truncation when writing into a file. This has no effect on a block device such as sda or sdb.
Peter