Saturday, 2 March 2013

create a vfat Grub2 boot floppy

Create a small Grub2 boot .iso using :

 grub-mkrescue --diet -o fd.iso

create some directories, names are important

mkdir -p mnt fdboot/boot /grub

mount the .iso and copy all files in /boot/grub/i386-pc into fdboot/boot /grub
Then create a fdboot/boot /grub/grub.cfg that match your need, for example :

set timeout=5
set default=0 # Set the default menu entry

menuentry "This is the floppy that will boot on first disk" {
   set root=(hd0)
   chainloader +1

If you want to create a real 1.44Mo floppy, you have to remove some file in fdboot/boot /grub.
I choose to create a 2.88Mo floppy, because VMware don't care about the size of the floppy :-)

Then cut&paste the script bellow adapt the 2880 and the -a to mach the size of your floppy and the version of your Grub2. 5760 means 2.88Mo, use 2880 for 1.44Mo floppy.

The run the scrip below. the scrip come from Robert at Re: [SOLVED] Re: Grub2 editable floppy?

# Creates a vfat editable Grub2 boot floppy  (not a read-only ISO9660 one like grub-mkrescue)
# template folder ./fdboot/boot/grub  shall contain a grub2 tree like /boot/grub
#    including a grub.cfg,  stripped down to <= 1.4MB;
#    or a tree copy from a "grub-mkrescue [--diet] -o fd.iso" iso floppy
#       (and do "cd fdboot/boot/grub; mv i386-pc/* ." ! because the boot.img+bootdisk looks there)
#       ("--diet" unfortunately disappeared in v1.99)
# Note: used with Grub2 v1.98 and v1.99; v1.99 requires the "-a" flag in "grub-setup -a ..."

# output image filename

# script

umount mnt
losetup -d /dev/loop0

dd if=/dev/zero of=$fdimg count=5760
losetup /dev/loop0 $fdimg || exit 1
fdformat /dev/loop0
mkfs.vfat /dev/loop0 || exit 1
mount /dev/loop0 mnt || exit 1

##rm fdboot/boot/grub/i386-pc/efiemu.mod grcy_* ... strip off to 1.4MB  / create by "grub-mkrescue --diet ..."
cp -a fdboot/* mnt/  || exit 1
##cp /boot/grub/grub.cfg mnt/boot/grub/

cat > mnt/boot/grub/ <<EOF
##(fd0) /dev/fd0
##(hd0) /dev/sda
##(hd1) /dev/sdb

cp /boot/grub/boot.img mnt/boot/grub/ || exit 1

grub-mkimage -o mnt/boot/grub/core.img -O i386-pc biosdisk fat part_msdos || exit 1

# --force is needed to force blocklists (for core.img) on floppy:
##grub-setup --force -d mnt/boot/grub -m mnt/boot/grub/ /dev/loop0 || exit 1

# variant with -a required for Grub2 1.99+ :
grub-setup -a --force -d mnt/boot/grub -m mnt/boot/grub/ /dev/loop0 || exit 1

umount mnt
losetup -d /dev/loop0

# copy the image to virtual machine image folder
cp -a $fdimg /hptemp/boot/

echo Grub2 VFAT editable boot floppy image $fdimg created. Done.
echo TO MOUNT: mount -o loop $fdimg mnt
echo TO WRITE TO REAL FLOPPY: cp $fdimg /dev/fd0
##cp $fdimg /dev/fd0

Good luck, thanks Robert for this script.

1 comment:

  1. This does not work with grub 2.0
    # grub-mkrescue --diet -o fd.iso
    grub-mkrescue: unrecognized option '--diet'
    # grub-mkrescue --version
    grub-mkrescue (GRUB) 2.00