Home turboPC
Python scripts Python tutorial Bouncing dice Diagram editor LRC network simulation
Qt embedded
OS Bootfloppy Go 64 bits Bochs

Creating a bootfloppy

Create an empty image the size of an 1.44 meg floppy

$ dd if=/dev/zero of=bootdisk.img bs=512 count=2880

Create a dos file system on it using mkfs.msdos (part of the dosfstools package):

$ mkfs.msdos bootdisk.img

List your files with mdir (part of the mtools package):

$ mdir -i bootdisk.img
 Volume in drive : has no label
 Volume Serial Number is D443-3665
Directory for ::/

No files
                          1 457 664 bytes free

Now create a directory using mmd:

$ mmd -i bootdisk.img boot
$ mmd -i bootdisk.img boot/grub

and copy stage1 and stage2 to the disk and configure GRUB:

$ mcopy -i bootdisk.img /usr/lib/grub/i386-pc/* ::/boot/grub

and verify the result with mdir:

$ mdir -i bootdisk.img boot/grub
 Volume in drive : has no label
 Volume Serial Number is D443-3665
Directory for ::/boot/grub

.                 2011-09-15  21:11 
..                2011-09-15  21:11 
E2FS_S~1         13728 2011-09-15  21:18  e2fs_stage1_5
FAT_ST~1         11824 2011-09-15  21:18  fat_stage1_5
FFS_ST~1         10592 2011-09-15  21:18  ffs_stage1_5
ISO966~1         10592 2011-09-15  21:18  iso9660_stage1_5
JFS_ST~1         12800 2011-09-15  21:18  jfs_stage1_5
MINIX_~1         10592 2011-09-15  21:18  minix_stage1_5
REISER~1         14624 2011-09-15  21:18  reiserfs_stage1_5
stage1             512 2011-09-15  21:18 
stage2          147440 2011-09-15  21:18 
STAGE2~1        147440 2011-09-15  21:18  stage2_eltorito
UFS2_S~1         10996 2011-09-15  21:18  ufs2_stage1_5
VSTAFS~1         10080 2011-09-15  21:18  vstafs_stage1_5
XFS_ST~1         14856 2011-09-15  21:18  xfs_stage1_5
       15 files             416 076 bytes
                          1 037 824 bytes free

enter the grub terminal by running:

$ grub
setup with grub:
grub> device (fd0) bootdisk.img
grub> root (fd0)
  Filesystem type is fat, using whole disk
grub> setup (fd0)       
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/fat_stage1_5" exists... yes
 Running "embed /boot/grub/fat_stage1_5 (fd0)"... failed (this is not fatal)
 Running "embed /boot/grub/fat_stage1_5 (fd0)"... failed (this is not fatal)
 Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.lst "..
. succeeded
Done.
grub> quit

run the system with bochs:

$ bochs -q

There is no menu.lst and no kernel image, that is later work...

Putting this all together into a bash script:

#!/bin/bash
# Creates an empty floppy with grub loader on it.

# Filename:
FLOPPYFILE=emptybootdisk.img

# Create file of 1.44M size:
dd if=/dev/zero of=$FLOPPYFILE bs=512 count=2880

# Create filesystem:
mkfs.msdos $FLOPPYFILE

# Create grub directory:
mmd -i $FLOPPYFILE grub

# Copy grub files:
mcopy -i $FLOPPYFILE /usr/lib/grub/i386-pc/* ::/grub

# Run grub commands in batch mode:
grub --batch <<THEEND
device (fd0) ${FLOPPYFILE}
root (fd0)
setup (fd0)
quit
THEEND

# List files on floppy:
mdir -i $FLOPPYFILE