User Tools

Site Tools



Geometría de memorias USB

First off it appears that the geometry on a pendrive is NOT fixed in hardware, I have been able to change the parameters and have it work fine both in DSL and WinXP, the upshot is that if your pendrive doesn't have parameters you like, change them!

From fdisk(8) man page:

     -c cylinders, -h heads, -s sectors
             Specifies an alternate BIOS geometry for fdisk to use.  By de-
             fault, an automatic calculation of disk size will be built using
             heuristics.  These figures are taken from the in-core disklabel
             (see disklabel(8)), or values that /boot has passed to the ker-

Why would you want to change the parameters? When making a bootable partition you want to have 32 sectors per track and 1024 or less cylinders in the boot partition. Some pendrives come with strange parameters and if you change the sectors per track, the number of cylinders might go over 1024.

Conceptos sobre geometría de discos

The total disk size is simply the product of the total number of sectors (number of cylinders x number of heads x number of sectors/track) with 512 (the sector size).

CHS (24 bits)

In the CHS format a sector is identified by its Cylinder/Head/Sector number. Earlier these values meant the physical location of the sector on the disk. Today these values are only logical numbers.

The (logical) number of cylinders, heads and sectors per track can be determined by the func. 08h resp. 48h of the BIOS interrupt 13h.

The CHS format is supported by all the BIOS but it is limited to a disk size of 8 GB: with 24 bits and a sector size of 512 bytes it is possible to address all sectors of a disk up to a maximum disk size of 8 GB. For the LBA addressing scheme there are 32 bits reserved in the partition table. At the same sector size of 512 bytes all sectors of a disk up to a maximum size of 2048 GB (2 TB) can be addressed.

The CHS format has the following restrictions:

   cylinder number  0 - 1023 (10 Bit)
   head number      0 - 254  (8 Bit)
   sector number    1 - 63   (6 Bit)

10 bits permiten un número máximo de cilindros de 1024. Las BIOS usan CHS para acceder a los discos, por lo que para acceder a discos de más de 1024 cilindros necesitamos accederlos directamente, sin usar la BIOS. Sin embargo, es la BIOS quien accede a la partición de arranque al iniciar el sistema, por lo que la partición de arranque debe respetar el máximo número de 1024. Es en esa partición de no más de 1024 cilindros donde debe de estar el kernel del sistema operativo.

Due to a problem in the DOS operating system a maximum head number 255 leads to a crash although the BIOS would allow this number. Therefore a maximum head number 255 is not used in general.

LBA (32 bits)

LBA format: LBA is the abbreviation for Logical Block Address. This simply means the sectors of a disk are sequentially numbered starting with LBA number 0. Every sector is identified by its unambigious LBA number. The LBA format is supported only by a mainboard BIOS which is not too old.

Ejemplos de geometrías en discos USB

Pendrive Transcend 8Gb

 sd0 at scsibus0 targ 1 lun 0: <JetFlash, TS8GJFV10, 0.00> SCSI2 0/direct removable
 sd0: 7871MB, 7871 cyl, 64 head, 32 sec, 512 bytes/sec, 16121855 sec total

Tarjeta Compact Flash SANDISK 512Mb

 sd0 at scsibus0 targ 1 lun 0: <SanDisk, SDCFB-u1r ` ` `, t.p4> SCSI2 0/direct fixed
 sd0: 524776MB, 524776 cyl, 64 head, 32 sec, 512 bytes/sec, 1074742768 sec total

OLYMPUS WS-300M Digital Voice Recorder

 sd0 at scsibus0 targ 1 lun 0: <OLYMPUS, DVR, 1.00> SCSI2 0/direct removable
 sd0: 250MB, 62 cyl, 64 head, 32 sec, 2048 bytes/sec, 128000 sec total

Este dispositivo viene preformateado a 2048 bytes/sector. Esta geometría no estándar solo se soporta en versiones recientes de sistemas operativos: OpenBSD 4.1, Linux kernel 2.1.32).

Disco duro Hitachi 20 Gb

 sd0 at scsibus0 targ 1 lun 0: <IC25N020, ATMR04-0, AD0A> SCSI2 0/direct fixed
 sd0: 19077MB, 19077 cyl, 64 head, 32 sec, 512 bytes/sec, 39070080 sec total


The problem was that the card I was using had < 1024 sectors (cylinders?) and so the Soekris automatically uses CHS to address it. The machine on which I was building the image via the CF-ATA adapter was using LBA. Changed it to CHS and reformatted, reinstalled DOS and presto!


MS-DOS does, in fact, view the sectors on a disk as a one-dimensional array of sectors numbered from 0 to n-1, where n is the total number of sectors on the disk. It therefore must translate from the logical sector numbers to physical to physical cylinder-head-sector, or CHS addresses. In doing so, MS-DOS sequentially numbers all the sectors of head 0, cylinder 0, then all the sectors of head 1, cylinder 0, and so on for each head, and then repeats this for each cylinder, to the end of the disk.

Furthermore, MS-DOS logically divides this array of sectors into five distinct areas, which are, in the order they appear on the disk,

  • The partition table,
  • The boot record,
  • The File Allocation Table (FAT),
  • The root directory, and
  • The data area.

The first four areas of the disk, collectively called the system area, are used by MS-DOS to keep track of the contents of the disk. The largest area of the disk, the data area, is where all user files and data reside. MS-DOS uses a special numbering scheme for the area called cluster numbering which is in addition to, but independent of logical sector numbers.

The boot record occupies one sector, and is always placed in logical sector number (LSN) 0, which is physically cylinder 0, head 0, sector 1, the first sector of the first head of the first cylinder on the disk. This is the easiest sector on the disk for the computer to locate when it begins running.

The File Allocation Table (FAT) is an array of integers in which each element represents one cluster in the data area. For each cluster in the data area the corresponding entry in the FAT contains a code which indicates the status of the cluster. The cluster may be available for use, it may be reserved by the operating system, it may be unavailable due to a bad sector on the disk, or it may be in use by a file.

Master Boot Record

El MBR contiene una tabla de particiones describiendo donde estan las particiones (primarias). Hay 4 entradas en dicha tabla, para 4 particiones primarias, y cada una tiene el siguiente aspecto:

   struct partition {
            char active;     /* 0x80: arrancable, 0: no arrancable */
            char begin[3];   /* CHS para el primer sector */
            char type;
            char end[3];     /* CHS para el ultimo sector */
            int start;       /* numero de sector en 32 bit (contado desde 0) */
            int length;      /* numero de sectores 32 en bit */

(donde CHS se refiere a Cilindros/Cabezas/Sectores). Por tanto, la informacion es redundante: la localizacion de la particion se da tanto por los campos de 24 bits begin y end, como por los campos de 32 bits start y length.

Linux solo usa los campos start y length, y puede por tanto manejar particiones no mayores de 232 sectores, o lo que es lo mismo, particiones de mas de 2 TeraBytes. Lo cual es doscientas veces el tama˜no de los discos disponibles actualmente, por lo que sera suficiente para los proximos años.


hardware/discos.txt · Last modified: 2007/07/16 10:51 by jherrero