home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LINUX / HOWTO / mini / largedsk.txt < prev    next >
Text File  |  1997-07-07  |  19KB  |  400 lines

  1.   Large Disk mini-HOWTO
  2.   Andries Brouwer, aeb@cwi.nl
  3.   v1.0, 960626
  4.  
  5.   All about disk geometry and the 1024 cylinder limit for disks.
  6.  
  7.   1.  The problem
  8.  
  9.   Suppose you have a disk with more than 1024 cylinders.  Suppose
  10.   moreover that you have an operating system that uses the BIOS.  Then
  11.   you have a problem, because the usual INT13 BIOS interface to disk I/O
  12.   uses a 10-bit field for the cylinder on which the I/O is done, so that
  13.   cylinders 1024 and past are inaccessible.
  14.  
  15.   Fortunately, Linux does not use the BIOS, so there is no problem.
  16.  
  17.   Well, except for two things:
  18.  
  19.   (1) When you boot your system, Linux isn't running yet and cannot save
  20.   you from BIOS problems.  This has some consequences for LILO and
  21.   similar boot loaders.
  22.  
  23.   (2) It is necessary for all operating systems that use one disk to
  24.   agree on where the partitions are.  In other words, if you use both
  25.   Linux and, say, DOS on one disk, then both must interpret the
  26.   partition table in the same way.  This has some consequences for the
  27.   Linux kernel and for fdisk.
  28.  
  29.   Below a rather detailed description of all relevant details.  Note
  30.   that I used kernel version 2.0.8 source as a reference.  Other
  31.   versions may differ a bit.
  32.  
  33.   2.  Booting
  34.  
  35.   When the system is booted, the BIOS reads sector 0 (known as the MBR -
  36.   the Master Boot Record) from the first disk (or from floppy), and
  37.   jumps to the code found there - usually some bootstrap loader.  These
  38.   small bootstrap programs found there typically have no own disk
  39.   drivers and use BIOS services.  This means that a Linux kernel can
  40.   only be booted when it is entirely located within the first 1024
  41.   cylinders.
  42.  
  43.   This problem is very easily solved: make sure that the kernel (and
  44.   perhaps other files used during bootup, such as LILO map files) are
  45.   located on a partition that is entirely contained in the first 1024
  46.   cylinders of a disk that the BIOS can access - probably this means the
  47.   first or second disk.
  48.  
  49.   Another point is that the boot loader and the BIOS must agree as to
  50.   the disk geometry.  It may help to give LILO the `linear' option.
  51.   More details below.
  52.  
  53.   3.  Disk geometry and partitions
  54.  
  55.   If you have several operating systems on your disks, then each uses
  56.   one or more disk partitions.  A disagreement on where these partitions
  57.   are may have catastrophic consequences.
  58.  
  59.   The MBR contains a partition table describing where the (primary)
  60.   partitions are.  There are 4 table entries, for 4 primary partitions,
  61.   and each looks like
  62.  
  63.   struct partition {
  64.           char active;    /* 0x80: bootable, 0: not bootable */
  65.           char begin[3];  /* CHS for first sector */
  66.           char type;
  67.           char end[3];    /* CHS for last sector */
  68.           int start;      /* 32 bit sector number (counting from 0) */
  69.           int length;     /* 32 bit number of sectors */
  70.   };
  71.  
  72.   (where CHS stands for Cylinder/Head/Sector).
  73.  
  74.   Thus, this information is redundant: the location of a partition is
  75.   given both by the 24-bit begin and end fields, and by the 32-bit start
  76.   and length fields.
  77.  
  78.   Linux only uses the start and length fields, and can therefore handle
  79.   partitions of not more than 2^32 sectors, that is, partitions of at
  80.   most 2 TB.  That is two hundred times larger than the disks available
  81.   today, so maybe it will be enough for the next ten years or so.
  82.  
  83.   Unfortunately, the BIOS INT13 call uses CHS coded in three bytes, with
  84.   10 bits for the cylinder number, 8 bits for the head number, and 6
  85.   bits for the track sector number.  Possible cylinder numbers are
  86.   0-1023, possible head numbers are 0-255, and possible track sector
  87.   numbers are 1-63 (yes, sectors on a track are counted from 1, not 0).
  88.   With these 24 bits one can address 8455716864 bytes (7.875 GB), two
  89.   hundred times larger than the disks available in 1983.
  90.  
  91.   Even more unfortunately, the standard IDE interface allows 256
  92.   sectors/track, 65536 cylinders and 16 heads.  This in itself allows
  93.   access to 2^37 = 137438953472 bytes (128 GB), but combined with the
  94.   BIOS restriction to 63 sectors and 1024 cylinders only 528482304 bytes
  95.   (504 MB) remain addressable.
  96.  
  97.   This is not enough for present-day disks, and people resort to all
  98.   kinds of trickery, both in hardware and in software.
  99.  
  100.   4.  Translation and Disk Managers
  101.  
  102.   Nobody is interested in what the `real' geometry of a disk is.
  103.   Indeed, the number of sectors per track often is variable - there are
  104.   more sectors per track close to the outer rim of the disk - so there
  105.   is no `real' number of sectors per track.  For the user it is best to
  106.   regard a disk as just a linear array of sectors numbered 0, 1, ...,
  107.   and leave it to the controller to find out where a given sector lives
  108.   on the disk.
  109.  
  110.   This linear numbering is known as LBA.  The linear address belonging
  111.   to (c,h,s) for a disk with geometry (C,H,S) is c*H*S + h*S + (s-1).
  112.   All SCSI controllers speak LBA, and some IDE controllers do.
  113.  
  114.   If the BIOS converts the 24-bit (c,h,s) to LBA and feeds that to a
  115.   controller that understands LBA, then again 7.875 GB is addressable.
  116.   Not enough for all disks, but still an improvement.  Note that here
  117.   CHS, as used by the BIOS, no longer has any relation to `reality'.
  118.  
  119.   Something similar works when the controller doesn't speak LBA but the
  120.   BIOS knows about translation.  (In the setup this is often indicated
  121.   as `Large'.)  Now the BIOS will present a geometry (C',H',S') to the
  122.   operating system, and use (C,H,S) while talking to the disk
  123.   controller.  Usually S = S', C' = C/N and H' = H*N, where N is the
  124.   smallest power of two that will ensure C' <= 1024 (so that least
  125.   capacity is wasted by the rounding down in C' = C/N).  Again, this
  126.   allows access of up to 7.875 GB.
  127.  
  128.   If a BIOS does not know about `Large' or `LBA', then there are
  129.   software solutions around.  Disk Managers like OnTrack or EZ-Drive
  130.   replace the BIOS disk handling routines by their own.  Often this is
  131.   accomplished by having the disk manager code live in the MBR and
  132.   subsequent sectors (OnTrack calls this code DDO: Dynamic Drive
  133.   Overlay), so that it is booted before any other operating system.
  134.   That is why one may have problems when booting from a floppy when a
  135.   Disk Manager has been installed.
  136.  
  137.   The effect is more or less the same as with a translating BIOS - but
  138.   especially when running several different operating systems on the
  139.   same disk, disk managers can cause a lot of trouble.
  140.  
  141.   Linux does support OnTrack Disk Manager since version 1.3.14, and EZ-
  142.   Drive since version 1.3.29.  Some more details are given below.
  143.  
  144.   5.  Kernel disk translation for IDE disks
  145.  
  146.   If the Linux kernel detects the presence of some disk manager on an
  147.   IDE disk, it will try to remap the disk in the same way this disk
  148.   manager would have done, so that Linux sees the same disk partitioning
  149.   as for example DOS with OnTrack or EZ-Drive.  However, NO remapping is
  150.   done when a geometry was specified on the command line - so a
  151.   `hd=cyls,heads,secs' command line option might well kill compatibility
  152.   with a disk manager.
  153.  
  154.   The remapping is done by trying 4, 8, 16, 32, 64, 128, 255 heads
  155.   (keeping H*C constant) until either C <= 1024 or H = 255.
  156.  
  157.   The details are as follows - subsection headers are the strings
  158.   appearing in the corresponding boot messages.  Here and everywhere
  159.   else in this text partition types are given in hexadecimal.
  160.  
  161.   5.1.  EZD
  162.  
  163.   EZ-Drive is detected by the fact that the first primary partition has
  164.   type 55.  The geometry is remapped as described above, and the
  165.   partition table from sector 0 is discarded - instead the partition
  166.   table is read from sector 1.  Disk block numbers are not changed, but
  167.   writes to sector 0 are redirected to sector 1.  This behaviour can be
  168.   changed by recompiling the kernel with
  169.    #define FAKE_FDISK_FOR_EZDRIVE  0 in ide.c.
  170.  
  171.   5.2.  DM6:DDO
  172.  
  173.   OnTrack DiskManager (on the first disk) is detected by the fact that
  174.   the first primary partition has type 54.  The geometry is remapped as
  175.   described above and the entire disk is shifted by 63 sectors (so that
  176.   the old sector 63 becomes sector 0).  Afterwards a new MBR (with
  177.   partition table) is read from the