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
   boot
}


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?


#!/bin/sh
# 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
fdimg=fdb.fat

# 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/device.map <<EOF
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/device.map /dev/loop0 || exit 1

# variant with -a required for Grub2 1.99+ :
grub-setup -a --force -d mnt/boot/grub -m mnt/boot/grub/device.map /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.


2 comments:

  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

    ReplyDelete
  2. Do you understand there is a 12 word sentence you can say to your partner... that will induce intense emotions of love and impulsive appeal to you buried inside his heart?

    Because deep inside these 12 words is a "secret signal" that triggers a man's instinct to love, cherish and look after you with all his heart...

    12 Words Will Fuel A Man's Desire Instinct

    This instinct is so built-in to a man's mind that it will drive him to work better than ever before to to be the best lover he can be.

    Matter of fact, triggering this influential instinct is so essential to achieving the best ever relationship with your man that as soon as you send your man one of the "Secret Signals"...

    ...You'll instantly find him expose his soul and heart for you in a way he never expressed before and he'll distinguish you as the only woman in the galaxy who has ever truly interested him.

    ReplyDelete