home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / linux / 16588 < prev    next >
Encoding:
Text File  |  1992-11-13  |  7.7 KB  |  250 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!email!saruman.neuro.tuwien.ac.at!kircher
  3. From: kircher@saruman.neuro.tuwien.ac.at (Gerhard R. Kircher)
  4. Subject: How to make a bad blocks list for mk(e)fs
  5. Message-ID: <1992Nov13.110044.9914@email.tuwien.ac.at>
  6. Sender: news@email.tuwien.ac.at
  7. Nntp-Posting-Host: saruman.neuro.tuwien.ac.at
  8. Organization: Technical University of Vienna
  9. X-Newsreader: TIN [version 1.1 PL6]
  10. Date: Fri, 13 Nov 1992 11:00:44 GMT
  11. Lines: 237
  12.  
  13.  
  14. Generating a bad block list for mk(e)fs
  15. =======================================
  16.  
  17. Nov 11, 1992  Gerhard Kircher   (kircher@neuro.tuwien.ac.at)
  18.  
  19.  
  20. Introduction
  21. ------------
  22.  
  23. First of all: the -c option (check bad blocks) of mk(e)fs
  24. does not work (the code used cannot detect any bad blocks).
  25. Fortunately there is another option -l <file> to tell
  26. mk(e)fs where the bad blocks are.
  27. SCSI and IDE drive users do not need any bad block management
  28. - the drive logic does it for them. However, users of old
  29. MFM or RLL drives do need it. 
  30.  
  31.  
  32. 1 Where are my bad blocks ?
  33. ---------------------------
  34.  
  35. Every MFM or RLL drive is tested by the manufacturer and the
  36. locations of bad blocks are usually printed directly
  37. on the drive case.
  38. If you cannot find any bad block information on your
  39. drive, you can use the common disk test software (Norton,...)
  40. to check your drive and obtain a defect list.
  41.  
  42. Locations of bad blocks are given in terms of
  43. cylinder and head coordinates. Cylinder and head
  44. together specify a certain track. Some manufacturers
  45. are more specific about the location of the bad spot
  46. within the track but if you know how to use this information
  47. you probably do not need to read this guide.
  48. So if we know the track where the bad spot sits, we
  49. declare the entire track as bad (even experts do this).
  50.  
  51. What we have now is a table of the form
  52.  
  53.   CYLINDER  HEAD
  54.   ...       ...
  55.   ...       ...
  56.   ...       ...
  57.  
  58.  
  59. 2 calculating all bad sectors
  60. -----------------------------
  61.  
  62. Each sector on the drive can be addressed by three cordinates:
  63.   Cylinder = [0..CYLINDERS-1]
  64.   Head     = [0..HEADS-1]
  65.   Sector   = [0..SECTORS-1]
  66. where
  67.   CYLINDERS ... total number of cylinders
  68.   HEADS     ... total number of heads
  69.   SECTORS   ... number of sectors per track
  70.  
  71. The absolute address of a sector on the disk is then calculated
  72. according to the formula
  73.  
  74.   Abssector = HEADS*SECTORS*Cylinder + SECTORS*Head + Sector.
  75.  
  76. We can now calculate the absolute addresses of all sectors
  77. of every bad track on our disk according to
  78.  
  79.   for each bad track given by Cylinder and Head do
  80.   begin
  81.     for Sector=0 to SECTORS-1 do
  82.     begin
  83.       Abssector = HEADS*SECTORS*Cylinder + SECTORS*Head + Sector
  84.     end
  85.   end
  86.  
  87. obtaining a list of all bad sectors.
  88.  
  89.  
  90. 3 Converting absolute sectors to partition relative sectors
  91. -----------------------------------------------------------
  92.  
  93. Partitions are like separate disks, that means that sector counting
  94. starts with 0 for each partition. So what we have to do next is
  95. to generate a bad sector list for each partition we want to use
  96. for linux. To do that, we must know where each partition starts
  97. and ends. We can get this information from fdisk. When we start
  98. fdisk and type 'p' to view the partition table, the begin, start
  99. and end information will be given in terms of cylinders.
  100. When we type 'u' to toggle the units, an then again 'p'
  101. we get what we need: Start and End of each partition in terms
  102. of absolute sectors.
  103. Here is what I see on my system (I use my second disk for linux):
  104.  
  105. /# fdisk /dev/hdb
  106.  
  107. Command (m for help): p
  108.  
  109. Disk /dev/hdb: 8 heads, 17 sectors, 1024 cylinders
  110. Units = cylinders of 136 * 512 bytes
  111.  
  112.    Device Boot  Begin   Start     End  Blocks   Id  System
  113. /dev/hdb1           1       1     963   65483+  81  Linux/MINIX
  114. /dev/hdb2         964     964    1024    4148   82  Linux swap
  115.  
  116. Command (m for help): u
  117. Changing display/entry units to sectors
  118.  
  119. Command (m for help): p
  120.  
  121. Disk /dev/hdb: 8 heads, 17 sectors, 1024 cylinders
  122. Units = sectors of 1 * 512 bytes
  123.  
  124.    Device Boot  Begin   Start     End  Blocks   Id  System
  125. /dev/hdb1           1       1  130967   65483+  81  Linux/MINIX
  126. /dev/hdb2      130968  130968  139263    4148   82  Linux swap
  127.  
  128. Command (m for help): q
  129.  
  130. Sector counting (as counting always should do :-) starts with 0.
  131. The first partition begins with sector one, as sector 0 is
  132. always the boot sector.
  133.  
  134. This is how we calculate the addresses for one partition:
  135.  
  136.   a) From the list obtained in section 2, cancel all addresses
  137.      that are not in the range [Start..End] (including limits)
  138.      shown by fdisk.
  139.   b) Subtract Start from each remaining entry.
  140.  
  141.  
  142. 4 Converting to blocks
  143. ----------------------
  144.  
  145. A disk sector has a length of 512 bytes (this is the usual size
  146. BIOS/DOS can handle). Linux groups two sectors to an entity
  147. called block. A block therefore consists of two physical sectors
  148. and has a size of 1024 bytes (I read somewhere that larger blocks
  149. will be supported in the future). The mk(e)fs program wants to
  150. know the addresses of bad blocks, not sectors. So we convert
  151. our partition relatve sector addresses to partition relative
  152. block addresses by dividing by two and taking the integer part.
  153. Doing that we certainly get a lot of duplicate addresses
  154. which we have to get rid of, so we simply delete redundant
  155. entries.
  156.  
  157. What we have now is a list of bad blocks for each partition.
  158. Mk(e)fs likes to get this information from a file,
  159. one address per line, one file for each partition.
  160.  
  161.  
  162. 5 Automating the process
  163. ------------------------
  164.  
  165. Doing all the calculations by hand is tedious and error prone.
  166. So we may decide to automate the whole thing.
  167. We can do everything in dos when we use the proper utilities
  168. (see later)
  169.  
  170. 5.1 The Input File
  171.  
  172. We need a single file containing the coordinates of all bad tracks
  173. of one entire disk. Each line of the file consists of two fields,
  174. the first of which is the cylinder number and the second is
  175. the head number. These are the first few lines of the file for my
  176. second disk:
  177.  
  178.     48 0
  179.    105 4
  180.    150 2
  181.    224 1
  182.    380 2
  183.    427 6
  184.    435 1
  185.  
  186.  
  187. 5.2 An AWK script for doing all the calculations
  188.  
  189. In the following we present an awk script that does all the work
  190. for us. We just have to plug in the correct values of the
  191. partition and drive parameters and off we go.
  192. I use gawk211.zip and sort03.arc which I downloaded from a
  193. simtel20 mirror.
  194. Sort is used to remove the duplicates.
  195.  
  196. #---the awk script starts here
  197. # generates linux bad blocks file (starting count with 0)
  198. # for partition ONE
  199. # for micropolis drive 8 heads, 17 sectors
  200. # input file: cyl[0.. ] head[0.. ]\n
  201. # stdout: abs blocks of corresponding partition\n
  202. BEGIN { start   = 1;
  203.         end     = 130967;
  204.         sectors = 17;
  205.         heads   = 8;
  206.       }
  207. { sec=$1*sectors*heads+$2*sectors;
  208.   if (sec>=start && sec<=end)
  209.     for (i=0; i<sectors; i++) print int((sec-start+i)/2) | "sort -mu"
  210. }
  211. #---the awk script ends here
  212.  
  213. Suppose that our input file is named 'badtrack.lst' and that the
  214. awk file is 'part1.awk', then we can generate a bad block list
  215. for mk(e)fs by typing the command
  216.  
  217.   gawk -f part1.awk badtrack.lst > badblk1.lst
  218.  
  219. This is the file we need. 
  220.  
  221. 5.3 Making the file system
  222.  
  223. What we must do now is to have this file accessible for linux during 
  224. installation. There are several ways to do this. I put it somewhere 
  225. on my dos drive (partition) and mounted the drive (could be a second 
  226. floppy drive as well). Suppose we do the installation from drive a and 
  227. have the file badblk1.lst in the root directory of a floppy in drive b.
  228. Then we mount the floppy b to the /user directory by
  229.  
  230.   mount -t msdos /dev/fd1 /user
  231.  
  232. Now we can make the file system (to be concrete we use my example,
  233. that is the first partition of my second drive)
  234.  
  235.   mk(e)fs -l /user/badblk1.lst /dev/hdb1 65483
  236.  
  237. Thats it!
  238.  
  239.  
  240. Bugs
  241. ----
  242.  
  243. I only tried mkfs but I'm rather convinced that it works with
  244. mkefs as well.
  245.  
  246.  
  247. Suggestions and corrections welcome
  248.  
  249. - Gerhard
  250.