extipl.txt for FreeBSD/Linux

			 June 16, 1999

			takamiti@tsden.org
			 extipl@tsden.org
		http://www.tsden.org/takamiti/extipl/
(translated into English by Ryutaroh Matsumoto <ryutaroh@tsden.org>)

==============================================================================

1. Introduction

Extended-IPL is an OS boot selector, which has following nice features:

	(1) You can boot OS in 2nd, 3rd and 4th hard disk if these disks
	    can be read through BIOS and target OS support it. *BSD 
	    and Linux are known to boot from second or later HD.
        (2) You can boot OS in an extended partition (partition ID
            0x05 or 0x85).
	(3) You can boot OS whose partition isn't marked bootable (active).
	(4) You can mark a partition bootable with Extended-IPL.
	(5) You can select and boot OS without installing Extended-IPL to HD.
	(6) Extended-IPL is upper compatible with original IBM IPL.
        (7) Extended-IPL can coexist with the password of DR-DOS.

Extended-IPL resides in first 512 bytes of HD and does not use any
other space. Thus its operation does not depend any OS. Once you
installed it, you can continue to use it even after you delete all OS
partition and repartition your HD. You do not have to reinstall
Extended-IPL unless first 512 bytes of HD is destroyed for some
reason.

1.2 The Limitations of Extended-IPL

o Extended-IPL cannot boot OS in a partition that cannot be accessed through
  BIOS.
o Extended-IPL merely load the first sector of a selected partition and
  execute it. Booting from the second harddisk or an extended partition
  depends on the function of the first sector, which is a part of the OS
  installed in the partition.

1.3 Copyright, etc.

Copyright (C) 1991-1999 Takamiti Kimura. All rights reserved.

Redistribution and use with or without modification are permitted provided
that the following conditions are met:

 1. One of the following (1-a,1-b,1-c)

   1-a. Source distribution have all information in the original distribution.
   1-b. Binary distribution have the complete corresponding machine-readable
        source code to build up the working version of the software.
   1-c. Binary distribution have the written offer, valid for at least one
        year, to give any third party, for a charge no more than your
        cost of physically performing source distribution, a complete
        machine-readable copy of the corresponding source code, to build up
        the working version of the software.

 2. Modifications are documented.
 3. The copyright notice and this list of conditions are maintained.

 Note: 
    I (the author of this software) recommend that you (the user) make
    the executable binary from the source code using your own system.

    Also, I welcome the improvement of the code from you, and I hope 
    that you will create the better IPL code by yourself using 
    the sample code in the original archive of this software.

1.4 Warranties

THIS SOFTWARE IS PROVIDED BY TAKAMITI KIMURA ``AS IS'' AND ANY
EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL TAKAMITI KIMURA OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

1.5 Support

Enhancements and bug fixes of Extended-IPL will be distributed at
http://www.tsden.org/takamiti/extipl/. If you have comments, bug reports,
etc., feel free to email them to extipl@tsden.org. Although we do not make
any guarantees, we will make the best effort to response your report.

1.6 Technical information

If you have interest in internal structure of Extended-IPL or IPL in
general, refer to develop.txt included in this package.

2. Before Installation

First 512 bytes of HD is called Master Boot Record, abbreviated as MBR.
MBR has three parts. Please remember the role and structure of MBR to
understand Extended-IPL function.

First 446 bytes is program code. It load first 512 bytes of booting partition
and execute it. Program code in booting partition (not MBR) does OS specific
task to boot its OS. This part in MBR is the only part in HD changed by
Extended-IPL installation.

Next 64 bytes is partition table. 4 entries are in it. Each entry has
information of whether its partition is bootable or not, starting sector
and number of sectors of partition, OS identification number, etc.
Partition marked bootable is also called "active partition" in fdisk program
in MS-DOS and Windows95.

Last 2 bytes is always 0xaa55. If last 2 bytes is not 0xaa55, MBR is 
considered invalid.

Extended-IPL installation replace MBR with its own. It is safe to back
up MBR. First find the filename of your first harddisk.
To back up MBR with extipl.exe, do "extipl save filename-of-harddisk".
Now current MBR is saved "./master.ipl". If you want to restore MBR to
backed up one, do "extipl restore filename-of-harddisk master.ipl".

2.2 Filename of Devices.
In order to install Extended-IPL, you have to specify the filename of
the (first) harddisk (or the floppy disk). The common case is as
follows.

   * FreeBSD :		2.2.x	3.x
	IDE  HDD #0 -    wd0	wd0
	SCSI HDD #0 -    sd0	da0
	Floppy   #0 -    fd0	fd0

   * Linux :	    	2.0.x
	IDE  HDD #0 -    hda
	SCSI HDD #0 -    sda
	Floppy   #0 -    fd0


