Bootloading and boot floppies


It's useful to have a floppy from which you can boot your computer in case of any problems booting from the hard disk. There are different ways to produce a boot floppy. One way is to use use grub, which which is "non-automatic" so allows you significant involvement in the process and provides an opportunity to gain insight into the boot process. In linux, your first floppy disk drive is named /dev/fd0.

The exercise for you to perform:

Mimic the sessions shown in the screenshots below. The commands to execute there are distinguished by their blue color and bold style.

GRUB to make a bootable floppy that depends at boottime on a configuration file on the hard disk

Make sure the driver for the floppy drive device is loaded and available:

modprobe  floppy

Put a floppy in the drive. First format it, using linux's fdformat command. Then put an ext2 filesystem on it, using the mkfs command. GRUB can now use it, so invoke the grub command for an interactive grub session.

[root@hostz root]# fdformat /dev/fd0
Double-sided, 80 tracks, 18 sec/track. Total capacity 1440 kB.
Formatting ... done
Verifying ... done
[root@hostz root]# mkfs /dev/fd0
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
184 inodes, 1440 blocks
72 blocks (5.00%) reserved for the super user
First data block=1
1 block group
8192 blocks per group, 8192 fragments per group
184 inodes per group

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@hostz root]#
[root@hostz root]# grub


Grub gives you its own interactive shell, within which its own special command set can be used. Therein, as shown in the screenshot below, tell grub where the executable boot code and accompanying configuration file are. This is accomplished with grub's "root" command. It expresses the location in terms of a particular partition. Now, if grub is called upon to make a disk or partition bootable, it knows where to get the raw material it will write there. The "setup" command tells it to go ahead and do that, and identifies which partition or disk to do it to. The "root" and "setup" commands below say, "get code from the first partition on the first disk, and apply it to the floppy disk. Embed in that code the information that when the floppy is used to boot the computer, and will need to dynamically locate a configuration file, it should get it off  the first partition of the first disk." These provisions are for the general case where a number of different bootable partitions and config files might be present in the system. 

GNU GRUB version 0.94 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83

grub> setup (fd0)

Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (fd0)"... failed (this is not fatal)
Running "embed /grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
Running "install /grub/stage1 d (fd0) /grub/stage2 p /grub/grub.conf "... succ
eeded
Done.

grub> quit

Now examine what's on the diskette.

[root@hostz root]# mount -t ext2 /dev/fd0 /mnt/floppy/    (alternatively /media/floppy; this assumes floppy not auto-mounted)
[root@hostz root]#
[root@hostz root]# ls -l /mnt/floppy
total 12
drwx------ 2 root root 12288 Oct 14 16:35 lost+found
[root@hostz root]#
[root@hostz root]# umount /dev/fd0

Note that there is nothing on the diskette but a directory named "lost+found." This is characteristic of a freshly formatted diskette. The diskette should nonetheless be able to boot the system.

The acid test: please reboot the system from the floppy you have created. It should boot. Moreover, if you make any changes to the configuration file /boot/grub/grub.conf on the hard disk, they should be reflected in the behavior of future boots.

GRUB to make a self-contained bootable floppy that contains its own boottime configuration file

With the same floppy in the drive, we will make modifications so that the floppy will be self-contained at boottime. This amounts to migrating onto the floppy things that are on the hard disk, so that they can be sourced from the floppy instead in future boots.

 

[root@hostz root]# mount /dev/fd0 /mnt
[root@hostz root]# mkdir -p /mnt/boot/grub
[root@hostz root]# cp /usr/share/grub/i386-redhat/stage? /mnt/boot/grub
[root@hostz root]# cp /boot/grub/grub.conf /mnt/boot/grub/
[root@hostz root]# ls -l /mnt/boot/grub/
total 103
-rw------- 1 root root 559 Oct 14 17:04 grub.conf
-rw-r--r-- 1 root root 512 Oct 14 17:04 stage1
-rw-r--r-- 1 root root 101800 Oct 14 17:04 stage2
[root@hostz root]# umount /dev/fd0
[root@hostz root]# grub

Now you will again enter grub's interactive shell. There, execute the commands shown in the screenshot below.


GNU GRUB version 0.94 (640K lower / 3072K upper memory)

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename.]

grub> root (fd0)
Filesystem type is ext2fs, using whole disk

grub> setup (fd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... no
Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/grub.c
onf "... succeeded
Done.

grub> quit

This is similar to the previous case where we told grub to put stuff from the hard disk onto the floppy, except now we tell it to put stuff from the floppy onto the floppy. And in particular that on future boots it should source its configuration file from floppy (not hard) disk, for dynamic determination of boottime behavior.

The acid test: please reboot the system from the floppy you have created. If you want to prove which config file is heeded during the boot process, make a distinguishing change to one or the other (e.g., change the timeout value) and see which file "takes."