This is (yet another) Linux boot loader. My main goal was to have a boot
loader that didn't needed reinstallation every time I change the boot image.
This goal is achieved. This code is in "very early alpha" stage -- I have
tested it only on 3 systems. I hope it'll work for you and you'd like it as
I do.


This package is free software copyright Rafal Pietrak, it can be distributed
under GNU General Public Licence.


The package contain:

README			- this file
Makefile		- with ib, boothd and bootfd targets
ext2boot0.S		- as86 source of bootsector for floppy or ext2 active
			  disk partition.
ext2boot1.S		- as86 source of code for ext2 directory processing
			  and BOOTENV buildup.
ext2boot.h		- include file with ext2 filesystem dependant
			  constants.independent
fsboot.h		- include file with filesystem independant constants
			  and defines.
setup.S			- a modified version of a setup code from
			  /src/linux/boot/setup.S
setup.diff		- a context diff of both these setup.S sources.
ib.c			- boot install program. It's used only to write inode
			  number of the "boot[fh]d" file into the "boot[fh]d"
			  file.
boot.help		- a sample boot help file.


This boot loader (while booting a hard disk) REQUIRES that some external boot
code is installed in your Master Boot Record. The only requirement concerning
this MBR is that it have to passes control to this boot loader with DS:SI
pointing to *current* (that is: currently booting) partition. MS-DOS and
NextStep MBF work with this booter.



What this package does:

0) this boot loader loads kernel from SECOND EXTENDED FILESYSTEM.
1) you can provide this boot code with a pathname to your kernel executable
   AT THE BOOT TIME -- this means that you can have as many kernel images as
   your root filesystem can hold.
2) symbolic links are supported.
3) boot code boots GNU-C executable, so you just copy your
   /src/linux/zBoot/zSystem in some convenient place (like /linux_kernel) and
   that's it. No need to "build image".
4) you can lookup root filesystem directories before selecting the kernel to
   load by typing "boot: ? directoryname".
5) you can type kernel and init options after the boot prompt.  (at 'boot:'
   prompt options *have* to be proceeded by a dash sign to distinguish them
   from kernel filename). The dash sign is removed when the option is passed
   to kernel.
6) you can write down kernel options into a plain text file (/etc/boot.conf)
   which is read at boot time. Options don't have to be proceeded by dash sign
   in this configuration file but kernel image have to be defined as
   environment value BOOTIMAGE (i.e. BOOTIMAGE=/unix/kernel/linux.24)
7) booting from floppies is also supported, although you have to use different
   bootcode (bootfd instead boothd). Don't use kernels above 1.1.22 with
   RAMDISK, though (I don't know what, but something doesn't work there).
8) boot code recognizes 'svga=' environmental variable and sets svga mode
   according to its numerical value. Thus you can store this value in
   configuration file.
9) boot code recognizes 'ramdisk=' whith numerical value of ramdisk size in
   kbytes (this should probably be done by start_kernel() instead), so you can
   request a ramdisk at the "boot: " prompt.
10) bootloader tries to detect your disk configuration. CMOS data is used to
   determine whether you boot from hda or sda device. The choice can be changed
   to hda vs. xda by compilation constant.
11) configuration file can be selected at the "boot:" prompt. It is also
   looked up by its pathname.


What it doesn't:

0) this boot loader DOES NOT WRITE anything anywhere during the boot process,
   so the chance that it damages anything is minimal. (Of course a piece of
   code it brings into the memory believing it's a kernel image may still do
   some harm, but...)
1) YOU CANNOT use this code as Master Boot Record for your hard disk.
2) you cannot boot from any other hard disk but C: (BIOS 0x80) or any other
   floppy but A: (BIOS 0x00).
3) traditional kernel parameter area in bootsector (offset 498 and above) is
   now overwritten by bootcode, I can't help that -- there is not enough room
   in the bootsector for everything.



QUICK START:

1) **IMPORTANT** you have to have some alternative means to boot your system
   if you're going to install this boot loader into your hard disk. You may
   try this code on a floppy first, though.

2a) hard disk installation:
	install# cp /src/linux/zBoot/zSystem /linux_kernel
	install# make w2

