Page 1 of 2

Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 1:17 pm
by ThisMayWork
I have created a floppy image using dd which has my bootloader on the first sector. Now I need to copy my kernel to the next one but I cannot mount it on OSX (it complains about not recognising the filesystem). Is there any other way to copy it? Thanks in advance! :)

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 1:32 pm
by bwat
ThisMayWork wrote:I have created a floppy image using dd which has my bootloader on the first sector. Now I need to copy my kernel to the next one but I cannot mount it on OSX (it complains about not recognising the filesystem). Is there any other way to copy it? Thanks in advance! :)
Can't you copy it to the second sector (or whatever sector your bootloader expects it to be at)?

If you were on linux and your bootloader binary was called "mbr" and the kernel binary was called "system" and the bootloader wanted the kernel at sector number 2, then you would do the following:

Code: Select all

	dd if=mbr of=/dev/sdb seek=0 conv=sync
	dd if=system of=/dev/sdb seek=1 conv=sync
Actually in the above it isn't the floppy but a harddisk (/dev/sdb). Obviously you would change that.

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 1:35 pm
by ThisMayWork
I thought of that but my kernel is not 512B in size (the size of the sector). Will this work as expected?

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 1:40 pm
by bwat
It'll copy however many sectors it needs to.

Here is a tiny kernel which has a build system that installs the system onto a harddisk just like you want to on a floppy. Check out the "build.x86" directory and look at the "Makefile", especially the target "harddisk". Look at the last section of the README file in the top level directory for a wee bit more info on how the disk is prepared.

EDIT: Make sure the conv=sync option is given (linux) or conv=osync (BSD) - I don't know what it is on OSX. If you don't have this set you can get problems with your last sector.

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 1:48 pm
by ThisMayWork
This is actually very helpful! However, objcopy is not available for OSX and there doesn't seem to be any decent alternative. Will there be any difference if I just link it as .bin instead of .elf? ELF is flat, right?

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 1:50 pm
by bwat
PM me with your email address and I'll send you the source code for a wee tool which will flatten an ELF so you can just copy it with dd.

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 5:05 pm
by alexfru
ThisMayWork wrote:...
That's a rather large sig!

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 8:08 pm
by Brendan
Hi,
ThisMayWork wrote:I thought of that but my kernel is not 512B in size (the size of the sector). Will this work as expected?

Code: Select all

void foo()
{
}
NOT

Code: Select all

void foo() {
}
Neither of these function actually do anything; so your question (whether they work as expected) doesn't really make any sense.


Cheers,

Brendan

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 8:40 pm
by linguofreak
Brendan wrote: Neither of these function actually do anything; so your question (whether they work as expected) doesn't really make any sense.


Cheers,

Brendan
That's his sig, not code that he's asking about.

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat Mar 22, 2014 9:35 pm
by Brendan
Hi,
linguofreak wrote:
Brendan wrote: Neither of these function actually do anything; so your question (whether they work as expected) doesn't really make any sense.
That's his sig, not code that he's asking about.
I never would've noticed - perhaps his signature should be larger so it stands out more, and his post/s smaller to avoid distracting people... :roll:


Cheers,

Brendan

Kernel compiled, everything linked. Floppy?!

Posted: Sat May 10, 2014 8:14 am
by ThisMayWork
Hello! I am fairly new to OS development and I have successfully managed to compile my *tiny* kernel, assemble my *tiny* bootloader and link everything together in one file called os-image. Now how do I create a floppy and copy that image to it so Virtual PC will boot it? I am running OSX...

EDIT: I managed to create a floppy image using hdiutil, Apple's image tool. However, it contains no file system (that is exactly what I want, as my bootloader using no file system, only jumps to the correct sector and loads the whole floppy after that to memory). However, since it has no filesystem, OSX refuse to mount it so I have no way of copying my os-image to it.

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat May 10, 2014 9:34 am
by sortie
ThisMayWork: I took the liberty of merging your new topic into the old topic as they seem to be a continuation of each other.

Re: Copying kernel to a floppy without a filesystem?

Posted: Sat May 10, 2014 9:38 am
by Bender
You can use HxD to copy the sectors, and regardless if it's a floppy with a filesystem, QEMU (or any other sane emulator) should be able to boot it.
I highly recommend to use a well-known filesystem (extN/FATXX etc.) because your kernel will soon turn big enough.

Re: Copying kernel to a floppy without a filesystem?

Posted: Tue May 13, 2014 1:22 pm
by max
ThisMayWork wrote:This is actually very helpful! However, objcopy is not available for OSX and there doesn't seem to be any decent alternative. Will there be any difference if I just link it as .bin instead of .elf? ELF is flat, right?
You can install binutils via brew or port :)

Re: Copying kernel to a floppy without a filesystem?

Posted: Wed May 14, 2014 3:08 am
by bluemoon
max wrote:
ThisMayWork wrote:This is actually very helpful! However, objcopy is not available for OSX and there doesn't seem to be any decent alternative. Will there be any difference if I just link it as .bin instead of .elf? ELF is flat, right?
You can install binutils via brew or port :)
Build a cross compiler, the toolchain comes with objcopy. This is (still?) the recommended option in this forum.
Search the wiki for detail.