home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slakinst / eide.txt < prev    next >
Encoding:
Text File  |  1995-08-04  |  7.2 KB  |  174 lines

  1.  
  2. [NOTE: With the newer kernels now used by Slackware you shouldn't need to
  3.        worry about this, but I'm including it in case anyone needs to run an
  4.        earlier kernel (like 1.1.18) on an EIDE drive  - Pat ]
  5.  
  6.  
  7.  
  8.                 Everything I Know About Linux and EIDE
  9.                 --------------------------------------
  10.  
  11. Introduction
  12. ------------
  13.  
  14. It is possible to use Linux on a large EIDE drive with no restrictions
  15. on where anything resides.  I only deal with DOS and Linux here, but
  16. the approach I suggest should be compatible with other operating
  17. systems as well.
  18.  
  19. I presently use version 1.0.9 of the kernel, but everything here
  20. applies to kernels at least through 1.1.34.  Sometime in the future,
  21. Linux will probably support EIDE gracefully and transparently, at
  22. which point all of this will be moot.  Everything I suggest, however,
  23. should continue to work with these future kernels, although most of it
  24. will become unnecessary.
  25.  
  26.  
  27. Background and Terminology
  28. --------------------------
  29.  
  30. Sectors on an ATA (IDE) drive are 512 bytes long.  There are two ways
  31. to address sectors.  Logical Block Address (LBA) form, or logical
  32. form, numbers the sectors linearly starting with 0.
  33. Cylinder-Head-Sector (CHS) form, or physical form, addresses each
  34. sector with a (cylinder, head, sector) triplet.  To convert addresses
  35. from logical to physical form, it is necessary to know how many heads
  36. per cylinder and how many sectors per head the drive has.  If the
  37. total number of cylinders is known as well, the size of the drive can
  38. be determined.  The number of cylinders, heads per cylinder ("heads"),
  39. and sectors per head ("sectors") is called the "disk geometry".
  40.  
  41. Old controllers and BIOSes require sectors to be addressed in physical
  42. form; all controllers and BIOSes allow sectors to be addressed in
  43. physical form.  Linux uses logical addresses everywhere except at the
  44. lowest possible level, when it translates to physical form to talk to
  45. the controller.  Linux does not use the BIOS for anything except to
  46. determine the disk geometry.
  47.  
  48. The partition table records the start and end of each partition in
  49. *both* logical and physical form.  Both DOS fdisk and Linux fdisk
  50. expect these values to agree.  DOS fdisk obtains the disk geometry by
  51. querying the BIOS; Linux fdisk obtains the geometry by querying the
  52. kernel.
  53.  
  54. Now for the fun part.  MS-DOS and the BIOS interface use a 10-bit
  55. field to hold the cylinder number, so they only allow cylinders 0-1023
  56. to be accessed.  This is not sufficient for modern drives, which tend
  57. to have 63 sectors/head, 16 heads/cylinder, and many cylinders.  The
  58. "solution" is a complete hack: An EIDE BIOS will *lie* when queried
  59. for the disk geometry by halving (or quartering) the number of
  60. cylinders and doubling (or quadrupling) the number of heads.  Then
  61. whenever a physically addressed I/O request arrives, the BIOS will
  62. assume the request is based on the bogus disk geometry, and will
  63. convert it appropriately to talk to the controller.  This process is
  64. called "address translation".
  65.  
  66.  
  67. The Problem
  68. -----------
  69.  
  70. When the Linux kernel queries the BIOS (actually, it just reads the
  71. CMOS settings) to determine the disk geometry, it will get the bogus
  72. values which claim more than 16 heads.  Linux knows that this is
  73. impossible, so the code in hd.c gives up and skips the drive.  (Note
  74. that even though the BIOS is reporting a bogus geometry, requests to
  75. the controller still need to be based on the real geometry.  Thus
  76. merely eliminating the test in hd.c won't work.)
  77.  
  78.  
  79. The Wrong Solution
  80. ------------------
  81.  
  82. One fix is to use the BIOS "setup" program to turn off address
  83. translation completely.  You may have to manually set the
  84. cylinder/head/sector values to the real geometry, or it may be
  85. possible to simply turn off the translation, depending on how your
  86. setup works.
  87.  
  88. Then you can repartition your drive with DOS and/or Linux fdisk,
  89. install both operating systems, and things will work, provided you
  90. observe certain restrictions.
  91.  
  92. The problem is that the BIOS still can't be used to access cylinders
  93. above 1023.  So all of your DOS partitions will have to be below that
  94. limit, as will anything which needs to be accessed through the BIOS.
  95. For example, LILO uses the BIOS to do its dirty work; so if you want
  96. to use LILO to boot Linux, you will have to make sure the kernel
  97. (read: entire root partition) lies below the 1024 cylinder limit.
  98. Linux itself, however, will happily access the entire drive.
  99.  
  100.  
  101. The Right Solution
  102. ------------------
  103.  
  104. Restrictions are annoying, so we will avoid them.  This obviously
  105. requires leaving address translation on and dealing with the remaining
  106. problems in a different way.
  107.  
  108. To fix the kernel's problem, simply feed the real geometry to the
  109. kernel with a boot-time option line.  You can do this from the LILO
  110. boot prompt by typing "<image name> hd=<cylinders>,<heads>,<sectors>".
  111. You can also have LILO feed the options automatically by using an
  112. "append=" directive in your lilo.conf file.
  113.  
  114. Now the kernel will be able to recognize and access the drive, but
  115. when a user mode program (e.g., fdisk or the LILO installer) queries
  116. the kernel for the disk geometry, the kernel will return the real geometry,
  117. not the bogus one.  So Linux fdisk (which queries the kernel) and DOS
  118. fdisk (which queries the BIOS) will disagree about how the partition
  119. table should look.  Also, the LILO installer will be computing
  120. physical addresses which are incompatible with what the BIOS (and
  121. therefore the LILO runtime) requires.
  122.  
  123. The fdisk problem is easy to fix:  Go to expert mode, and set the
  124. number of cylinders and number of heads to the bogus (BIOS-compliant)
  125. values.  Then edit the partition table and write it out, confident
  126. that Linux fdisk and DOS fdisk are seeing eye to eye.
  127.  
  128. The LILO problem is just as easy to fix: Add the "linear" directive to
  129. your lilo.conf file.  This will cause LILO to use logical addresses
  130. instead of physical to store its data, forcing LILO to compute
  131. physical addresses at run time instead of at install time.  This will
  132. use the geometry supplied by the BIOS instead of that supplied by the
  133. kernel, and everything will "just work".
  134.  
  135.  
  136. Example / Summary
  137. -----------------
  138.  
  139. I have a 1 Gig EIDE drive on which I recently installed Linux.  Here
  140. is the procedure I used.
  141.  
  142. 1) Ran setup and examined the (bogus) disk geometry.  It said 505
  143. cylinders, 64 heads, 63 sectors.  More than 16 heads is impossible, so
  144. the real values must be 2100 cylinders, 16 heads, 63 sectors.
  145.  
  146. 2) Booted DOS boot disk, ran fdisk, created a DOS partition.
  147.  
  148. 3) Booted Slackware boot disk.  Typed "ramdisk hd=2100,16,63" to boot
  149. the kernel.  Ran Linux fdisk, typed "p" to see lots of errors, typed
  150. "x" to access expert mode, set cylinders to 505, set heads to 64,
  151. returned to normal mode, typed "p" to see my DOS partition and no
  152. error messages.  Created partitions to heart's content.  Saved
  153. partition table and rebooted from Slackware disk (not sure why I had
  154. to do this).
  155.  
  156. 4) Installed Slackware normally, creating an ordinary lilo.conf file.
  157.  
  158. 5) Edited lilo.conf (in this case, /mnt/etc/lilo.conf) to add these
  159. lines to the top:
  160.  
  161. append="hd=2100,16,63"
  162. linear
  163.  
  164. 6) Ran "lilo -r /mnt".  I expected to need the "-P ignore" option, but
  165. didn't.  Go figure.
  166.  
  167. 7) Installed DOS and Windows, much to my chagrin.
  168.  
  169.  
  170. Good luck to all.
  171.  
  172. - Patrick LoPresti
  173.   patl@lcs.mit.edu
  174.