Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Aug 2002 18:39:37 +0200
From:      Thomas Stratmann <strattbo@fsp1.physik.ruhr-uni-bochum.de>
To:        stable@freebsd.org
Subject:   BAD DISKLABEL - BIOS problem w/ workaround
Message-ID:  <20020828183937.A26822@fsp1.physik.ruhr-uni-bochum.de>

next in thread | raw e-mail | index | archive | help
Hi folks,

I post this to the stable list since the workaround I found for my problem
involves a bit of source hacking, so this addresses people who are a bit
fearless about that.
Before I digged into the source and started debugging I queried Google for
"BAD DISKLABEL" (see Symptom below) and got no relevant hit, so I hope
this post will appear on the search engines and maybe help people with
similar problems. It could save a lot of time! Debugging before the kernel
is nontrivial...

Symptom: /boot/loader (the bootstrap code startet by/after the code which
	prompts ">> FreeBSD/i386 BOOT" reports "BAD DISKLABEL" for my
	FreeBSD slice.
	BUT the involved slice was absolutely intact!
	(I have another bootable slice; no kernel complaints after booting
	into it, and mounting the "infected" slice partitions works as it
	should)

It took about two days of hacking to find out that:
(skip this if you need to get your bootstrap work NOW!)
* the output of "BAD DISKLABEL" is only triggered by checking for the
	magic key in the label block. But: I verified that the label block
	was in the right position and had the right magic at the right offset!
* /boot/loader tries to load the right block from disk before checking the
	magic (actually, I only went so far as to see that the code which
	prepares and runs the real-mode BIOS call uses the right cylinder/		head/sector parameters, I did not check if the registers were 
	correctly assigned. But I believe it should be VERY improbable
	to have the registers wrong, since this must be a well-known issue.
	Am I wrong here?)
* the block actually read comes from somewhere else on the disk, probably
	sector # 256, starting from 1 (I enabled hexdumping of the read
	block to find this out), but definitely not from the second sector
	from the beginning of the slice.

This all lead me to the assumption that my BIOS must be buggy. 
By the way: I have an AWARD BIOS and stable-source from two days ago.
If your symptoms are similar, the following might work out as it did for me:

FIX: Replace your BIOS with a correct one (I did not try this ;-)
WORKAROUND:
	You need another bootable system, of course!

	I feel I have to warn that the method described here is rather dirty.
	Please ensure that your "infected" slice is really OK!
	Back up /boot/loader !
	
	Edit /usr/src/sys/boot/i386/libi386/biosdisk.c :
	Look for the function "bd_read(...", and inside it, the line

		if (cyl > 1023) {

	Replace (or: duplicate;comment one out;change the other) to:

		if (1) {

	Then cd to /usr/src/sys/boot and type

		make clean all install

	or make and install your (complete) world instead.
	This will replace your /boot/loader with a version which might work
	for you. Assuming you do this from inside a system which you can
	boot into without any problems, mount the problem system and copy
	/boot/loader over. I also suggest you keep a spare copy like
	/boot/loader.LBA which does not get overwritten by make installworld.
	I also keep a copy in my linux system since I use GRUB in my boot
	sector which can access the linux filesystems.

	A few words of explanation: /boot/loader loads blocks from disk
	using cylinder/head/sector parameters for BIOS by default. Only when
	this is not possible (i.e. cyl > 1023) it uses LBA addressing, if
	available. The above "patch" makes it use LBA mode in every
	situation. The BIOS bug seems to appear in C/H/S mode only, so
	I'm fine with this.
Scope for the workaround: Your BIOS needs to support LBA mode (means it can
	theoretically boot into partitions beyond cylinder 1023), otherwise
	you're lost.
	As you can see in the paths, this applies to i386 platform.

I hope this is helpful for those who need it and not too annoying for
the rest.


Yours
Thomas Stratmann

thomas.stratmann@ruhr-uni-bochum.de

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020828183937.A26822>