From: julian@tfs.com (Julian Elischer)
Subject: Re: SUMMARY of answers to: "how to label partition to 386BSD?"
Summary: more on partitioning a drive
Organization: TRW Financial Systems
Distribution: comp
Date: Wed, 19 Aug 1992 00:35:46 GMT

In article <1992Aug13.231848.7930@access.usask.ca> israel@dvinci.USask.Ca (Israel Oznovich) writes:
>--------------------------------------------------------------------
>--------------------------------------------------------------------
>A few days ago I posted the following question to this newsgroup:
>"how to label a partition for 386BSD?"
>I got many responses, all of them informative and helpful;
>I also got messages urging me to summarize the answers and re-post.
>Thank you Henrik Storner, Rick J Weldon, Frank Terhaar-Yonkers,
>Brian D. Carlstrom, Spaceman Spiff, and more...
>Here goes.
>Israel.
[ lots of useful information deleted]

I have gone through a painful but rewarding week in which
I have broken and ficed just about every structure on my disk
in an attempt to have concurrent mach and 386bsd partitions.

I post here some of the highlights to save others from going through
the same "delightful' experience.


First:

Mach has an fdisk utility which beats up the DOS partition table.
I used it to change various things in the DOS boot block (block 0)
but others could use the DOS norton stuff and DOS fdisk to do the same things.
Using this utility it was possible for me to totally confuse myself because
it allowed the figures for partitions to be totally inconsistant if I type them
in that way 8-)

things to know that I discovered the hard way:

386BSD must have it's partition starting on a cylinder boundary.
This must be a REAL cylinder boundary, not a funny one as created by
block translation stuff. (see STAGE2 later)

The boot code uses the adapter's idea of the disk geometry, so
whatever you have set into the BIOS (which will be used by the BIOS
to initialise the adapter should have the right number of heads and sectors
per track. The number of cylinders is totally unimportant as long as it 
is large enough to cover your DOS partition, and the boot blocks of
any other partitions you may have.
e.g.

I have a drive of 1222 cylinders, 15 heads (1 for servo I guess) and 34 sectors
per track. I told the adapter to format with 1 slip-sector per track so I get
final figures of 1222 x 15 x 33.

If I try to use these figures, the BIOS won't work, but one of the options
I get given by the format utility is 1023 x 15 x 33. I use this as
it has enough cylinders to reach as far as my mach partition's boot blocks.
(I set my disk up with 769 xylinders for 386BSD and 453 cylinders for MACH.)

Because the 386BSD partition must start on a cylinder boundary, it starts
on block 495. (the first cylinder is effectively lost except for the BOOT BLOCK)

STAGE1:
So, the FIRST boot block (os-bs in this case) uses the BIOS to load the
first block of the 386BSD boot code.
This requires that the bytes in the BOOT BLOCK 
that give the start cylinder and sector (and head) for the partition match
the start sector number IN THE DISK GEOMETRY that you last told the BIOS.

STAGE2:
The second stage boot just loads sectors 2-16 on whatever track it is already
set up for (The reason that the BSD partition must be on a cylinder boundary).

STAGE3:
The third stage boot actually has the disklabel embedded in it and uses it
as a source of the information as to the disk geometry. It can read
the partitions where-ever they may be.

STAGE4, (THE KERNEL)
The final stage is the kernel itself. Before it can read the disklabel, it
has no idea of what the disk looks like. A catch 22 as it needs to know
the layout before it can read the disklabel if the disklabel is not
on the first cylinder. It solves this by horrible means.
What it does is to read the DOS bootblock and assume that the end of the 
BSD partition in on the last block of the last track of the last cylinder
in that partition. It then assumes uses the sector number and head number
of that last block as if they were the number of sectors and number of heads,
which allows the kernel to calculate the required cylinder number etc. for
the disklabel, which it then reads in.

SO all in all, you need 4 different sets of data to agree to get your
kernel successfully booted in 386BSD.!


MACH does the 2nd and 3rd and 4th steps differently.
They use the BIOS in all the bootstrap stages, not touching the hardware at 
all. In the kernel, they use the cylinder, head and sector numbers given
in the bootblock (sector 0) for the partition start, but add 29 to the
sector number (They do assume you have more than 30 sectors per track on the 
disk) to find the 'disklabel'.




Incidentally, I found that by extending the disklabels of mach and 386BSD
to each other's areas, I can cross mount the partitions.

(e.g. MACH can mount the BSD partitions).


+----------------------------------+       ______ _  __
|   __--_|\  Julian Elischer       |       \     U \/ / On assignment
|  /       \ julian@tfs.com        +------>x   USA    \ in a very strange
| (   OZ    ) 2118 Milvia st. Berkeley CA. \___   ___ | country !
+- X_.---._/  USA+(510) 704-3137(wk)           \_/   \\            
          v

Newsgroups: comp.unix.bsd