Virtual floppy with preinstalled Grub (linux)

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Aurea

Virtual floppy with preinstalled Grub (linux)

Post by Aurea »

Hi !

I used to be coding my little piece of OS under windows, but now I am using Linux. Under windows, I used VFD to load a preinstalled grub image, then copied my kernel.bin to this virtual floppy and then everything was working fine. But under linux .. I have no idea how to do it.

I read some threads about how to make an iso from scratch using dd and such, I also found a page on the Wiki that explained how to use mkisofs but mkisofs can't find my grub.img when I use the -b option.. so for now, I am kinda stuck. Is there an *easy* way to just load my grub.img ( a 1.44 mb iso containing just grub), copy kernel.bin to it and then save the whole as a new iso ?

Thanks !
Midas
Member
Member
Posts: 140
Joined: Sat Jun 24, 2006 4:40 pm
Location: Falkirk, Scotland
Contact:

Re:Virtual floppy with preinstalled Grub (linux)

Post by Midas »

Em, I don't know what filesystem this image is meant to be formatted as, but it sounds like you made the image to be read in Windows - so I'm guessing it's FAT? (If not, I'm sure you can work out how to change it!)

Create directory to mount the image to

Code: Select all

mkdir /mnt/vfloppy
Mount your grub.img as a filesystem of type vfat at /mnt/vfloppy
Copy your kernel.bin to the boot directory on that floppy (might not apply to you - depends on your GRUB setup)
Unmount your grub.img from /mnt/vfloppy

Code: Select all

mount -t vfat /path/to/your/grub.img /mnt/vfloppy
cp /path/to/your/kernel.bin /mnt/vfloppy/boot/
umount /mnt/vfloppy
Should add your kernel.bin to the existing image, I think (I haven't tried it, but the theory should apply alright). If you want to add it to a fresh copy, then just copy your existing grub.img to another file and change the commands as appropriate.

If you use bochs, you can either specify this image as the source for the floppy drive, or you (theoretically, but the bochs docs recommend against it, IIRC) can mount it as above and then use that as the source.
Regards,
Angus [Óengus] 'Midas' Lepper
Aurea

Re:Virtual floppy with preinstalled Grub (linux)

Post by Aurea »

Thanks ! That seems to be working after all ^^ (I had actually tried something similar, but everytime I looked at the date of modification of grub.img, it was the same, so I had assumed that it wasn't modified...but it actually is !)

Now on with >real< OS programming problems ;p
guest

Re:Virtual floppy with preinstalled Grub (linux)

Post by guest »

If you want to install grub into a fresh image from scratch you can also try this (requires loopback kernel support, needs to be done as root):

Code: Select all

dd if=/dev/zero of=~/grubdisk.img count=2880 bs=512   # Create disk image
losetup /dev/loop1 ~/grubdisk.img      # Map image to device
mke2fs /dev/loop1            # format disk image
mount /dev/loop1 -t ext2 /boot      # mount image device on boot
mkdir /boot/grub            # install grub
cp /lib/grub/x86_64-pc/stage1 /boot/grub
cp /lib/grub/x86_64-pc/e2fs_stage1_5 /boot/grub
cp /lib/grub/x86_64-pc/stage2 /boot/grub
grub --no-floppy

>device (fd0) /dev/loop1
>geometry (fd0) 80 2 18
>root (fd0)
>setup (fd0)
>quit

umount /boot
losetup -d /dev/loop1
This is from a 64bit Gentoo box, grub source file's path may vary depending on your distro and whether it's i686/x86_64.
Post Reply