-------------------edited 16/9/09 See
this thread for a
Grub2 floppy-------------------
-------------------edited 6/2/06 to include a reference of "Making a Grub bootable CD-Rom" off Chapter 3.4 of Grub Manual---------------
Introduction
This is a write-up outlining methods to create a generic bootable Grub floppy and CD. The floppy side has been well documented and included here for the sake of completeness. The main aim is to explain how to create a bootable Grub CD.
A simplistic explanation of how one can use Grub is explained relative to a DOS system.
A generic Grub floppp or CD is non distro-specific and its difference to those generated by other methods in a Linux is described. It can be used to boot any operating system based on a PC.
Grub is DOS like
Grub is used by over 50% of the GNU/Linux distributions. It serves mainly the Linux that incorporates it for multi-booting others systems in addition to its own master. However Grub can be used without being attached to an operating system. On its own and alone it can boot any system I know in a PC. It is therefore an ideal tool for rescuing an operating system which due to whatever reason no longer accessible by the boot loader in the MBR.
Grub working alone is just like DOS but possibly only a fraction in size. It has the same two parts; the first part is a boot code for the MBR and the second part what I would regard a “command interpretor”.
The former is like the MBR boot code MS uses on all its systems and re-installable by commands like fdisk /mbr, fixmbr and sys. It is a fact that an old DOS bootable floppy can restore the MBR for a XP.
The command interpretor in DOS is the command.com program.
The Grub’s equivalent to these two are the stage1 and stage2 files.
I use DOS to help explanation here because Grub can be loaded just like a DOS to a command prompt. One can then manually type in commands line by line for Grub to perform the various booting tasks. In GNU/Linux the commands are pre-recorded and stored in /boot/grub/menu.lst which is no different to a Batch file in DOS.
There are remarkably similarities between DOS and Grub in term of the way each is created, used manually and automated by a batch file.
To create a bootable DOS floppy one needs to boot up to DOS first, put a floppy in the drive and type " format c:/s" to transfer the booting code and the command interpretor across. If the floppy has been previously formatted then doing "sys c:" will achieve the same result.
For Grub one needs to boot to a Linux that has Grub inside. To transfer the equivalent boot code and command interpretor is to type in terminal mode
dd if=/boot/grub/stage1 of=/dev/fd0 bs=512 count=1
dd if=/boot/grub/stage2 of=/dev/fd0 bs=512 seek=1
There are literatures sourcing the stage1 and stage2 file in a different directory, which can vary between distros, but I found /boot/grub always have them.
Thereafter the Grub floppy will be able to boot to a command prompt in exactly the same way as DOS but goes on to boot any system in a PC required by the user.
Method of booting any operating system in a PC
The main attraction of using Grub is that the commands to boot any system is achieved by the same 3 lines of simple commands of specifying which partition to be booted, select chain-loading and give the green light to go ahead. The appropriate Grub commands are therefore
root (hdi,j)
chainloader +1
boot
where i = disk No. and j = partition No. (Grub counts from 0, hence hda7=(hd0,6))
On receiving the first command line Grub will report the partition type serving to confirm its content.
No response is given by Grub if the partition is bootable on receipt of the second command line. The user will be informed of any problem if the partition cannot be chain-loaded.
The target system will be booted if the third line of command is issued.
The "sole" necessary condition for Grub to chain-load a system is that the system must has its own boot code or boot loader inside the boot sector of its own partition. This is automatically arranged in the installation of any MS system, BSD and Solaris. In GNU/Linux a choice is often given by the installer to be either in the MBR or in the root partition. The two are the same if the Linux resides in hda1. If a Linux has placed its boot loader in the MBR then its boot code can be replicated in root partition, say it is the hdc39 partition, by
grub-install /dev/hdc39
or
lilo -b /dev/hdc39
depending on its boot loader being Grub or Lilo respectively.
Grub achieves its versatility mainly by the command "chainloader +1". Since being already in the PC memory Grub just "cut and paste" itself with the boot loader of the requested system to be booted. The requested system's boot loader is loaded from "+1" sector position (or from the 2nd sector onward).
Q&A
(1) I have a Linux that uses Lilo how can I make a bootable Grub floppy?
Ans - Find a Live CD that has Grub, boot it up and follow the above procedure.
(2) Which Live CD has Grub?
Ans - Recent Live CDs wanting to cramp as much as functions into a CD seem to favour Lilo and only few Live CDs use Grub. However System Rescuse CD always supports Grub so download it from this site "http://www.sysresccd.org/ " if you need a Live CD packaged with Grub.
Free download from Distrowatch.com these Live CD has Grub - Mepis, Kanotix, Knoppix, Puppy, Damn Small Linux
(3) Would it be simpler just use "grub-install /dev/fd0" to create a bootable floppy for my Linux, why do we have to bother with the above crap?
Ans - Yes one can replicate a bootable Grub floppy to boot an installed Linux but it will be distro specific and not generic to boot other systems.
(4) Can I delete my /boot/grub/menu.lst temporarily and trick Grub to produce a generic bootable floppy for all the systems?
Ans - OK smart arse. You win this time if you can make it do it.
(5) Give me straight, why Grub can boot all the systems in a PC?
Ans - In chain-loading Grub does not boot the system. It boots its boot loader. That is why any bootable system will answer its call.
To make a bootable Grub CD
I have investigated in this area because many Laptop owners need a Grub bootable CD but have no floppy drive. The procedure involved here is a bit long but it works. There may be a quicker or shorter method. I shall report it if I find one.
Basically one use a bootable Grub floppy and burn it into a CD to emulate the floppy drive. This is a standard function provided by CD burner Nero and needs no writing up by me. The problem is that Nero would not burn a CD from bootable floppy that got nothing inside. The bootable floppy described by the methods above, either using dd or grub-install commands in Linux, has the information writen natively without the need of a filing system inside. Nero would not burn it thinking there is nothing to be transferred over to the CD. If a formatted floppy is used then the formatting will be destroyed by the dd and grub-install commands. Thus the trick is to have some files inside the floppy for Nero to carry out its routine. A workable procedure is given here. (The trick is to let Grub to arrange it for you)
Preparing a bootable Grub floppy suitable for burn into a CD
(a) Boot a Linux with Grub support and log in as root or in superuser mode (su followed by the password)
(b) Format the floppy in MsDOS (or Ext2) by typing "mkmsdosfs -F32 /dev/fd0" after inserting a floppy into the drive.
(c) Create a mounting point, mount the floppy and make the necessary directories to store the files at a designated location where Grub will search for them
mkdir /mnt/fd0
mount /dev/fd0 /mnt/fd0
mkdir /mnt/fd0/boot
mkdir /mnt/fd0/boot/grub
(d) Copy all the necessary files in /boot/grub directory of the booted Linux to the mounted fd0
cd /boot/grub
tar cf - . | (cd /mnt/fd0/boot/grub; tar xf -)
(e) To remove or erase the content of /mnt/fd0/boot/grub/menu.lst. Grub will boot to Grub prompt if there is no instruction in the menu.lst or the menu.lst is empty or unavailable. If the System Rescuse CD is used its menu.lst has already been emptied.
(f) Reboot the system (I am not 100% sure if this is required by a reboot will get the files transferred properly)
(g) Reboot the Linux, again log in as root or in superuser mode, drop into command prompt and activate Grub by just type
grub
root (fd0)
setup (fd0)
Grub will search the stage1 and stage2 files in the floppy. If they exist Grub will installed them in the boot sector.
Functionally the above floppy boots other operating systems same as the one created by the two dd statements. The difference is the current floppy has a filing system inside to satisfy Nero whereas the bootable floppy above has no filing system inside and is unformatted to Nero.
Burn a bootable Grub floppy into the CD
This is fully described by this site from which I learned the special way to use Nero.
http://www.bay-wolf.com/bootcd.htm
I only describe the principle as I understand it here. The floppy is burn in a CD in a special way so that on boot up with the resulting CD it would emulate as a floppy drive "A". The drive destination has no consequence because Grub's stage1 and stage2 would have been loaded into the memory by then.
edited 6/2/06---------
Apart from the emulated mode described above the standard method of making a bootable Grub CD has recently been added to the GNU/Grub Grub Manual Chapter 3.4 in which one can use just one file stage2_eltorito from Grub to create a iso image burn into a CD. This method is very simple but require an operating Linux.
Method of using Grub in command prompt
This is the famous Grub Manual which has also been fully documented in "Linux in a nutshell" too.
http://www.gnu.org/software/grub/manual/grub.html
A few usefully commands while at Grub prompt
Geometry (hd0) - to tabulate the partition table of disk (hd0)
hide (hd0,1) or unhide (hd0,1) - to hide of unhide (hd0,1)
map (hd2) (hd0)
map (hd0) (hd2) - To swap (hd0) and (hd2) positions so that (hd2) on boot up inherits the position of (hd0), mainly used for DOS/Windows systems
configfile (hd0,1)/boot/grub/menu.lst - Boot up partition (hd0,1). This command is only good for Linux with Grub as boot loader.
The bootable Grub floppy/CD has been tried successfully on 45+ systems that I can find, including
DOS, Win3x, Win9x, Win2k, XP
FreeBSD, PCBSD, Solaris 10
About 35 Linux distributions
It goes without saying that if Grub can boot any of them manually it can mult-boot all of them in the hard disk by amending the menu.lst of any chosen Grub-supported Linux given the privilege into the MBR. I use Suse 9.1 for this purpose.