# kernel gets wrong harddisk size with ata_piix [solved]

## mv

Hello,

after switching from ide_generic (for which no dma is available) to the sata/pata-driver of my board (CONFIG_ATA_PIIX=y), the kernel gets a wrong (total) number of sectors for one of my harddisks (a slave on ordinary ide). Since this number is much too low, half of my /dev/sdb* partitions are not visible, and the last partition (which is "cut off") does of course not mount correctly. Also fdisk/cfdisk/parted cannot help, since they use the disk size they get from the kernel - they do not even start but just claim that the disk goes beyond its limits (and analyzing the source, I checked that the reason is that they read the wrong count by a kernel call); of course, using these tools would not be the proper solution anyway, since I need the full harddisk space.

My board is an intel gigabyte 82801G (ICH7). The sector number reported by the kernel is that shown by the BIOS if I switch the disk to "LBA" mode. However, there is also "CHS"-mode (which is the default mode), but switching to that mode in the BIOS makes no change for linux. So is it a driver bug that the kernel uses the wrong mode to read the number of sectors?

Or maybe I am missing some config option which would the kernel allow to "switch" the mode correctly?

The strange thing is that everything works correctly with ide_generic.

If it is really a kernel or BIOS bug: Can I somehow "force" the kernel to take the correct number? (I would not mind if I would have to hardcode the correct sector number somewhere manually)?Last edited by mv on Sun Jan 18, 2009 9:41 pm; edited 1 time in total

----------

## NeddySeagoon

mv,

I'm guessing that your drive is bigger than 137G but you can only see the first 137G.

It would be useful to know the real size of the drive.

The BIOS should be set to LBA mode. C/H/S mode can address 8G maximum. The kernel doesn't care. There are two standards for LBA mode, LBA28 which can address 137438953472 Bytes (137G) and LBA48 which can address a lot more. The kernel checks the LBA48 drive ID first and if there is nothing there, tries the LBA28 ID, which is in a different location. 

Drives bigger that 137G report 137Gb in the LBA28 ID location as its all the space allows. you don't have to do anything special, it just works.

What does 

```
hdparm -iI /dev/...
```

report?

Also, what does 

```
fdisk -l /dev/
```

... show

----------

## mv

NeddySeagoon, thanks for your reply.

 *NeddySeagoon wrote:*   

> I'm guessing that your drive is bigger than 137G but you can only see the first 137G.

 

The first guess is correct (160 GB) but the second not: I see only the first 33 GB.

 *Quote:*   

> The BIOS should be set to LBA mode.

 

As I mentioned, it makes no change. I can set the mode only after the autodetection anyway. It seems that the BIOS does not detect the harddisk correctly (but my other harddisk which is even larger is detected correctly; BTW they are master/slave). More precisely, in the BIOS I can only switch four modes:  *BIOS screen wrote:*   

> CHS: reports 33822 MB, 65531 Cylinders 16 Heads 63 Sectors
> 
> Large: reports 31703 MB, 4095 Cylinders, 240 Heads, 63 Sectors
> 
> LBA: 33816 MB, 4111 Cylinders, 255 Heads, 63 Sectors
> ...

  Unfortunately, it is not possible in the BIOS to change this information manually. The information which the kernel gets with the ata_piix driver is the one of LBA (no matter which mode I choose in the BIOS).

So I was actually rather surprised that there are no problems with the ide_generic driver: Somehow the kernel gets the correct size in this case anyway, I do not know from where.

 *NeddySeagoon wrote:*   

> What does 
> 
> ```
> hdparm -iI /dev/...
> ```
> ...

 

The information depends of course whether the ide_generic or the ata_piix driver is use. In the following, I write both informations side by side (red is the [false] information of the ata_piix driver).

 *hdparm -iI /dev/... wrote:*   

> /dev/hdb /dev/sdb
> 
>  Model=SAMSUNG SP1614N [25 spaces], FwRev=TM100-24, SerialNo=(not made public here)
> 
>  Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs }
> ...

 

 *NeddySeagoon wrote:*   

