Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to make a floppy image with a working file system so that I can test a 2 stage boot loader. When I attempt to mount the floppy and then cp the second binary over to it, mount gets all unhappy. Here are the steps I am trying to use:

dd if=/dev/zero of=floppy.img bs=512 count=2948
mkfs.vfat floppy.img
dd if=boot1.bin of=floppy.img bs=512 count=1
su -c 'mount -t msdos -o loop floppy.img /mnt'

dmesg | tail

[591461.669870] FAT: invalid media value (0x09)
[591461.669876] VFS: Can't find a valid FAT filesystem on dev loop0.
share|improve this question

2 Answers 2

I've actually written a two-stage floppy boot loader a long time ago. Despite what various specifications might say (from Microsoft or other "experts"), the first sector of the diskette must conform to a standard MS-DOS floppy with a BIOS Parameter Block, BPB. The error message you're seeing seems to indicate that your "boot1.bin" does not meet this requirement. The only thing you can really change in the floppy boot sector about 400 or so bytes of code. You cannot customize the BPB values from what MS-DOS or Windows uses for floppies.

Even though there is a value to indicate the number of sectors that the boot code occupies, every BIOS and other software I encountered only expects or tolerates one reserved sector for boot. Two copies of the FAT are required, and then the first sector of the root directory. The method I used for storing the secondary boot loader was to hard allocate some sectors following the root directory, and then mark those sectors as "bad" in the FAT. This accomplished the following goals:

  1. the additional sectors used by the secondary loader were at a fixed location on the floppy and known to the first-stage boot, which had to read/load them.

  2. hid the secondary loader from users.

  3. made the secondary loader undeleteable.

  4. the floppy was usable in DOS and mountable in Unix.

BTW floppies have a boot sector. It is not called a MBR, as there is no partition table.

share|improve this answer
    
You'll have a hard time pointing to where Microsoft, or indeed an expert, has said that a BPB is not used on a FAT format floppy disc. None will have said any such thing. And you've missed out on a decade and a half of Microsoft operating systems from DOS+Windows 95 OSR2 onwards reserving 32 sectors for bootstrap code (and FSInfo blocks). The notion that firmwares don't like anything other than 1 reserved sector is nonsense. Firmwares don't care one whit. As for "other softwares": What do you think that the -R option to the questioner's mkfs.vfat is there for? –  JdeBP Aug 15 '11 at 7:07
    
I don't expect anybody to document the shortcuts other software have taken which ignores values in the floppy BPB that I've encountered. After designing and implementing a multi-stage floppy loader (that went into release & production) that would work on any PC, I'm offering my real-world experience, not analysis from reading a spec. –  sawdust Aug 15 '11 at 7:42
    
My comments are based on actually customizing the BPB, e.g. reserving 4 sectors instead of the standard 1 sector, and seeing various MS-DOS utilities totally ignore my nonstandard specification (i.e. root directory was still read from a hardcoded location). IIRC the "MS-DOS Bible" mentioned that the 2nd FAT was not used on a floppy; I found that to be false. I've never seen a floppy with 32 sectors for bootstrap; have you? The BPB also encompasses "logical disk drives" in HDD partitions, as well as floppies. The usage of the large bootstrap is only on HDD, not floppies. –  sawdust Aug 15 '11 at 7:45
    
I hate to break this to you kiddo, but your "real-world experience" is outweighed by the real world experiences of the millions of people who have happily bootstrapped DOS+Windows 95 OSR2 and later operating systems from FAT volumes with 32 reserved sectors. It's outweighed by mine, too. I actually have a FAT formatted floppy boot disc with 32 reserved sectors in one of my machines right now. The ideas that this is specific to hard discs, or that firmwares care about it, are simply erroneous, and demonstrably so by people who've used DOS+Windows 95 OSR2 or later. –  JdeBP Aug 15 '11 at 10:33
    
And stop taking what the "MS-DOS Bible" says as definitive on the subject. If it's the "MS-DOS Bible" that I have, it pre-dates Microsoft's widespread introduction of FAT volumes with 32 reserved sectors by some five years. The only tools that I've encountered that cannot handle such FAT partitions were made years before DOS+Windows 95 OSR2. Modern tools can cope, as indeed can old tools written by people who took heed of the existence of the reserved sectors field of the BPB right from the get-go and never hit the problem when the field value started to be something other than 1. –  JdeBP Aug 15 '11 at 10:39

You're learning some of the problems with using a POSIX toolset for this sort of stuff. Installing a bootstrap program into the VBR of a volume is not a matter of just blamming a sector full of data into sector #0 from an image. You must preserve the existing BIOS Parameter Block, coping with the several BPB variants.

The tools that come with operating systems like MS/PC/DR-DOS, OS/2, and Windows NT know all about things like BPBs. Their various sys, sysinstx, bootsect and other tools know how things are supposed to be handled. But if you use POSIX tools like dd you have to manually tell them which bytes to overwrite in the VBR and which to preserve as-is.

ms-sys knows the how to preserve BPBs as well, but it doesn't have the option of applying a custom bootstrap program. Go and request it as a new feature.

share|improve this answer
    
"request it as a new feature" - The Solaris fdformat utility had an option to install a custom floppy boot program. –  sawdust Aug 15 '11 at 6:54
    
The Linux fdformat utility has not, and Linux is what the questioner is asking about. The Solaris fdformat utility was superseded by rmformat, which had no such option, since the functionality for high-level formatting was transferred to mkfs_pcfs. mkfs_pcfs has the reserve= option, too. –  JdeBP Aug 15 '11 at 10:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.