From: kjb@cs.vu.nl (Kees J. Bot)
Subject: [PC,Source] Minix Boot Monitor 1.5 part 0/4
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Date: Tue, 12 Jan 1993 14:53:27 GMT

The next four articles contain the sources of the Minix Boot Monitor
version 1.5.  Short explanation: "It boots Minix from floppy or hard
disk.".  Long explanation:  The README attached below.

Version history:

  1.0 - 1.2.	Writing and debugging.

  1.3.		Released to the net in March of '92.

  1.4.		Presented to Andy in October.  It was accepted after
		some changes and simplifications and put into tools to
		replace the old build/menu complex.

  1.5.		This version is basically the same as 1.4, but it is the
		full distribution, you could say 1.4 good enough for 90%
		of the users, and 1.5 is for the 10% that need some of
		the extra features.

Naming differences between 1.4 and 1.5.
  Andy did not like the names on the utilities in the package, and I do
  not like the naming he has chosen.  Look at it as an advantage,
  because now one can keep the two packages apart.  These files/calls
  are the same:

	1.4		1.5
	bootblk		bootblock	Bootstrap code in sector 0
	monitor		boot		Monitor + Minix boot code.
	construct	installboot	Install boot code + Make image
	monhead.s	boothead.s	Low level, BIOS support
	mon1.c		boot.c		Command mode, booting other O.S.'s
	mon2.c		bootimage.c	To pull a Minix image in core
	rawfs.c		rawfs.c		Raw file system library
  /usr/include/tools.h	*.h
	construct -i	installboot -i	    Make an image
	construct -b	installboot -b	    Make a separate boot disk
	construct -d	installboot -demo   Make a demo disk
	construct -h	installboot -d	    Make a root device bootable
	(construct -m)	installboot -m	    Install a master bootstrap

Reasons for wanting this package over the 1.6.24b tools:
  - It runs under 1.5 and 1.6 (Tested to work with the K&R compiler.)
  - 14 pages of documentation.
  - Support for booting stupid bootstrap loaders as found in SysVr4 and
    (I think) Xenix.
  - The command mode assumes that you are an unfriendly user.

Both version 1.4 and 1.5 can boot a kernel in 386 mode, but the bcc
assembly for mpx386.x has not been written yet.  (The ACK assembly must
be translated).  I'm working on it.

This package can also be obtained from ftp.cs.vu.nl:kjb/monitor-1.5 if
you miss one of the postings.  There are also 16-bit binaries of the
monitor there for if you have trouble compiling them for Minix-386.
--
	                        Kees J. Bot  (kjb@cs.vu.nl)
	              Systems Programmer, Vrije Universiteit Amsterdam
_._. .._ _   ._ ._.. ___ _. __.   _ .... .   _.. ___ _ _ . _..   ._.. .. _. .


README(8)                 Minix Programmer's Manual                  README(8)


Minix Boot Monitor 1.5
     This package contains a flexible Minix bootstrap loader that may be  used
     to  boot  Minix from either floppy or hard disk.  Use it to replace build
     to make a simple boot diskette, or to dress up  a  hard  disk  root  file
     system  for  an automatic boot at power on.  The monitor mode gives you a
     powerful Bourne shell like interface to configure and boot Minix,  or  to
     boot other operating systems.

Installation
     First of all: Be Careful.  The installboot program should  normally  only
     be used on floppy devices, or on your hard disk root file system with the
     -device option.  Better make a copy of the device you are going to use it
     on.   Don't  be  alarmed  however,  unless I made a terrible mistake, the
     -device option should only write the boot block,  and  the  -boot  option
     halts  for  ten  seconds when it is about to scribble over a file system.
     Nevertheless, you should test this on a floppy first.

Where to place this package
     I suggest you make a directory '/usr/src/util' and  extract  the  package
     there.   (Next to its idiot brother in tools.)  The Makefile assumes that
     it can find the kernel and fs directories by following '..'.

Compiling
     The Makefile and the assembly files  are  written  for  the  ACK  ANSI  C
     compiler,  but  you can type 'config kr' to transform these files for the
     old ACK K&R C compiler.  Running 'config ansi'  will  retrieve  the  ANSI
     files from the directory 'ansi', removing the K&R set.  Now run 'make'.

Differences with 1.3
     Version 1.3 had a kluge that made it say 'PS0' to Minix when booting from
     a  1.44Mb  diskette.  This version needs -DMINIX15 added to CFLAGS in the
     Makefile to enable this trick, because Minix 1.6  can  now  autodetect  a
     1.44Mb floppy.

     The main difference with 1.3 is the changed menu  interface,  instead  of
     fixed  built  in  functions  for  menu items, one can now define the menu
     items dynamically.  You will have to  change  things  like  'dos()  {boot
     hd1}'  into  'dos(d,Boot  MS-DOS) {boot hd1}'.  I changed the name of the
     default function action into main, to keep 1.5 from executing 1.3 junk.