> Also, what does 
> 
> ```
> fdisk -l /dev/
> ```
> ...

 

With the ata_piix driver it shows nothing (since it probably exits immediately because a partition is beyond the end). However, by inserting some printf-s into the sourcecode I found that it gets from the kernel the same information as with the ide_generic driver except for the total number of sectors [which it calculates by ioctl(fd, BLKGETSIZE64, bytes)] (the heads/sectors of the kernel and on the partition table are the same):

 *patched fdisk /dev/sdb wrote:*   

> heads: 255, sectors: 63, total sectors:  66055248

 

 *patched fdisk /dev/hdb wrote:*   

> heads: 255, sectors: 63, total sectors:  312581808

 

(the second is of course with the ide_generic driver). With the ide_generic driver, fdisk -l /dev/hdb gives 

```
Disk /dev/hdb: 160.0 GB, 160041885696 bytes

255 heads, 63 sectors/track, 19457 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: (not made public here)

   Device Boot      Start         End      Blocks   Id  System

/dev/hdb1               1          38      305203+  16  Hidden FAT16

/dev/hdb2              39         268     1847475   16  Hidden FAT16

/dev/hdb3   *         269         765     3992152+   b  W95 FAT32

/dev/hdb4             766       19457   150143490    f  W95 Ext'd (LBA)

/dev/hdb5             766         880      923674+   e  W95 FAT16 (LBA)

/dev/hdb6             881         992      899608+   e  W95 FAT16 (LBA)

/dev/hdb7             993         996       32098+  83  Linux

/dev/hdb8             997        1000       32098+  83  Linux

/dev/hdb9            1005        2248     9992398+  83  Linux

/dev/hdb10           2249        3492     9992398+  83  Linux

/dev/hdb11           3493        4736     9992398+  83  Linux

/dev/hdb12           4737        5980     9992398+  83  Linux

/dev/hdb13           5981        6602     4996183+  83  Linux

/dev/hdb14           6603       18844    98333833+  83  Linux
```

 This is the way the disk actually was partitioned (on a different system).

----------

## NeddySeagoon

mv,

This all helps. 33Gb was the previous BIOS limit, before 137Gb 

Your BIOS will never see more than 33Gb of the drive but thats OK. The kernel should still see it all.

You still need to set LBA in the BIOS, not Auto.

```
RawCHS=16383/16/63, TrkSize=34902, SectSize=554, ECCbytes=4 
```

IS not correct.

The drive should report 16383/255/63, which is the fake full field value that drives bigger than the can report for old standards are supposed to use.

----------

## mv

 *NeddySeagoon wrote:*   

> You still need to set LBA in the BIOS, not Auto.

 

I retried this again, but still it doesn't change anything: hdparm -iI /dev/sdb still shows the same, and the kernel knows only /dev/sdb{1..11}, not /dev/sdb{12..14} (and attempting to mount /dev/sdb11 would probably again give errors - I do not try now).

Isn't there a "manual" way to tell the kernel the correct information? (Of course, it can be done by hacking the kernel source sufficiently, but I mean a less cumbersome way).

----------

## NeddySeagoon

mv

The Large Drive HOWTO is worth a read.

Set the jumpers on the drive for 33Gb clipping. Go here and get version 1 of the user manual to see how.

This makes the drive lie to the BIOS about its size but thats OK, its only telling the BIOS what it wants to see.

Linux will still see all of the drive.

----------

## mv

NeddySeagoon,

thank you very much!  Fortunately the jumper settings were printed on the harddisk (they were different than in the pdf).

I had never expected that this problem could have been caused by wrong jumper setting, but apparently this was the problem.

In fact, it appears that the setting was wrong (33GB clipping) from the very beginning!  :Embarassed:   (I just did not realize this, because with my previous main board (and another ide driver) the problem was not visible). Now even the BIOS shows the correct size in all modes.

----------

