*BSD News Article 20038


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!uniwa!nodecg.ncc.telecomwa.oz.au!tdwyer
From: tdwyer@nodecg.ncc.telecomwa.oz.au (Terry Dwyer 4915161)
Subject: bad144 problem?
Organization: Network Computer Centre, Telecom, Perth
Date: Fri, 27 Aug 1993 06:36:26 GMT
Message-ID: <1993Aug27.063626.18664@nodecg.ncc.telecomwa.oz.au>
Keywords: how I got around it 
Lines: 192

I've been following this thread with a great deal of interest, in fact,
I posted some questions very early in the piece to c.o.3.q (I think)
because I could not install NetBSD-0.8 on a wren 94186-383H.  
Following are the drive parameters:

WREN ESDI Model No. 94186 383H
Cylinders	Heads		Sect/Track
1224		15		35 (*)

ESDI controller wd1007V

The number of formatting options available with this drive/controller
combination are very confusing.  I finally settled on the above for
the drive, and used the alternate sector mapping for the controller.
Note that this is _NOT_ automatic sector forwarding, the question asked
at the time of installation.  You have to answer no to that question.
(see below)

After multiple attempts to install NetBSD-0.8, I decided that since
NetBSD-0.9 was just around the corner, I would wait for it to become
available and see if it had problems with bad144 sorted out.  So the 
box waited in a corner for a couple of weeks....

Got '0.9 and tried installing, same probs.   The difficulty here is
that I could find no way of doing a test for bad sectors on the drive
that was valid.  Copying files (large ones) to fill the disk will only
find a sector that is definitly bad _NOW_, it may not find a sector
that is merely flakey which will fail during use later.

Using a WD1007V ESDI controller, the only _practical_ way to install
NetBSD was to format the drive with the ESDI BIOS, using alternate 
sector mapping.  This will cause any track with a _SINGLE_ bad sector
to have the additional sector on that cylinder mapped into the
faulty one's place.  Tracks with more than one bad sector and you're
on your own. the ESDI BIOS marks them bad, can't do alt sect mapping
and leaves it to the OS to sort out.  This is OK for DOS or Novell
but NetBSD-0[89] spits the dummy when it finds a bad sector during a
write, probably during a read as well.

In my case, the drive had two veerry flakey tracks, 479 and 1003,
that kept causing the machine to fail when writing a file.

To do a really cheap and nasty test for write failures, I grabbed a
copy of the entire NetBSD-0.8 source I had tarred up (about 33 Megs)
and copied it multiple times to new files.  
	If you don't have a large file, do this to create one.
  	'cat /386bsd >> bigfile' (append the kernel to a file) 
	as many times as it takes to make a _large_ file.  It is 
	useful to have a range of file sizes, because as you get 
	to the 90% full mark, you will need a file small enough 
	so it won't overflow the disk space.  
As it filled up the drive a pattern emerged on the two faulty tracks, 
and I gradually marked each sector as bad when it was found.  The problem 
with this was that when sectors on each of these cylinders were written 
to, they might not be bad the first time.  Now I'm a bit confused here 
as to what was happening (it was 2 AM), sometimes the next sector, the 
sector after the one I had just marked bad, would be found bad while 
writing the next file.  Anyway, because of this I decided to add all 
sectors on both flakey tracks to the bad track table.  That way any 
possible flakey sectors could not come back and bite me later.
The important part is that the drive is now working.

In all of this thread, I get the distinct feeling that nobody has
posted _in detail_ how to initially find the bad sectors on the drive 
and how to enter them in the badtrack table so NetBSD will be able to 
avoid using them.  Is there a way to find bad sectors by running a
utility? I have not seen anything in the man page that indicates
badd144 will.  A lot of people are not able install NetBSD as a 
result.  There appears to be a lot of technical knowledge about how
bad144 works but very little in the way of examples (humble apologies 
if I missed any of these detailed explanations/examples) to show people
how it is done.  In particular the man page for bad144 is misleading
about the use of the -f switch (see below), and I have not seen any
mention of the correct way to use it.  This is _not_ a flame, It's only
that I can see a lot of people asking questions about problems with
ESDI and IDE drives, quite a few of them may not be as familiar with
unix as many of the posters are, and have not got a clue about things
those knowledgable posters take for granted.  I put myself in the
_dumb_ class when it comes to bad144, because this is the first
experience I've had with an ESDI drive and I wouldn't want to go through
it again - ESDI is shit.  My system at work runs NetBSD-0.8, 3 SCSI
drives and has no problems. 8-)


