2

I'm studying OS development and I use brokenthorn resource but with a little bit different tool, namely, I use CentOS, NASM and Qemu as a test/dev environment. I've been facing some issues while creating bootable img file with secondary loader.

I've got two files: 1. bootloader.bin which is first stage loader. 2. stage2.bin which is secondary loader.

In order to create bootable img file I do the following:

  • dd if=/dev/zero of=floppy.iso bs=1024 count=1440 -- Creating empty file
  • mkfs.vfat -F 12 floppy.iso --Creating file system in the file
  • dd if=../bin/bootloader.bin of=floppy.iso bs=512 count=1 conv=notrunc --Writing first loader to the boot sector
  • sudo mount -o loop floppy.iso /mnt/floppy/ -- Try to mount file system to write secondary loader using previously create FAT-12 files system.

In the last step I'm getting the following error:

mount: /dev/loop0 is write-protected, mounting read-only
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

Can you please help me to understand what I'm doing wrong and what other ways I can use to accomplish creating bootable img with file system on board. Thanks!

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • 2
    `mount` will look at the bootsector (first 512 bytes) to determine the disk geometry and the type and size of the file system (FAT12). The section at the beginning of the bootsector with this data is called the [BIOS Parameter Block](https://en.wikipedia.org/wiki/BIOS_parameter_block)(BPB). – Michael Petch Nov 18 '18 at 08:37
  • Thanks a lot, I've added BPB to my bin file and I now I can mount into my file system. But is there any way to the same just using linux tools? – Andrew Bolotov Nov 18 '18 at 12:49

1 Answers1

1

I once stumbled upon the similar problem and this answer may be of help to you.

However I would strongly recommend you switching to bootloader like Grub and spend time and effort developing the actual OS of yours. For that I would reccomend grub resque as it's simple to use and allows to to quickly create ISO that you can either burn or feed to virtual machine. Otherwise, you may just drown in all these minor things like enabling protected mode, loading your stages and so on.

hrust
  • 734
  • 1
  • 11
  • 34
  • I would strongly recommend building the bootloader by yourself as the knowledge, power and other advantages far outweigh the time. – vigilante_stark Jan 20 '19 at 05:49
  • @vigilante_stark I believe it's obvious that that this question may rise heated discussion. I agree that this will inevitably help build up knowledge, but if main goal is to develop an OS it's wise to jump right in using already existing and well-working building block as grub or any other general purpose bootloader. – hrust Jan 21 '19 at 13:17