Skip to content

Using physical floppy disks

Maximilian Jung edited this page Nov 8, 2024 · 4 revisions

The main goal of this project is to write a new operating system for vintage hardware and for that we need a physical disk to boot. This is becoming increasingly difficult, since we are living in times in which disk drives are dying out anyway - and very few computers still have an interface for floppies. You will probably end up having to use an external USB floppy drive. The good thing is: These usually have their own controller that abstracts the low-level handling, so that a disk can be used as a block device (similar to a USB stick). The disadvantage is that we are dependent on the correct firmware implementation, as we want to copy the image exactly.

Understanding floppies

We are talking about 3 1/2 inch floppy disks, which are common for an 80386 system. These disks are usually structured as follows: There are two sides that can be written to, so there are 2 heads. The heads can reach 80 tracks by moving radially towards and away from the center. By rotating the disk, 18 sectors of 512 bytes each can be reached on each track.

80 tracks * 18 sectors * 512 bytes * 2 heads = 1.44 MiB or 1440 KiB

Preparing disks

Find the correct device

The lsblk command provides a useful system utility, that lists all block devices attached to your system. Go through the list and find the name of the correct device file (easily recognizable by its size).

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 232.9G  0 disk 
└─sda1   8:1    0 232.9G  0 part /
sdb      8:16   1   1.4M  0 disk 

Low-level formatting

As described before, a floppy disk is divided into tracks and sectors. This structure is initially established in a process called "low-level formatting". As you may have guessed, this will wipe the entire disk.

There is a neat utility ufiformat (AUR) specifically for formatting with USB devices:

# Format sdb as a 1.4M floppy
ufiformat -f 1440 /dev/sdb

Using floppy disks

Before you copy anything to disk, it is strongly recommended to create a clean image in a separate file. The reason for this is that there may be residuals of the previous write left on disk, which might be left unchanged otherwise. Use dd to create an empty image file:

dd if=/dev/zero of=~/free86/empty_image.img bs=512 count=2880

You can then copy your compiles as shown below.

Writing data to disk

To write raw data to specific sectors on the floppy, you can also use the dd command. In addition to that, is it quite easy to calculate the correct offset relative to the beginning of the image file. Just set the block size to the sector size (512 bytes) and expect 18 sectors per track.

# Write to the first sector of the second track
dd if=example.bin of=/dev/sdb bs=512 count=17 conv=notrunc

Checking disk condition

Floppies disks degrade over time. Verify that the disk is in good condition before using it. There utility badblocks checks for bad sectors:

# Check disk sdb
badblocks -w /dev/sdb

What makes them bootable

Disks are considered bootable when the MBR (Master Boot Record - first sector, first track) ends with the boot signature 0x55aa. If found, the first sector is loaded into memory at address 0x7c00 and executed.