If you have an ESDI (or IDE) drive that has bad sectors, try this:

When installing NetBSD-0.[89], make the highest cylinder number 1023
range 0 - 1023 = 1024 which is OK for the BIOS - see posts by other
people in this thread for a more in-depth explanation.  Calculate 
your partition boundaries to suit.  when asked if you drive does 
automatic sector forwarding, say no.
This will put the entry: 'flags: badsect' in your disklabel.  This
allows NetBSD to use bad144.
NOTE: This only applies to a configuration where NetBSD uses _all_
the hard drive.  If you want DOS on your drive you may be able
to use this, but then you may not. 8-(
Then after installing basic NetBSD...... read on.

For those people having problems with bad144, this is a summary of
what I did to mark the bad sectors into the table, and here is the
part that puzzled (and frustrated me) for my 20 or so unsuccessful
attempts to install NetBSD-0.8.  bad144 could have the sector marked
bad using the -a switch, but would fail when writing a file over
that sector?????.  i.e. bad144 -a -v wd0 bad_sect_num
I found the bad144 man page to be _really_ bad and a switch
did not work as described in the man page.  In particular,
the -f switch, which formats the sector as bad so the system will
see it. The man page entry shows the position of the switches in
the command line: 
	bad144 -a [-c] [-f] [-v] disk [bad ...]
                       ^^^^
This did not work for me.  The -f switch _MUST_ be used _AFTER_
the disk name, i.e.  
	bad144 wd0 -f sorted_list_of_sector_numbers
You must provide bad144 with a list of sector numbers each time it
is invoked.  If this is not done, the bad track table is altered
to show _only_ the sector number/s you provided when it was run.
See table below:

Bad Sector table
Bad Sector table		params passed to	Bad Sector table
before using -f			bad144 with -f		after bad144 -f
--------------------------------   ------  --------------------------------
sn=527028, cn=1003, tn=12, sn=33   527027  sn=527027, cn=1003, tn=12, sn=32
sn=527029, cn=1003, tn=12, sn=34
--------------------------------   ------  --------------------------------

The syntax used here would have been:
bad144 wd0 -f 527027
It should have been:
bad144 wd0 -f 527027 527028 527029
to preserve the existing entries in the table.  

How do you do this when you have a list of sectors as long as your arm?

I wrote a simple script which does the job.  create a file with the
first sector you find and enter it as an absolute sector number (for the 
drive), call the file anything you like.  In the script below, I called it
/etc/bad144.1  As you find each bad sector, it must be added to this file,
preferably in numerical order.

this is what the file should look like using the above example sectors:

527027
527028
527029

this is the (really rough) script:

# /bin/addbad
bad144 -a -v wd0		        # cleans out the table 
bad144 -a -v wd0 `cat /etc/bad144.1`	# add sectors in the file
					# to the bad track table
bad144 wd0 -f `cat /etc/bad144.1`	# formats the sectors as
					# bad so NetBSD won't use them

I am not absolutely sure about the first use of bad144 -a -v wd0, it should
clean out the table so there will be no duplicates causing problems with
your table, but the rest definitely works!

IMPORTANT:  Do NOT use this script when you have a working system.  If
you clean out the table on the working system, all the sectors that have
been mapped into the bad track table will be deleted, thereby losing data
from your existing files that have sectors mapped into the table.  I think
the only way you may be able to do this, someone correct me if I am wrong,
is to add the sector to the table and then reformat the entire table:

bad144 -a -v wd0 123456		# adds the new bad sector to the table
then add the sector to your file (/etc/bad144.1) with the list of bad
sectors and run bad144 again with the list of sectors to format.
bad144 wd0 -f `cat /etc/bad144.1`

Please correct me if I am wrong about this, I don't know how bad144
handles sectors already in the table if you use this method.

You will also need to get a copy of fsck - It doesn't get installed
when you first install NetBSD-0.[89].  Neither does vi, grab that 
while you're at it.  Running fsck after each bad sector was found
and entered into the badtrack table cleaned up the system, I am not 
sure how clean the filesystem would be without it.

I hope my this helps anyone having problems with ESDI or old IDE
drives that don't do automatic sector forwarding.  I remember reading
at least one post that described problems with an old IDE drive that
was not doing sector forwarding.


-- 
-- 
   _-_|\    Terry Dwyer 	      E-Mail: tdwyer@nodecg.ncc.telecomwa.oz.au
  /     \   System Administrator      Phone: +61 9 491 5161  Fax: +61 9 221 2631
  *_.^\_/   Australian and Overseas Telecommunications Commission (AOTC)