How Does it Work?
     The driving force behind the development of this package was  the  simple
     way the SunOS systems I normally work with are booted:  The ROM bootstrap
     reads and executes the boot block, the boot block reads and executes  the
     program  /boot,  and /boot reads and executes /vmunix, which contains the
     kernel.  So I decided to make something just like that with the exception
     that  /vmunix  should  of  course be named /minix.  Furthermore, I wanted
     /boot to have the functionality  that  is  normally  found  in  ROM  boot
     monitors:  Set  parameters,  select  the root device, and be able to boot
     other devices.

Replacing build
     The monitor in its most primitive mode may be used to make a simple  boot
     floppy.  This is what 'make floppy' does:

          installboot -image image kernel mm fs init

          installboot -boot /dev/fd0 bootblock boot image

     After booting, you will see a menu interface with just one choice: "Start
     Minix".   The kernel has not been loaded yet, that happens after you type
     '='.  When it asks you to insert your root floppy you can either  do  so,
     or just hit RETURN to use /dev/hd3 as root.

Make a device bootable
     Now is the right time to read the installboot(8) manual page in  the  cat
     directory.   I  will just repeat the example given there to complete this
     story.

     To make a Minix file system /dev/fd0 mounted on /mnt bootable, enter  the
     following:

          cp boot /mnt/boot

          installboot -image /mnt/minix kernel mm fs init

          installboot -device /dev/fd0 bootblock boot

I don't have those kernel binaries.
     The command demolish(8) can take an image made by build to  pieces.   Use
     'make  demolish' to make it, and read the manual page to understand why I
     can't guarantee success.

My root FS is too small
     The /boot and /minix files are dead weight on a  RAM  disk,  so  you  can
     remove them by placing this code in /etc/rc:

          case `printroot` in
          /dev/ram*) rm -rf /boot /minix
          esac

     If your root FS is too small to even contain /boot and /minix,  then  you
     can try the -boot option on installboot to make a separate boot diskette,
     or you can use the -demo option to place the  kernel  image  outside  the
     file system.

After the floppy test
     Try if you can boot a hard disk partition with the boot command from  the
     monitor  after  booting  the  floppy,  an  MS-DOS partition for instance.
     After you've seen that work, make a Minix partition bootable, and try  to
     boot  it  from  the  floppy.  You can now make the Minix partition active
     with fdisk(8).  (I've had one report on an XT whose  master  boot  record
     could  not  boot non-DOS partitions.  Installing my master boot code with
     installboot -master cured the problem.)

The Manual Pages
     I urge you to read  the  manual  pages,  this  README  describes  only  a
     fraction  of  what  the monitor can do.  Feel free to ask me questions if
     the details elude you, they may help me to improve things.

The Competition
     The advantages of the monitor over competitive boot loaders:

          The bootstrap and monitor are  wholly  contained  within  the  Minix
          partition,  the  master  bootstrap  is  not  touched.  (This package
          contains a normal master bootstrap if you lost the  original,  fdisk
          /mbr under MS-DOS 5.0 will also reinstall the master bootstrap.)

          The bootstrap is independent from the media it's on.  Bootable  file
          systems  may  be copied between floppies of a different type or hard
          disk partitions using dd(1) and they will still be bootable.

          The bootstrap is only one sector, so it can never span tracks.

          Both V1 and V2 file systems are supported under Minix 1.6.

          Kernel binaries are combined in one image for fast loading and  easy
          manipulation of different kernel versions.

          The interface is configurable at the  boot  prompt  or  by  using  a
          program  that  simulates  the  boot monitor interface.  You can have
          Minix booted in 5 seconds if no key is typed to a menu interface for
          instance.   (The menu interface looks much better than a hex dump of
          your partition table.)

          Only two files are enough on a boot device: /boot and /minix.

          The monitor can call a kernel in 386 mode.  This allows for a kernel
          that is completely compiled in 386 mode.

Copyright
     Copyright 1992 Kees J. Bot, All rights reserved.
     This package may only be used in combination with Minix.  Changes that do
     not increase the functionality or that are incompatible with the original
     may not be released to the public without  permission  from  the  author.
     Use of so called "C beautifiers" is explicitly prohibited.

Author
     Kees J. Bot (kjb@cs.vu.nl)
Newsgroups: comp.os.minix