[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Not a bug] [From help-grub] Problems creating a boot floppy image

From: David Lindsay
Subject: Re: [Not a bug] [From help-grub] Problems creating a boot floppy image
Date: Thu, 11 Jun 2009 21:34:33 +1000

[ This has been crossposted to help-grub under the thread "Problems
creating a boot floppy image". ]

- The following information is for GRUB Legacy; in my case,
specifically version 0.97. This is because GRUB Legacy is pertinent to
a project I'm working on.
- This mailing list does not provide support for GRUB Legacy, so
please don't ask this mailing list for help with it. My email address
can be found below.

I got it to work!

Using info I found on the 'Net as well as some late-night umm-ing and
uhh-ing in bed I ironed out some misconceptions and realized how the
GRUB install process actually works - I'd had a fair bit of it wrong.

The result is the following procedure - if you execute these steps you
should end up with a bootable floppy disk with a filesystem AND GRUB
on it! This works with both ext2 and FAT!!

It's easiest to do all of the following as root, TBH.

Everything below is formatted such that it would be easy to paste it
into a script.

- Lines prefixed with !s are multiple choice questions - one needs to
have the ! removed, the other needs the ! replaced with a # to comment
it out.
- Please note step 11 - this is where you'll copy extra files to the
disk image, and is probably of interest to you.

>> Note that after step 13 the script ends.

 ---< % >---

# By David Lindsay <address@hidden>
# I wouldn't have discovered the --device-map/dev/null and "device
(hd0) /dev/loopX" tricks had I not found http://sig9.com/bochs-grub,
so I must thank "Vivek" for that vital knowledge!

# Some required info:

# Image name (include a path if you want)

# Loopback device

# Filesystem
! fs=ext2
# OR
! fs=msdos

# Image mountpoint (NEEDS TO EXIST):

# Location of stage1 and stage2

# ---

# 1. Create a floppy disk image:
! dd if=/dev/zero of=$imgname bs=1024 count=1440
# OR
! qemu-img create $imgname 1440

# 2. Setup a loopback device
losetup $loopdevice $imgname

# 3. Create a filesystem:
mkfs -V -t $fs $loopdevice

# 4. Mount it somewhere:
mount -o loop $loopdevice $mntpath

# 5. Copy stage1 and stage2 to it:
cp $stage1 $mntpath
cp $stage2 $mntpath

# 7. Unmount the image:
umount /mnt/floppy

# 8. Use the GRUB shell to work its magic on stage1 and stage2 so they boot
echo -e "device (fd0) $loopdevice\nroot (fd0)\ninstall /$(basename
$stage1) d (fd0) /$(basename $stage2)\nquit" | grub
--device-map=/dev/null --batch

# 9. Remount the image
mount -o loop $loopdevice $mntpath

# 10. Remove stage1 and stage2, which don't appear to be needed
anymore and will only consume unneccessary space on the disk - I've
personally had success removing both files under both FAT and ext2.
rm $mntpath/$(basename $stage1)
rm $mntpath/$(basename $stage2)

# 11. Copy any extra files you want to the disk at this point.
# Note: I have this step here because until step 10 you had around
100K of data on the image that would have been deleted anyway.

# 12. Unmount the image. Again. :P
umount /mnt/floppy

# 13. Finally delete the loopback device.
losetup $loopdevice -d

# ---< % >---

# Now try it out!!!

$ qemu -boot a -fda floppy.img

reply via email to

[Prev in Thread] Current Thread [Next in Thread]