2b) bootable floppy preparation (1.44M floppy is a must):
	install# make
	install# mke2fs /dev/fd0 1440
	install# mount -t ext2 /dev/fd0 /mnt
	install# (cd /mnt; mkdir bin dev etc lib proc mnt \
	> tmp usr)
	install# (cd /mnt; ln -s bin sbin)
	install# cp bootfd /mnt
	install# ib /mnt/bootfd
	install# dd if=/mnt/bootfd of=/dev/fd0 bs=1k count=1
    now copy all necessary files:
	install# cp /src/linux/zBoot/zSystem /mnt/linux_kernel
	install# (cd /sbin; cp init getty update /mnt/bin)
	install# (cd /bin; cp sh login ls /mnt/bin)
	install# (cd /lib; cp lib.so.4 ld.so /mnt/lib)
	install# (cd /etc; cp reboot /mnt/bin)
    you may need to modify some of the following files after you copy them.
	install# (cd /etc; cp passwd shadow group fstab \
	> inittab rc* /mnt/etc)
    on some systems booting such floppy may be particularly slow (one control
    dot a second), sometimes fdformating the diskette helps (sometimes it
    doesn't ;-) this is because the boot loader reads only two sectors at
    a time.

3) Now you can reboot your system




FLOPPY BOOT PROCESS:

1) boot sector (sector 1, head 0, cylinder 0) of your floppy boot device (A:
   or in other words /dev/fd0) is read into RAM at address 0x7C00 and a jump
   is done there (I tried not to assume whether this jump is 7C00:0 or 0:7C0).
2) boot code determines floppy parameters and initializes its environment to
   allow for translation of linear logical block number into the BIOS
   acceptable register values. Disk blocks are assumed to be 1k (2 sectors)
   long, although buffers are reserved for blocks up to 8k long.
3) disk block nr.1 (the superblock; block numbering start with 0) is read to
   determine whether there is a second extended filesystem on the floppy.
4) if so, superblock data is read into bootcode data area (BP register points
   there during all boot process)
5) then bootfile inode is brought into the memory by get_inode procedure. This
   inode defaults to 5 (ext2 constant) but must be updated by running the 'ib'
   program on this file.
6) bootfile is brought into memory at address 9000:0 (INITSEG:0) (see FILES).
7) a far jump is done there into the loaded code at: INITSEG:200
8) bootfile code print 'boot: ' prompt and wait (with timeout) for user input.
9) configuration file (/etc/boot.conf) is read; its contents parsed and
   appended to BOOT_ENVIRONMENT.
10) any input from operator is parsed and appended that ENV.
11) certain variables are looked up (these are: BOOTFLAGS=, svga=, ramdisk=
   and eventually BOOTIMAGE=)
12) file specified in BOOTIMAGE= is loaded into memory at SYSSEG:0.
13) floppy drive motor is stopped.
14) control is passed to setup.S code.





HARD DISK BOOT PROCESS:

1) Before this code got control the Master Boot Record was read into memory
   by BIOS, it moved itself out off the way, loaded active partition boot
   sector code (this boot code) and jumped into it at address 7C00:0 with
   SI:DS pointing to current partition table entry.
2) this bootcode saves current partition data, then initializes its local
   storage to allow for referencing current partition blocks by linear logical
   block number.
3) further boot process proceeds exactly like floppy_boot_process_(3) with one
   change: wherever floppy_boot refers to disk_block this boot code references
   current_partition_block.



FILES:

/boot[hf]d		- bootfile(s)
/linux_kernel		- kernel executable
/etc/boot.conf		- boot configuration
/unix/kernel/boot.help	- text help file



BUGS:

1) One serious bug is that file loding procedure does not fill areas of
   unallocated file blocks with 0. I haven't found the causing problems,
   but it definitely violates specification. It may be wise to dd the
   kernel image into its load place.
2) parsing pathnames is badly implemented, but works. I have to rewrite 
   the code at some point.
3) If you boot from a floppy and want to save some space on it by not
   using the init/getty/login programs DON'T DO IT with linux kernels
   newer then 1.1.19 - these kernels fail the second exec in the init/main.c
   so you never get shell prompt with them.


Comments, bug reports, etc to:

		Rafal_Pietrak@camk.edu.pl