3. Installation
You might hesitate to rewrite MBR of HD. You can try Extended-IPL
without making any change to your HD. Extended-IPL can be installed in
a floppy disk. If you want to install Extended-IPL to HD now, go to 3.2.

3.1 Using Extended-IPL on floppy disk
To install Extended-IPL on a floppy, insert formatted disk to A: and type
	extipl fdtest filename-of-floppy-drive.
Then Extended-IPL will be installed to floppy.

Let's use Extended-IPL on floppy. Make sure that floppy drive is tried
for booting before hard disk. Otherwise you cannot boot from floppy
disk.

Insert the floppy disk and reboot your computer. You should see your computer
boot as usual. Extended-IPL boot OS as original MBR does unless shift key is
pressed down.

Reboot your computer and see when floppy disk is accessed for booting.
Push down shift key when floppy drive starts reading.  Then partition
information and prompt "Boot#0:0.?" is displayed. In this prompt, the
first 0 stands for hard disk unit 0 (first HD), the second 0 does the
depth of the selected partition table, and ? stands for the partition
selected for booting.  You can select booting partition by typing
1--4. Hitting enter key boots OS in selected partition. A more detailed
usage is given below.

3.2 Installing Extended-IPL onto hard disk
Booting from floppy is inconvenient. You may want to install Extended-IPL
to HD once you convince that it is safe.

To install it to HD, type
	extipl install filename-of-hard-disk
