[SOLVED] Virtual Disk (Bochs Disk File) and MBR
[SOLVED] Virtual Disk (Bochs Disk File) and MBR
Hi.
I am newbie in OS programming.
I must boot my kernel from hard disk - not floppy. So I have create virtual disk, and here is a little problem. I do not know how to write MBR section for my Bootloader.
Simple bootloader in 512 bytes, should call extended bootloader over 512 - 'cose file system driver is needed to boot kernel from disk. So for testing I must write my own file system but first write bootloader to virtual hard disk.
I know how to copy files to virtual disk but I really do not know how to write bootsector... It is passible?
I really need my own file system. So I really need my own bootloader at mbr...
I am using Linux - any idea?
Thanks a lot.
I am newbie in OS programming.
I must boot my kernel from hard disk - not floppy. So I have create virtual disk, and here is a little problem. I do not know how to write MBR section for my Bootloader.
Simple bootloader in 512 bytes, should call extended bootloader over 512 - 'cose file system driver is needed to boot kernel from disk. So for testing I must write my own file system but first write bootloader to virtual hard disk.
I know how to copy files to virtual disk but I really do not know how to write bootsector... It is passible?
I really need my own file system. So I really need my own bootloader at mbr...
I am using Linux - any idea?
Thanks a lot.
Last edited by yonami on Thu Jun 29, 2006 10:35 am, edited 1 time in total.
- AndrewAPrice
- Member

- Posts: 2327
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
Disk images in Bochs are basically raw disk images. Find out how big the sectors are for the harddrive (usualy 512 bytes), and write a binary bootloader that is that size, and replace the beginning of the disk image with your bootloader.
The master boot record also needs to store a list of partitions in a partition table, and later you'll probably need and extended MBR to help store the partition table in if 512 bytes isn't enough (Windows XP reserves 8MB for the extended MBR!)
If partitioning is too hard you could write a file system header to the first sector of the disk and use the whole disk as a single partition. You can do anything you like, it's you're operating system!
Just remember that only the first sector of the hard drive is in memory when the system is powered on.
EDIT: You can find plenty of examples of MBRs through a simple Google search!
The master boot record also needs to store a list of partitions in a partition table, and later you'll probably need and extended MBR to help store the partition table in if 512 bytes isn't enough (Windows XP reserves 8MB for the extended MBR!)
If partitioning is too hard you could write a file system header to the first sector of the disk and use the whole disk as a single partition. You can do anything you like, it's you're operating system!
Just remember that only the first sector of the hard drive is in memory when the system is powered on.
EDIT: You can find plenty of examples of MBRs through a simple Google search!
no you dont... the MBR doesnt know anything about the filesystem -- only the partitions, your boot sector should be at the first sector of the partition, which the MBR will load just like BIOS would
I really need my own file system. So I really need my own bootloader at mbr...
not really familier with linux (as i usually use windows), but iirc linux comes with tools to create disk images (and even format them -- this should take care of your MBR) and insert sectors (for adding your bootsector)I am using Linux - any idea?
this isnt quite accurate -- boot menu programs (not really part of the MBR), commonly use sectors between the MBR and the first partition (edit: also some partition managers use this space to create backups of the MBR/partition table) -- traditionally, partitions always start on the first sector of a cylinder, therefore an entire cylinder is unused between the MBR and the first partition (this wasnt intended for an extended MBR, but rather to simplify sector adjustment)
The master boot record also needs to store a list of partitions in a partition table, and later you'll probably need and extended MBR to help store the partition table in if 512 bytes isn't enough (Windows XP reserves 8MB for the extended MBR!)
modern systems have no concept of 'cylinder' as they use LBA (for obvious reasons), however, for compatability, winXP reserves some space:
512 (bytes/sector) * 63 (max sector/track) * 254 (max heads) = 8,193,024 -- almost 8MB -- noone could possibly expect more than that
OK. But I know that
I am asking how to write my 512 bytes on disk file. I can't copy bootloader as a single file. It must be in MBR section.
I think I must write simple code, and run with Bochs as pseudo-kernel. Than than kernel should write on virtual disk byte by byte my Bootloader ...
Good I think?
I am asking how to write my 512 bytes on disk file. I can't copy bootloader as a single file. It must be in MBR section.
I think I must write simple code, and run with Bochs as pseudo-kernel. Than than kernel should write on virtual disk byte by byte my Bootloader ...
Good I think?
- chase
- Site Admin
- Posts: 715
- Joined: Wed Oct 20, 2004 10:46 pm
- Libera.chat IRC: chase_osdev
- Location: Texas
- Discord: chase/matt.heimer
- Contact:
Are you just asking what utility to use to copy your compiled code into the correct section of your virtual disk image?yonami wrote:OK. But I know that![]()
I am asking how to write my 512 bytes on disk file. I can't copy bootloader as a single file. It must be in MBR section.
I think I must write simple code, and run with Bochs as pseudo-kernel. Than than kernel should write on virtual disk byte by byte my Bootloader ...
Good I think?
If so I'm assuming that the disk image is a file that is a raw image(no special compressed virtual machine format). In Linux you'd use "dd" like this:
Code: Select all
dd if=/path/mymbr.bin of=/path/image.dsk bs=512 count=1
Code: Select all
dd if=/path/mysector.bin of=/path/image.dsk bs=512 count=1 seek=1
EDIT: You could probably just have your compiled MBR be your virtual disk image if you wanted, just add zeros to the end of it to get the right disk size.
Last edited by chase on Thu Jun 29, 2006 10:25 am, edited 1 time in total.
- AndrewAPrice
- Member

- Posts: 2327
- Joined: Mon Jun 05, 2006 11:00 pm
- Location: USA (and Australia)
OK. Now I can't write Extended Bootloader
Should I use seek=512 to write Extended Bootloader at 512 (200h)?:
Should I use seek=512 to write Extended Bootloader at 512 (200h)?:
Code: Select all
dd if=boot-ext.out bs=308 of=/dev/loop/0 seek=512
-
rexlunae
- Member

- Posts: 134
- Joined: Sun Oct 24, 2004 11:00 pm
- Location: North Dakota, where the buffalo roam
Not quite. Seek is in units of bs, so to write the second sector of a drive, use bs=512 and seek=1.yonami wrote:OK. Now I can't write Extended Bootloader![]()
Should I use seek=512 to write Extended Bootloader at 512 (200h)?:Code: Select all
dd if=boot-ext.out bs=308 of=/dev/loop/0 seek=512
