Subject: netbsd coexistence with other operating systems + solutions
To: None <tech-install@NetBSD.ORG>
From: Bernd Wiserner <wiserner@atbayer2.informatik.tu-muenchen.de>
List: tech-install
Date: 04/24/1995 21:05:30
Hi,

looking through the messages in the past few month, I observed that some
users are having trouble getting NetBSD on their disks. Some of theese 
problems have something to do with the partitioning scheme the bios 
wants to use , some have to do with the intriaces of disklabel and 
some with both.
I wanted to present some short description of problems I have seen 
so far and ( hopefully ) some solutions.

Problem I. Geometry translation.
	This is by far the most encountered problem. 
Problem description :
	The bios 'sees' another geometry as the one entered in the BIOS 
	( when using IDE disks ) or another geometry as the NetBSD
	inquiry ( when using IDE or SCSI disks )
	This problem is only relevant if all of the following apply :
		- The disk involved is the disk from which you want to boot
		- The disk is shared with another operating system OR NetBSD
		  is installed on a starting sector != 0 because of some 
		  other reason
		- The user supplied a wrong geometry.
	This shows that the problem is only relevant when NetBSD shares a disk
	with something (tm) else or is not installed at the beginning of the disk.
Solution:
	The solution suggested by the instalation notes is correct but the number
	of problems shows that it is too complicated for some people.
	Because of this I would suggest doing the following: 
	Follow the actual install notes to the point :
	"Install the other operating system first" ( Dos or whatever ).
	Most other operating systems have methods of figuring out the BIOS 
	translated geometry ( also known as the bios apparent geometry ). 
	( At least Dos, OS/2, SCO and other commercial things. ). Theese operating
	systems allways end their partitions on a cylinder boundary!( Calculated 
	in bios translated geometry ). Because of this fact we can calculate the bios
	geometry from the data we get from this partitions. 
	E.g. if Dos has made a partition which looks like :
	sysid 6 (Primary 'big' DOS (> 32MB))
    start 32, size 407520 (198 MB), flag 80
		beg: cylinder    0, head   1, sector  1
		end: cylinder  198, head  63, sector 32
		                          ^^         ^^
	we can extract the marked data and know for sure that this disk uses a 
	geometry of 64 heads X 32 sectors/track ( Heads are counted starting from  0,
	sectors from 1 ). From the NetBSD size inquiry we know the size of the disk 
	and voila' we have a complete geometry set.
	E.g.: sd0 at scsibus0: 1001MB, 2570 cyl, 14 head, 57 sec, 512 bytes/sec
	so the number of cyls computes to 2570*14*57/(64*32). 
	This rule apply to all configurations I have seen till now.
	So the solution is to specify in the installation notes :
	"Install operating system xyz BEFORE you install NetBSD OR create a dummy
	Dos partition if the installation of operating system is too timeconsuming".
	"Aftaerwards run the NetBSD install. Please use the native fdisk from 
	operating system xyz".
	Doing so we have a chance to determine the geometry from the fdisk tables we 
	find on the disk.
	I will present a solution how we can use this information in an easy fashion 
	later in this mail. ( changed fdisk )
	Alternatively we could use the information figured out by the bootblocks. 
	( They know about the geometry of any disk. ) But this shows up to not be so
	simple as it looks at the first moment, because there is no good algoritm 
	to assign e.g. the first bios wisible disk to a netbsd disk if the user has 
	more than one disk controller ( e.g. IDE + SCSI ).

Problem II. 'Sector 0 as start offset'
	I have seen this problem arising about 4-5 times in the last few month.
Problem description:
	Some users try to put NetBSD at the beginning of the disk ( startoffset 0 ).
	This makes it possible to boot NetBSD but makes it impossible to boot
	other operating systems because the netbsd bootblocks can boot ONLY NetBSD
	and they are used as master bootblock if netbsd is at offset 0. 
	It makes it also impossible to install bootselectors like os-bs because
	they would overwrite the first 512 bytes of the NetBSD bootblocks so
	the other operating systems would become bootable but NetBSD would loose.
Solution:
	The installation procedure should warn the user if :
		- startoffset = 0 AND
		- NetBSD is not the only operating system the user wants to install.
		  ( on that disk ).
	The install procedure should offer to install with a startoffset of one 
	cylinder.( Or at least one head ).	However I would consider it better if
	NetBSD would be installed with ending AND starting on a cylinder boundary,
	this saves lots of troubles in a biosified world .
	The solution presented later (changed fdisk ) also solves this problem.

Problem III. disklabel.
	This problem also appears quite often .
Problem description:
	Some people try to create 'fancy' disklabels, usually trashing at least
	one operating system on disk. 
	Some examples causing truble are :
		- partition c doesn't start and/or end where fdisk partition for NetBSD 
		  starts/ends
		- partitions c/d are not marked as unused but as 4.2BSD,MSDOS or somesuch.
		- partition a doesn't start where the fdisk entry starts.
	All of theese cause more or less strange situations, usually resulting in a
	frustrated user.
Solution :
	disklabel should let the user doing whatever he wants but should at least
	warn him about what MIGHT be wrong. The message 'overwrite disk with ....'
	isn't enough because it doesn't tell the user what he has done wrong.
	This is quite easily to accomplish by making a few checks in the disklabel 
	program.

Solution to Problems I + II.
	The solution to theese problems might be to use the NetBSD fdisk program
	during the installation phase. I think it is a good thing because we would
	not rely on the fact that the user has dos ( for pfdisk ) and we could
	warn the user if he is doing something wrong.
	If we want to use fdisk during the installation, it needs to be modified
	to be usable in some kind of 'batch' mode to query some information and/or
	to create/delete modify partitions.
	I have already done some of the modifications needed for this. Among others
	I have extended fdisk to accept a -b ( batch flag ) to report its output in 
	a '/bin/sh' readble form.
	It now accepts additional paramters to find out the following things :
		Is there a partition with a sysid of xyz ( for finding out if there is 
		  a NetBSD partition on that disk.
		Guess geometry using the method described at problem I.
		Find the maximum free slice on the disk and report size,offset.
	It also accepts paramters to set the geometry which will be used and paramters to
	create/modify/delete partitions. 
	The last modification is a kind of simple flag saying : Create a netbsd partition
	with xyz Megabytes ( fdisk -C 200 /dev/somedisk ).
	What is on the TODO list is checking of the sector - 0 problems described above
	and some ther consistency checking. However if someone has waded trough all this 
	and wants to beta test it , just mail me. I have compiled it on a not verry current
	-current ( End march ... )

B.Wiserner

P.S: Here are the new options of fdisk as far as I implemeted them :
usage: fdisk [-options] [device]
             -[0-3]: work on partition number x 
             -a    : set active partition
             -b    : batch-mode, make program unverbose 
             -i    : initialize partition table 
             -c x  : Set # of cylinders of disk to x
             -h x  : Set # of heads of disk to x
             -s x  : Set # of sectors/track of disk to x
             -m x,y: Set start of partition to x and end of partition to y
             -t x  : Set type of partition to x (NetBSD = 165)
             -f    : Report max free slice in MB's 
             -g    : Guess translated geometry of disk 
             -q id : query if id is present in partition table
             -u    : update partition table interactively
             -C x  : Create NetBSD partition with a size of x MB's