27

A lot of web sites describe how to create a bootable floppy disk using an existing image (via dd). But what about the image makes it bootable?

I'm interested in making my own bootable floppy images for an IBM PC and want to understand the details.

5

5 Answers 5

51

The notion of a bootable-vs-non-bootable floppy is a little odd. It's worth noting that almost all floppies you're likely to have are actually bootable: it's just that they boot a program that isn't especially useful (it either displays a message saying to insert a system disk, or they execute INT 18h - which runs BASIC if it's installed in ROM, or displays a boot error if it isn't).

In any case, the key to writing a useful bootable disk is to understand what the BIOS does when it boots from floppy (booting from a hard disk is subtly different, and adds a little extra complexity), which is this:

  • First, it loads the first sector (512 bytes) of the first track of the first side (if the disk is double sided) of the disk into memory at 0000:7c00h.
  • In some BIOSs, there may be a check that the last two bytes of the sector are 55h AAh (my tests on compatible machines show that this isn't necessarily true there, but I suspect IBM BIOSs do perform this test based on documents I've read about it), and the BIOS will ignore the disk if this signature isn't present.
  • The BIOS then jumps to 0000:7c00h, which is expected to contain a jump instruction to the actual code (again, some BIOSs may check whether this is present or not before booting it).

In addition to this, most useful boot programs will also include the data structures that are necessary for some file system or other, typically a FAT12 header which occupies the space between bytes 3 and 30.

The rest of the sector is available for the boot program. The DOS boot program simply loads a bunch of sectors from the start of the disk, performs some basic checks to make sure they were loaded correctly, and jumps into them to start the actual OS. Some other boot sectors are smarter; I wrote one back in the 90s that:

  • Checked if the processor in the system was a 386 or higher, giving useful error messages if it wasn't
  • Located and loaded a file by name in the FAT filesystem, thus allowing an OS kernel to be installed without the disk having any special space allocated as is required for DOS.

Writing a boot sector is fun. Good luck. :)

25
  • 9
    @Joshua It's a little hard. Credit where due. You know, the backside of the Dunning-Kruger effect is highly skilled people don't realise how good they are. Commented Dec 27, 2017 at 22:26
  • 3
    @JeremyP When did they add FAT disk IO to the BIOS? I am quite sure it wasn't there when the XT shipped, it would have made the BIOS fairly large... OP's XT-286 shipped in 1986, would it have been by then? Commented Dec 28, 2017 at 9:18
  • 3
    @Harper It's not possible to write code to navigate a FAT filesystem in 512 bytes. That's why there are certain requirements on the layout of the files used to boot. The S attribute on those files tells defragmentation tools not to move those sectors around.
    – kasperd
    Commented Dec 28, 2017 at 11:11
  • 3
    @JeremyP A modern BIOS might have some FAT code built in, but it would only be used by the BIOS itself not by DOS or other operating systems. When DOS was introduced the BIOS only provided the code for reading and writing disk blocks, the file system driver had to be provided by DOS itself.
    – kasperd
    Commented Dec 28, 2017 at 11:14
  • 5
    @Harper I found the code. The code from 7CD7 to 7CEB verifies that the first two entries in the root directory are IO.SYS and MSDOS.SYS so I was right about those having to be the first two entries. The code from 7D05 to 7D10 takes the starting cluster of IO.SYS (from the directory entry) and multiplies by SECTORS_PER_CLUSTER. So it does indeed use the starting location of the IO.SYS file.
    – kasperd
    Commented Dec 28, 2017 at 18:10
10

what about the image makes it bootable?

The program(s loader) starts at Track 0 Sector 0 of a device

I'm interested in making my own bootable floppy images for an IBM PC

Write the program to be executed (like this minimal one) to Sector 0 Track 0 and press reset.

[I] want to understand the details.

It's that simple. The BIOS looks for a floppy in drive 0, reads the first block and starts whatever is located there.

Wikibooks offers a real nice and easy to follow writeup about how to build a boot sector / bootable program, including an analysis how Linux does it.


