I must be getting incredibly dense. Does anyone have instructions on
how to create a Bochs floppy image with Grub in the bootloader that I
can stuff my kernel into? I've seen various sets of instructions using
Cygwin, two floppies, etc. But I was hoping to automate this build
process (which is impossible if you have to use physical floppies), and
my dev machine no longer has a floppy drive.
I tried binary overwriting a blank Bochs floppy image (created with
bximage) with a concatenated copy of stage1, stage2, and my kernel
image in a hex editor. But obviously that didn't work. Why I thought it
would, I dunno.
I'll use Cygwin if I absolutely have to. But I'd rather not. Just
trying to eliminate more unnecessary dev tools in the auto-build
process.
Ideas, comments, etc on how to do this? How does everyone else that's
developing under Windows build their boot [floppy|hd] images for Bochs?
Thanks!
--Scott
I've just two tools for this kind of thing. The first creates a FAT12
formatted floppy image with an option of putting boot sector from another
file to it (not the whole boot sector, just the code, preserving the
FAT-related details). The second uses my FAT module to "mount" a floppy/hdd
image formatted as FAT12/16/32 and write files to it using functions with an
API very similar to the standard C/Unix file/directory functions. So, having
the boot sector code in one file, the kernel files, and these two tools
alows me to create an image that can be fed into Bochs/Virtual
PC/Server/VMWare/whatever, written to the floppy as-is or used to make a
bootable CD (in floppy-emulation mode). I don't actually need to use the
floppy drive but I used to use it -- once the boot sector was written, I
could just copy over the (new) kernel files to the floppy and then boot off
it the PC or VM or take an image from it. But now that's about as simple as
it can be -- I can produce and consume the image w/o using any hardware or
tools that I don't have control of. Maybe you could also create images from
files in some simple way.
Alex
I was using WinImage to access floppy and harddisk images. Now I am
using FileDisk to write my kernel into floppy image. Since FileDisk
does not support harddisk image I am planning to shift to VDK if it
works.
-Sam
> Ideas, comments, etc on how to do this? How does everyone else that's
> developing under Windows build their boot [floppy|hd] images for Bochs?
Hi Scott,
The short answer is that you'll have to make something yourself. (Or I
suppose you could have my code if you want, but I imagine you'd rather do
it yourself?) The long answer is:
I have a FAT12 driver and a RAM floppy disk driver (because that's the
easiest disk device driver to make). To test these, I have a Windows
command-line application. The RAM disk driver opens a floppy image file as
a memory-mapped file, so changes are persisted. At the end of my build, my
makefile (actually I use VC++) uses this test application to copy my
kernel to the floppy image.
For the boot sector, the FAT12 driver exposes a "format" command that
writes a hardcoded boot sector to the first sector and initialises the
FATs. My boot sector only changes very rarely, but when it does I have to
modify the hard-coded bootsector in my format command - no big deal.
I went round and round in circles trying to find a way to have my build
script copy my kernel files to the floppy image, ready for bochs. But I
couldn't find a solution, and that's why I took the time to implement my
RAM floppy disk driver and its test harness. The problems I found with
every other tool, such as FileDisk and WinImage and so on, were that you
have to be an administrator to mount the image, and that bochs can't read
the file while it's mounted. This means that you have to mount/unmount the
file at every build, which is a pain in itself, but it also means that the
build script would have to run as an administrator, and I don't want to do
that. Not to mention that most of the tools don't expose a command-line
interface, which rules them out of a build script.
You mentioned that you're trying to avoid Cygwin. I think that's a good
idea if you're not already doing the rest of your build in Cygwin, because
starting a whole Cygwin instance just to do the file copying would be
maddeningly slow. Similarly, booting bochs off a real floppy disk is too
slow (at least with my real floppy drive and my unoptimized FAT code.)
My source code repository suggests that the elapsed time for this work was
about three weeks, although it tells me nothing about how much time I
spent on it during those three weeks. But it was worth it because now my
build is fully automated, and I have a working FAT12 driver, and I've made
a practical start on my device driver model.
Happy building!
Ciaran
--
Ciaran Keating
Amadán Technologies Pty Ltd
FileDisk supports command line. And I think, there is no support for
GUI in FileDisk. So safely you can use it in your makefile. I am using
it.
I am using WindowsXP with a single user account. That means I have
administrator rights. You can try "runas" if you are not using
administrator user while compiling. But I have not tried it yet.
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true
> FileDisk supports command line. And I think, there is no support for
> GUI in FileDisk. So safely you can use it in your makefile. I am using
> it.
Yes, that's true. I suppose I wasn't very clear - I didn't mean that every
tool I tried had every problem I mentioned, but rather that every tool had
at least one showstopper.
> I am using WindowsXP with a single user account. That means I have
> administrator rights.
I don't like my normal user account to be an administrator.
> You can try "runas" if you are not using
> administrator user while compiling. But I have not tried it yet.
Runas doesn't accept the password on the command line - you have to type
it manually. So it's not practical to use it in the build script.
Cheers,
Well, this almost works. I created the image, formatted it, and used
NTRawrite to write stage1 to the boot sector of the floppy image.
However, this then blows away the FAT, causing me to lose the ability
to copy stage2 and all the other files to the image. Besides, after all
this is done, wouldn't you have to boot GRUB in Bochs to run the GRUB
setup?
I'm trying to stay away from having to write throwaway
FAT12-in-mmap'd-Windows code for now, since I'm nowhere near the point
of writing an FS or device driver. Seems darn annoying that we all have
to jump through these hoops for this. :)
Alex or Ciaron, can you post up links to your image creators? I'd
rather not delve into Windows driver writing if I don't have to. :D
Thanks!
--Scott
It will be at the same location on my homepage some time during or shortly
after Thanksgiving. I'll announce the update.
Alex
> Well, this almost works. I created the image, formatted it, and used
> NTRawrite to write stage1 to the boot sector of the floppy image.
> However, this then blows away the FAT,
That's odd... the FATs start in the second sector, so if you're only
writing the first sector then you should be fine. I forget... maybe
rawrite writes the whole image in one go?
If this is the only problem you've got right now, then how about this:
write your own tool that takes a 512-byte boot sector file and floppy
image file, and overwrites the first 512 bytes of the image with the boot
sector? That should be trivial to implement.
> Besides, after all
> this is done, wouldn't you have to boot GRUB in Bochs to run the GRUB
> setup?
I have no idea... I couldn't figure GRUB out at all... all that business
with the multiboot header that has to go somewhere in the first xKB, and I
could never figure out how it gets found, and magic values whose meaning I
could never divine, and configuration, and blah blah blah... I just gave
up!
> I'm trying to stay away from having to write throwaway
> FAT12-in-mmap'd-Windows code for now, since I'm nowhere near the point
> of writing an FS or device driver.
Fair enough! But just so you know - FAT is very easy to implement. A few
minor gotchas, but that's all.
> Seems darn annoying that we all have
> to jump through these hoops for this. :)
Ah, but isn't that why we do this stuff? I always wondered whether those
floppy disk images were just raw data or was there some other housekeeping
stuff on the inside that I didn't know about. Now, having done my own, I
know that yes they're just plain data with nothing magic in them.
> Alex or Ciaron, can you post up links to your image creators? I'd
> rather not delve into Windows driver writing if I don't have to. :D
Well, I'm not that organised. Can I mail it to you at the address you used
to post this message? By the way, my stuff isn't a Windows device driver -
it's a device driver for my own OS, which I compile into a Windows test
harness for testing and debugging.
you can try the following
//create image using bximage tool that comes with bochs
//a.ima - temporary grub disk
//b.ima - Grub with FAT FS
bximage -fd -q -size=1.44 a.ima
bximage -fd -q -size=1.44 b.ima
//mount the images using filedisk
filedisk /mount 0 c:\test\a.ima 1.44M m:
filedisk /mount 1 c:\test\b.ima 1.44M n:
//create temp grub disk in raw format
copy /b grub\stage1+grub\stage2 grub.raw
ntrawrite -f grub.raw -d m:
//prepare the second disk with GRUB files and directory structure
format /fs:FAT n:
mkdir n:\grub
copy grub\stage1 n:\grub
copy grub\stage2 n:\grub
//copy your kernel
copy kernel.sys n:\
//all done - unmount the disks
filedisk /umount m:
filedisk /umount n:
-------------------------------------------------------------
Now modify your bochsrc file
floppya: image=a.ima, status=inserted
floppyb: image=b.ima, status=inserted
run bochs and type the following command in the grub prompt
root (fd1)
setup (fd1)
------------------------------------------------------------
You may delete the temp grub disk
del a.ima
modify your bochsrc file again
floppya: image=b.ima, status=inserted
------------------------------------------------------------
run bochs and type
kernel /kernel.sys
boot
Sam
*EXCELLENT* post Sam, IMO. Yeah, this is technically just a rehash of
the standard GRUB build-a-floppy instructions, using Bochs images. But
it works well.
As a side note, on the second boot of GRUB after running setup, b.img
needs to be in floppy a AND b, because GRUB looks for stage 2 in fd1
(drive b). My suggestion, and what works for me, is to run setup a
second time on fd0. Or just switch a.img to b.img in Bochs before you
run root and setup, and do root (fd0) and setup (fd0).
I'm not sure who runs the AOD FAQ (if one exists), but this would be a
great starter how-to.
--Scott
Might be of help !!!