Then you are asked to what file MBR is backed up. After backing up, you asked
for final confirmation. Hitting `y' key allows Extended-IPL replace MBR
with its own. If you want to stop installation, type Control-C.

You must login as root to do the installation.

3.3 Booting with Extended-IPL
Extended-IPL exactly do same thing as original MBR does unless shift key is
pressed down, i.e. it boot OS in the partition marked bootable. To select
booting OS, press down shift key when booting. Then Extended-IPL displays
contents of partition table and wait for your instruction. Below is an
example.

	-------------------
	Part  Sys
	 1    s01		;; partition NO. and partition ID (DOS)
	 2    sA5		;; FreeBSD
	 3    s05		;; (MS-DOS) extended partition
	 4			;; empty partition
	Boot #0:0.2		;; prompt
	-------------------
	      | | |
	      | | +---- partition NO.
              | +----- the depth of the partition table
	      +------ HD unit NO.

Partition ID below "System" depends on what OS you install in HD. First
selected partition is the partition marked bootable.

In this step you can select booting partition by number 1--4 and hitting enter
key starts booting. If you try to boot empty partition (4 in this case),
you here beep sound and booting does not start. Booting also does not start
if selected partition does not have 0xaa55 in 511th byte, which indicates
it is a valid partition.

Some OS does not boot if its partition is not marked bootable. Extended-IPL can
mark selected partition bootable before booting. It can be done hitting
end key instead of enter key. Extended-IPL has 2 kinds of booting key.
They are

	<Enter>	boot OS in selected partition.
	<End>	mark selected partition bootable and boot OS in it. If you
		do not press shift key in next booting, this partition is
		booted. Extended-IPL can mark partitions bootable only in
		first HD. You cannot mark partitions in second or later
		HD bootable, or an extended partition.

3.4 Booting OS in second or later hard disk
Booting OS in non-first HD is not official function of PC/AT compatible
computers. Thus not all OS can boot from second or later HD.

In stage of partition selecting, you can select them by inputting number
1 to 4. You can switch target HD by inputting 0. If you input 0, Extended-IPL
displays contents of partition table of next HD. You can do same thing with
currently selected HD as first HD except end key. You cannot mark partitions
in second or later HD bootable by end key. When you see the contents of
partition table of second HD and hit 0, you will see that of third HD if
you have it. Otherwise you will return to first HD.

3.5 Booting from an extended parition

If you choose partition 3 in the example in 3.3, extipl shows the
partition table in the extended parition 3. Below is an example

	-------------------
	 Part  Sys
	  1    s83		;; partition no. and system ID
	  2    s05		;;
	  3
	  4
	 Boot #0:1.1		;; prompt
	-------------------

In this example, the first partition in the extended partition is a
Linux partition, and the second is an extended partition in the
extended parition. If you select 1, you boot Linux. If you select 2,
you enter the extended partition. In order to return to the primary
partition, select 0 (switching hard drive) several times.

3.6 Tricky use of Extended-IPL
If there are no partitions marked bootable, Extended-IPL enters
partition selection even if shift key is not pressed. If you want not
to press shift key, you can exploit this feature. You can mark all
partition not bootable by "extipl clrboot" command. If BIOS loader of
MBR checks the validity of MBR strictly, it consider the MBR invalid
and YOU BECOME UNABLE TO BOOT ANY OS IN YOUR HARDDISK. BE CAREFUL.

4. Command Reference

In this chapter command reference of extipl is given. Parameters in []
are optional.

(1) extipl save filename-of-HD [file]
	Current content of MBR in HD is backed up in
	"file." 
	Content of MBR can be restored by "extipl restore" described
	below. If filename is omitted, default value "master.ipl" is
	used. Back up file is made read-only.
(2) extipl fdtest filename-of-FD
	Install Extended-IPL to floppy disk "filename-of-FD." You cannot
	use Extended-IPL installed floppy for any other purpose.
(3) extipl install filename-of-HD
	Install Extended-IPL to "filename-of-HD." Before installation,
	you are forced to back up MBR to some file. You are asked the
	filename as
		Enter file name to save:
	If you only hit enter, MBR is saved in "fdiskipl.001". Back up
	file is made read-only.
(4) extipl restore filename-of-HD file
	MBR contains partition information and OS booter. You are asked 
	as:

	C)ode:  restore ipl code only
	T)able: restore partition table only
	A)ll:   restore ipl code and partition table
	restore (c/t/a)? 

	Reply 'c', 't', or 'a'.  It is not examined whether specified
	file is valid copy of MBR. Filename cannot be omitted.

(5) extipl show device-name
	Display the content of the partition tables in
	"device-name". The content of an extended partition is also
	displayed.
	[Example]
	    # extipl show wd0
	    =========
	    Partition TABLE on "/dev/wd0"
	    =========
	     [1] 06: FAT16 (>32MB)
	    A[2] A5: FreeBSD/NetBSD/386BSD
	     [3] 05: Extended DOS
	        --> [1] 83: Linux native
	        --> [2] 05: Extended DOS
	            --> [1] 82: Linux swap
	     [4]

(6) extipl chgboot device-name
	Change the bootable partition in the specified device interactively.
	If you mark an extended partition bootable, you can also mark
	a partition in the bootable extended partition bootable. The
	follwing keys are understood:
		1 .. 4	  : mark the selected partition bootable.
		     w	  : write back the modified parition table to
			    the device.
		     q	  : quit without any modification to the device
		     c    : clear the bootable mark.
		     b    : back to the parent partition when you are
		            in an extended partition. If you are in
			    the top level partition, quit without any
			    modification.
	[Example]
	    # extipl chgboot wd0
	    =========
	    Partition TABLE on "/dev/wd0"
	    =========
	     [1] 06: FAT16 (>32MB)
	    A[2] A5: FreeBSD/NetBSD/386BSD
	     [3] 05: Extended DOS
	     [4]
	    >>> Select partition to make bootable (? for help): 3
	    Partition #3(Extended DOS) specified, Can you make bootable(y/n)? y

	    =========
	    Partition TABLE on "/dev/wd0"
	    =========
	     [1] 06: FAT16 (>32MB)
	     [2] A5: FreeBSD/NetBSD/386BSD
	    A[3] 05: Extended DOS
	        --> [1] 83: Linux native
	        --> [2] 05: Extended DOS
	     [4]
	    >>> Select partition to make bootable (? for help): 1

	    =========
	    Partition TABLE on "/dev/wd0"
	    =========
	     [1] 06: FAT16 (>32MB)
	     [2] A5: FreeBSD/NetBSD/386BSD
	    A[3] 05: Extended DOS
	        -->A[1] 83: Linux native
	        --> [2] 05: Extended DOS
	     [4]
	    >>> Select partition to make bootable (? for help): w

	In this example, we set the Linux native partition in the
	extended partition bootable. First, we set the extended
	partition in the top level partition bootable. Since the
	specification does not allow us boot from an extended
	partition, Extended-IPL ask user's confirmation. Then we set
	the Linux partition bootable. Finally we write back the
	modification to the device by `w' command. If you want to
	verify your modification, use "extipl show device-name".

(7) extipl clrboot device-name
	marks all partition in "filename-of-HD" not bootable. This force
	Extended-IPL to enter partition selection even if shift key is
	not pressed down.  Original booter in MBR cannot boot OS if
	all partition is marked non-bootable. You have to use
	Extended-IPL to boot something. If BIOS loader of MBR checks
	the validity of MBR strictly, it consider the MBR invalid
	and YOU BECOME UNABLE TO BOOT ANY OS IN YOUR HARDDISK. BE CAREFUL.

5 Error messages

Extended-IPL display an error message stop processing only if DISK BIOS
returns an error. Error messages of Extended-IPL are "?" followed by
hexadecimal number of BIOS error code. In tight 446 bytes of program space
allowed to Extended-IPL, returning descriptive error message is impossible.
BIOS error codes are defined as follows.

	0x01 Bad command
	0x02 Bad address mark detected
	0x04 Record not found
	0x05 reset fail
	0x07 Cannot drive initialize
	0x09 DMA boundary error
	0x0B Bad track flag detected
	0x10 Uncorrectable ECC error
	0x11 Correctable ECC error
	0x20 Bad controller
	0x40 Seek error
	0x80 Time out
	0xBB Undefined error
	0xFF Sense operation fail