Now, if you want to make floppies that also adhere to other standards - for example the FAT file system or the like, then you have to format it according to those specs. Like using a Volume Boot Record and squeezing your program in there. Plus adding a FAT structure and packing further boot stages into files according to that structure - or at least reserved by dummy entries.

But strictly nothing of that is needed when your goal is a bootable disk to do your own stuff. BIOS doesn't care for directories, clusters or assignment. Just Sector 0 on Track 0 and from there on Track/Sector numbers for reading, but that's already the domain of your program.

2

Addon, answering an aspect explicitly asked about in the question.

A "dd image" of a complete floppy disk, unless dd is used with special (skip/count) parameters, will always carry the parts that make a floppy disk bootable or not bootable along with it - dd if=/dev/fd0 of=temp ; change floppy to empty one; dd if=temp of=/dev/fd0 will create a bootable copy of a bootable original, unless special techniques (copy protection that works by (mis)using normally non-addressable parts of the media) were used in the original.

1

what about the image makes it bootable?

An operating system "kernel" sitting at track 0 sector 0.

EDIT: if "data", or a program that doesn't have the necessary code to finish booting the system, is at track 0 sector 0, then the BIOS' bootstrap code will throw an error saying that an operating system is not found.

EDIT 2: if it's a fresh or unformatted disk, the BIOS is still going to try and look where it thinks track 0 sector 0 is, not find anything and then throw an error.

7
  • Welcome to Retrocomputing Stack Exchange. This answer is technically correct but it's a bit minimal. What are the implications of this. Is it possible to omit a Track 0 or even just a Track 0 Sector 0? How can a floppy not be bootable?
    – wizzwizz4
    Commented Dec 27, 2017 at 13:38
  • @wizzwizz4 how do you omit track 0? You can not write anything to it, but the magnetic "stuff" will still be there, and the BIOS will still try to read it, even though it's random junk.
    – RonJohn
    Commented Dec 27, 2017 at 13:46
  • 1
    It's true that the BIOS won't boot a floppy disk that hasn't been formatted yet or otherwise doesn't have a readable first sector (track 0 sector 0). However if that first sector is readable then most BIOSes will execute whatever is there, regardless of whether it contains code or random data. If what it executes isn't code then the computer will likely just crash, freezing up without printing any sort of error message.
    – user722
    Commented Dec 27, 2017 at 16:15
  • @RossRidge and that's why, as part of the "Format A:" process, the format software writes a boot record with some correct code which handles that situation gracefully... Commented Dec 27, 2017 at 19:36
  • @Harper Sure, if you format the disk on an IBM PC or compatible using MS-DOS. If you format it on another kind of computer you might get some code for an entirely different CPU or just some "random" data if it uses the first sector for some other purpose.
    – user722
    Commented Dec 27, 2017 at 19:52
1

Short answer: A magic number (0xAA55) being at the end of the first sector on the floppy.

Slightly longer answer: "Booting" means that the first 512 bytes of the floppy are copied to memory (usually at real mode segment 0x0000:0x7C00 or physical address 0x7C00). This is the first sector of the floppy, sector 0. It's also known as the bootsector. The processor then jumps here and starts execution. Some older BIOSes will check that the last 2 bytes of the segment are 0xAA55. This is a magic number.

DD is a tool that is used to write to specific sectors on the disk. It is one of the more preferable tools for accessing raw disks on *nix systems.

EDIT: This is for IBM-PC & compatibles. See this article.

3
  • 1
    BIOSes don't actually check for the AA55 magic number on floppies, especially not old ones. Original PC-DOS 1.x boot discs don't have this signature nor do the Xenix boot floppies I have.
    – user722
    Commented Dec 28, 2017 at 3:47
  • This seems to be an answer about a specific type of bootable floppy. Could you clarify what specific machine this information is from?
    – wizzwizz4
    Commented Dec 28, 2017 at 15:26
  • 1
    I had the Commodore XT technical manual with the official BIOS listing, and I can swear the AA55 magic number was there to test for boot validity. Commented Jan 5, 2018 at 11:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .