How do I createa bootable floppy disk?
How do I createa bootable floppy disk?
A totally dumb question I can't find answer for anywhere :/
I want to create a bootable floppy disk (like MS-DOS had) but cannot seem to find any resources. Wiki only has page for making a bootable ISO image or I am missing something? Does anybody know how do I do this? Thanks.
I want to create a bootable floppy disk (like MS-DOS had) but cannot seem to find any resources. Wiki only has page for making a bootable ISO image or I am missing something? Does anybody know how do I do this? Thanks.
My own MS-DOS like OS
https://github.com/Vik2015/weevil/
https://github.com/Vik2015/weevil/
http://bestsoft.azurewebsites.net/ wrote: With Bestsoft Space you can write operating system eaven if it your first software.
Re: How do I createa bootable floppy disk?
You simply put your bootloader in sector 1 of your floppy disk and 0x55 and 0xAA in the last two bytes of this sector.
-
- Member
- Posts: 5588
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I createa bootable floppy disk?
Floppy disk booting is simple enough that it can be described completely in only a few sentences.
Re: How do I createa bootable floppy disk?
Oh man, sorry, forgot to say. I am trying to create a bootable floppy disk with FAT12 filesystem on it, not just plain binary (that's simple DD command).Octocontrabass wrote:Floppy disk booting is simple enough that it can be described completely in only a few sentences.
My own MS-DOS like OS
https://github.com/Vik2015/weevil/
https://github.com/Vik2015/weevil/
http://bestsoft.azurewebsites.net/ wrote: With Bestsoft Space you can write operating system eaven if it your first software.
-
- Member
- Posts: 5588
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I createa bootable floppy disk?
In that case, you want to look for more information about FAT12.
Re: How do I createa bootable floppy disk?
Are you asking about creating your own boot code, which would boot from a FAT12 partition? Or are you asking about formatting an image with FAT and putting GRUB (or any other compatible boot loader) there?Vik2015 wrote:Oh man, sorry, forgot to say. I am trying to create a bootable floppy disk with FAT12 filesystem on it, not just plain binary (that's simple DD command).Octocontrabass wrote:Floppy disk booting is simple enough that it can be described completely in only a few sentences.
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
- Alan Kay
- Alan Kay
Re: How do I createa bootable floppy disk?
Hi,
The FAT file system uses a BPB to describe its layout. The BPB has a "reserved sectors" field which specifies the number of sectors that are reserved at the beginning of the file system (that won't be used by the file system itself). Normally (e.g. for data disks) the number of reserved sectors is 1 (and there's a boot sector that displays "This disk isn't bootable" when you boot it).
Nothing prevents you from setting the number of reserved sectors to (e.g.) 1234 and storing the boot sector plus whatever else you like (second stage, kernel, etc) in that area; and in that case you can use the DD command to copy the boot sector plus whatever else you like onto the disk while also having a perfectly valid FAT file system on the same disk.
The only real problems with this are:
Cheers,
Brendan
These options aren't mutually exclusive.Vik2015 wrote:Oh man, sorry, forgot to say. I am trying to create a bootable floppy disk with FAT12 filesystem on it, not just plain binary (that's simple DD command).Octocontrabass wrote:Floppy disk booting is simple enough that it can be described completely in only a few sentences.
The FAT file system uses a BPB to describe its layout. The BPB has a "reserved sectors" field which specifies the number of sectors that are reserved at the beginning of the file system (that won't be used by the file system itself). Normally (e.g. for data disks) the number of reserved sectors is 1 (and there's a boot sector that displays "This disk isn't bootable" when you boot it).
Nothing prevents you from setting the number of reserved sectors to (e.g.) 1234 and storing the boot sector plus whatever else you like (second stage, kernel, etc) in that area; and in that case you can use the DD command to copy the boot sector plus whatever else you like onto the disk while also having a perfectly valid FAT file system on the same disk.
The only real problems with this are:
- The BPB in the boot sector must match the disk and its layout (which is also a problem if/when you're supporting multiple different floppy disk formats; and is relatively trivial to work around by writing a simple utility)
- It's probably hard to find a utility that's capable of formatting a FAT file system in a suitable way (e.g. you can't just format the file system and then modify the reserved sectors field after, because it effects the location of the cluster allocation table and root directory). Of course it's relatively easy to create your own utility (to either format a disk or generate a blank disk image) to work around that
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- TightCoderEx
- Member
- Posts: 90
- Joined: Sun Jan 13, 2013 6:24 pm
- Location: Grande Prairie AB
Re: How do I createa bootable floppy disk?
One of the ways I got around that is to format a data disk, change BPB reserved sectors and then used windows Properties\Tools\"Check now" for drive A: and let that utility fix the problem. Probably not the most elegant way, but it did work.Brendan wrote:
- It's probably hard to find a utility that's capable of formatting a FAT file system in a suitable way (e.g. you can't just format the file system and then modify the reserved sectors field after, because it effects the location of the cluster allocation table and root directory). Of course it's relatively easy to create your own utility (to either format a disk or generate a blank disk image) to work around that
Re: How do I createa bootable floppy disk?
Hi,
I mostly just write a "create bootable floppy image" utility that takes the media type (e.g. 720 KiB, 1440 KiB, 1200 KiB, 1680 KiB floppy, etc) and the file names for parts of my OS (boot loader file name, boot image/initrd file name, etc) as command line arguments; where the utility generates a BPB to suit the media type, installs my OS into the image and sets a few special fields in the boot sector ("starting LBA for boot image/initrd", etc).
Of course I don't bother with FAT (I expect the minimal OS will eventually fill the floppy leaving no space for cluster allocation table, directory metadata, etc); but FAT isn't too complicated and it wouldn't be hard to write a "create bootable floppy image" utility that also creates a FAT file system.
Note: The main reason I like the "special utility" approach is that you can slap it into your OS's build system so that it generate 5 different floppy disk images (one for each format) whenever you build the OS (in addition to building files for PXE/network boot, CD images, whatever).
Cheers,
Brendan
Hmm - that's clever (I didn't realise something like that would work).TightCoderEx wrote:One of the ways I got around that is to format a data disk, change BPB reserved sectors and then used windows Properties\Tools\"Check now" for drive A: and let that utility fix the problem. Probably not the most elegant way, but it did work.Brendan wrote:
- It's probably hard to find a utility that's capable of formatting a FAT file system in a suitable way (e.g. you can't just format the file system and then modify the reserved sectors field after, because it effects the location of the cluster allocation table and root directory). Of course it's relatively easy to create your own utility (to either format a disk or generate a blank disk image) to work around that
I mostly just write a "create bootable floppy image" utility that takes the media type (e.g. 720 KiB, 1440 KiB, 1200 KiB, 1680 KiB floppy, etc) and the file names for parts of my OS (boot loader file name, boot image/initrd file name, etc) as command line arguments; where the utility generates a BPB to suit the media type, installs my OS into the image and sets a few special fields in the boot sector ("starting LBA for boot image/initrd", etc).
Of course I don't bother with FAT (I expect the minimal OS will eventually fill the floppy leaving no space for cluster allocation table, directory metadata, etc); but FAT isn't too complicated and it wouldn't be hard to write a "create bootable floppy image" utility that also creates a FAT file system.
Note: The main reason I like the "special utility" approach is that you can slap it into your OS's build system so that it generate 5 different floppy disk images (one for each format) whenever you build the OS (in addition to building files for PXE/network boot, CD images, whatever).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How do I createa bootable floppy disk?
Why would you write something that already exists?
Re: How do I createa bootable floppy disk?
Hi,
Of course even if mtools did support it properly, it still won't copy your file/s into the reserved area or set any special fields (e.g. like my "LBA for first sector of boot image/initrd" field); and won't do things like (e.g.) auto-determine the number of reserved sectors to use from the size/s of the files you want to put in the reserved area. Because of these things it'd end up being an ugly pile of hassles (e.g. rather than just an "mformat" that doesn't work; you'd need an "mformat" that doesn't work plus multiple "dd" commands that carefully avoid touching the BPB; and this pile of hassles will be fragile and break and need "manual tweaking" when the sizes of files change).
Cheers,
Brendan
Because mtools isn't capable of doing this (their "mformat" has no option to set/change the "reserved sectors" field).Combuster wrote:Why would you write something that already exists?
Of course even if mtools did support it properly, it still won't copy your file/s into the reserved area or set any special fields (e.g. like my "LBA for first sector of boot image/initrd" field); and won't do things like (e.g.) auto-determine the number of reserved sectors to use from the size/s of the files you want to put in the reserved area. Because of these things it'd end up being an ugly pile of hassles (e.g. rather than just an "mformat" that doesn't work; you'd need an "mformat" that doesn't work plus multiple "dd" commands that carefully avoid touching the BPB; and this pile of hassles will be fragile and break and need "manual tweaking" when the sizes of files change).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How do I createa bootable floppy disk?
FAT has been historically tried and tested to make half a sector be enough for loading further sectors by filename. That is the normal approach, and that is what mtools supports perfectly fine. If you deviate from that, that's a choice of creating your own challenge for the sake of it, rather than one of practicality. In fact, you have enough accompanying bootsectors of various licences up for the taking where even finding and loading a file is not an issue anymore.
Re: How do I createa bootable floppy disk?
Just for interest, have you ever seen a FAT12 floppy with "reserved sectors" not equal one? I mean historical floppies that are not made by a "hobby OS" community. All the commercial operating systems seem to have used only one reserved sector. I have no idea why because using those reserved sectors would make things far easier. Although I use one sector also...Combuster wrote:FAT has been historically tried and tested to make half a sector be enough for loading further sectors by filename.
-
- Member
- Posts: 5588
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How do I createa bootable floppy disk?
It's much easier to debug and improve your second stage when you just have to replace a file on the disk instead of directly accessing sectors.Antti wrote:I have no idea why because using those reserved sectors would make things far easier.
Re: How do I createa bootable floppy disk?
Hi,
Note that every time I press F12 (to rebuild my project), within 2 seconds I've got an "up to date" set of floppy disk images I can boot (in emulators, etc). Directly accessing sectors is not hard (and is easier and faster than diddling with files on a FAT file system, even if you do use mtools).
Cheers,
Brendan
It's much easier to use the exact same boot code for FAT12, FAT16 and FAT32, and also for the file system you implement after you realise FAT is unusable trash, and also for "boot code only" partitions and floppies that have no file system at all.Octocontrabass wrote:It's much easier to debug and improve your second stage when you just have to replace a file on the disk instead of directly accessing sectors.Antti wrote:I have no idea why because using those reserved sectors would make things far easier.
Note that every time I press F12 (to rebuild my project), within 2 seconds I've got an "up to date" set of floppy disk images I can boot (in emulators, etc). Directly accessing sectors is not hard (and is easier and faster than diddling with files on a FAT file system, even if you do use mtools).
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.