# Harddrive sector size



## tty23 (Dec 22, 2009)

Hi,

I just bought 4 Western Digital Caviar Green WD10EARS, which uses 4k sectors:
http://www.wdc.com/wdproducts/library/whitepapers/en/2579-771430.pdf

However, diskinfo reports 512byte sectors. I hoped FreeBSD would figure out the sector size stuff. Is there any way to correct this? I am using the disks in a ZFS raidz.


```
diskinfo -c ad12
ad12
	512         	# sectorsize
	1000204886016	# mediasize in bytes (932G)
	1953525168  	# mediasize in sectors
	1938021     	# Cylinders according to firmware.
	16          	# Heads according to firmware.
	63          	# Sectors according to firmware.
```


----------



## mav@ (Dec 23, 2009)

New ada disk driver and `camcontrol identify` on 8-STABLE should support such cases, but this wasn't tested yet, so feedback welcome.


----------



## tty23 (Dec 23, 2009)

Thanks for the quick reply, I will try that.
Well if I master the kernel compilation stuff


----------



## tty23 (Dec 23, 2009)

Hi,

I ran camcontrol identify on the drive, but I cannot see any useful information
in the output. Also in the man pages, I did not find anything to resolve the problem.
Now I am a newbie when it comes to harddrive details, do I miss something?

Diskinfo still reports a 512byte sector size with the new ahci driver.


```
pass0: <WDC WD10EARS-00Y5B1 80.00A80> ATA/ATAPI-8 SATA 2.x device

protocol              ATA/ATAPI-8 SATA 2.x
device model          WDC WD10EARS-00Y5B1
firmware revision     80.00A80
cylinders             16383
heads                 16
sectors/track         63
LBA supported         268435455 sectors
LBA48 supported       1953525168 sectors
PIO supported         PIO4
DMA supported         WDMA2 UDMA6 
overlap not supported

Feature                      Support  Enable    Value           Vendor
write cache                    yes      yes
read ahead                     yes      yes
Native Command Queuing (NCQ)   yes              31/0x1F
Tagged Command Queuing (TCQ)   no       no      31/0x1F
SMART                          yes      yes
microcode download             yes      yes
security                       yes      no
power management               yes      yes
advanced power management      no       no      0/0x00
automatic acoustic management  yes      no      254/0xFE        128/0x80
```


----------



## mav@ (Dec 23, 2009)

There should be line like:
sector size    logical 512, physical 4096, offset 0
Probably it was added after you updated sources last time.

But I think disk will still report logical sector size of 512 bytes to keep compatibility with legacy software. The only effect you may get now is that ada driver report physical sector size to GEOM via existing mechanism, allowing upper layers to use it somehow. I have no idea whether ZFS able to use that info. UFS and usual disk partitioning tools doesn't yet. Probably with appearance of such devices, work in this area should activate.


----------



## mav@ (Dec 24, 2009)

I've just implemented in HEAD some missing parts of the stripe info path from disk via GEOM RAIDs to user-level. Now diskinfo able to report stripe size and offset for any device and partition. I'll merge it later.

Now all questions left to partitioning tools and FS maintainers to make this info used without user interference. It should be easy to implement automatic partitions alignment.


----------



## tty23 (Dec 27, 2009)

I just installed FREEBSD-8 STABLE and ran `camcontrol identify ada0`,
it reports 512byte sectors instead of 4k. Maybe this is some kind of
compatibility feature of the drive? Or do I need to install CURRENT?


```
pass0: <WDC WD10EARS-00Y5B1 80.00A80> ATA-8 SATA 2.x device
pass0: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO size 8192bytes)

protocol              ATA/ATAPI-8 SATA 2.x
device model          WDC WD10EARS-00Y5B1
firmware revision     80.00A80
cylinders             16383
heads                 16
sectors/track         63
sector size           logical 512, physical 512, offset 0
LBA supported         268435455 sectors
LBA48 supported       1953525168 sectors
PIO supported         PIO4
DMA supported         WDMA2 UDMA6 
overlap not supported

Feature                      Support  Enable    Value           Vendor
read ahead                     yes	yes
write cache                    yes	yes
flush cache                    yes	yes
Native Command Queuing (NCQ)   yes		31/0x1F
Tagged Command Queuing (TCQ)   no	no	31/0x1F
SMART                          yes	yes
microcode download             yes	yes
security                       yes	no
power management               yes	yes
advanced power management      no	no	0/0x00
automatic acoustic management  yes	no	254/0xFE	128/0x80
media status notification      no	no
power-up in Standby            yes	no
write-read-verify              no	no	0/0x0
unload                         no	no
free-fall                      no	no
```


----------



## tty23 (Dec 27, 2009)

Sorry, I just saw that I missed your part on the compatibility stuff. So I will just use the disk as it is and wait for the next release 

Is there anything I can do to help you (the FreeBSD developers) on this issue?


----------



## mav@ (Dec 29, 2009)

Try to apply such a patch to camcontrol to get raw identify information from the drive:

```
--- camcontrol.c.prev   2009-11-26 11:44:11.000000000 +0200
+++ camcontrol.c        2009-12-26 23:37:42.000000000 +0200
@@ -1348,6 +1350,13 @@ ataidentify(struct cam_device *device, i
        ata_bpack(ident_buf->media_serial, ident_buf->media_serial,
            sizeof(ident_buf->media_serial));
 
+       for (i = 0; i < sizeof(struct ata_params) / 2; i++) {
+               if ((i % 10) == 0)
+                   fprintf(stdout, "\n%3d: ", i);
+               fprintf(stdout, "%04x ", (uint16_t)ptr[i]);
+       }
+       fprintf(stdout, "\n");
+
        fprintf(stdout, "%s%d: ", device->device_name,
                device->dev_unit_num);
        ata_print_ident(ident_buf);
```


----------



## tty23 (Jan 1, 2010)

I added the lines manually, I hop I did it right.

`# camcontrol identify ada1`



```
0: 427a 3fff c837 0010 0000 0000 003f 0000 0000 0000 
 10: 4457 572d 4143 3556 3235 3632 3338 0034 0000 0000 
 20: 0000 0000 0032 3038 302e 4130 3038 4457 2043 4457 
 30: 3031 4145 5352 302d 5930 4235 0031 0000 0000 0000 
 40: 0000 0000 0000 0000 0000 0000 0000 8010 0000 2f00 
 50: 4001 0000 0000 0007 3fff 0010 003f fc10 00fb 0110 
 60: ffff 0fff 0000 0007 0003 0078 0078 0078 0078 0000 
 70: 0000 0000 0000 0000 0000 001f 1706 0000 0044 0040 
 80: 01fe 0000 746b 7f61 4123 7469 bc41 4123 407f 0066 
 90: 0066 0000 fffe 0000 80fe 0000 0000 0000 0000 0000 
100: 6db0 7470 0000 0000 0000 0000 0000 0000 5001 4ee2 
110: 5913 e513 0000 0000 0000 0000 0000 0000 0000 4018 
120: 4018 0000 0000 0000 0000 0000 0000 0000 0029 0000 
130: 0000 0000 0000 16ce 0000 0000 0000 0000 0000 0000 
140: 0000 0000 0004 0000 0000 0000 0000 0000 0000 0000 
150: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
160: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
170: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
180: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
190: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
200: 0000 0000 0000 0000 0000 0000 3031 0000 0000 0000 
210: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
220: 0000 0000 101e 0000 0000 0000 0000 0000 0000 0000 
230: 0000 0000 0000 0000 0001 1000 0000 0000 0000 0000 
240: 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 
250: 0000 0000 0000 0000 0000 a4a5 
pass1: <WDC WD10EARS-00Y5B1 80.00A80> ATA-8 SATA 2.x device
pass1: 300.000MB/s transfers (SATA 2.x, UDMA6, PIO size 8192bytes)

protocol              ATA/ATAPI-8 SATA 2.x
device model          WDC WD10EARS-00Y5B1
firmware revision     80.00A80
cylinders             16383
heads                 16
sectors/track         63
sector size           logical 512, physical 512, offset 0
LBA supported         268435455 sectors
LBA48 supported       1953525168 sectors
PIO supported         PIO4
DMA supported         WDMA2 UDMA6 
overlap not supported

Feature                      Support  Enable    Value           Vendor
read ahead                     yes	yes
write cache                    yes	yes
flush cache                    yes	yes
Native Command Queuing (NCQ)   yes		31/0x1F
Tagged Command Queuing (TCQ)   no	no	31/0x1F
SMART                          yes	yes
microcode download             yes	yes
security                       yes	no
power management               yes	yes
advanced power management      no	no	0/0x00
automatic acoustic management  yes	no	254/0xFE	128/0x80
media status notification      no	no
power-up in Standby            yes	no
write-read-verify              no	no	0/0x0
unload                         no	no
free-fall                      no	no
```


----------



## mav@ (Jan 3, 2010)

There should be some jumper on the drive, controlling it's behavior. Haven't you tried to move it?


----------



## tty23 (Jan 4, 2010)

Yes, there are some jumpers on the drive, but unfortunately there is no
documentation on what they do (except for one, who should be set for
WindowsXP compatibility).


----------



## tty23 (Jan 4, 2010)

I just googled around a bit, and it seems (as you said), that the drives do not announce the 4k sectors to the OS.
I now opened a support request at WDC. Hopefully they will give some information on the jumper settings.


----------



## zapher (Jan 4, 2010)

I don't know if I'm missing the point. But the pdf you posted says: 





> Many disk drive interface technologies already allow for increased sector sizes. However, the 512-byte sector has been the standard for over 30 years. As a result, many points in a computer system (systems like personal computers, servers, DVRs, PSPs, and cell phones) have become inflexible and only work using 512-byte sectors. To maintain compatibility with these devices, Advanced Format media emulates a 512-byte device by maintaining a 512-byte sector at the drive interface.



My interpretation is that the 4KB is not something the system has to deal with. It's an internal drive geometry. And by "tricking" the system it's 512B-sectors allows for longer ECC and less padding between sectors. Ergo - more bytes per space.

As I said, I'm sorry if I missed the point entirely. And I can see why the question on how to change sector size is still valid, although these drives seem to overcome the issue.


----------



## tty23 (Jan 4, 2010)

Yes, I think you are right zapher, it seems that with this thread, I missed the point entirely 

However, I asked at WDC if it is possible to announce the 4KB sector size to the OS by a jumper setting. So hopefully, this was not all in vain.


----------



## zapher (Jan 4, 2010)

Discussion is almost never in vain 

Go play with your disk now. It's feeling all lonely and hollow


----------



## mav@ (Jan 4, 2010)

Latest ATA specifications allow drive to announce both logical and physical sector sizes. While logical have to stay 512 bytes for compatibility reasons, physical one can be reported 4K as-is. It would allow OS to self-tune to it better, not just aligning on some "magic" "lucky" offset, as Vista+ do.


----------



## J65nko (Jan 5, 2010)

For a similar discussion on the OpenBSD misc mailing list see: http://www.mail-archive.com/misc@openbsd.org/msg84625.html


----------



## phoenix (Jan 5, 2010)

tty23 said:
			
		

> Yes, there are some jumpers on the drive, but unfortunately there is no documentation on what they do (except for one, who should be set for WindowsXP compatibility).



If these are the WD Green drives, the documentation is on the drive itself.  

And there's details on how it all works on anandtech and tomshardware.


----------



## tty23 (Jan 5, 2010)

> If these are the WD Green drives, the documentation is on the drive itself.


Yep, that what I meant with 


> (except for one, who should be set for WindowsXP compatibility).


----------



## semi-ambivalent (Jan 6, 2010)

*The Register has a brief take on this*

For those that don't have these drives there's a bit of info on them at:

http://www.theregister.co.uk/2009/12/14/wd_advanced_format/

sa


----------



## Zap (Jan 16, 2010)

I also have a problem with 4096 sector size on Transcend StoreJet 18M external USB drive. I tried to install FreeBSD 8.0 stable on this external drive for easy future maintenance.
The sysinstall fdisk reported 8 times lower size. As I was convinient even with that size I tried to make a slice. Then I partitioned it and tried to write the changes. What I got was an error: Unable to make device node for /dev/da0s1a. I couldn't go any further with install.
dmesg reports correct data for the disksize and sector size as does diskinfo.
Livefs fdisk exits with error "could not detect sector size".
What else should I try or how can I help the developers to fix it?


----------



## jem (Jan 19, 2010)

tty23 said:
			
		

> Yes, there are some jumpers on the drive, but unfortunately there is no documentation on what they do (except for one, who should be set for WindowsXP compatibility).



Maybe it's this "Windows XP compatibility" mode that forces the drive to report 512 byte sectors.  Try removing it and see what is reported to camcontrol afterwards.


----------



## mav@ (Jan 20, 2010)

I've just compared identify data with and without jumper installed. There is no any difference. Crap!


----------



## p5ycho (Jan 22, 2010)

jem said:
			
		

> Maybe it's this "Windows XP compatibility" mode that forces the drive to report 512 byte sectors.  Try removing it and see what is reported to camcontrol afterwards.



I'm willing to bet that this jumper aligns the 4K sectors to the default partition alignment on XP systems. Vista and above align partitions on an offset of exactly 2048 sectors from the start of the drive. XP and earlier use sector 63 i believe, which is not a multiple of 4KB.

So, either use XP compatibility with a default partition alignment, or align all your partitions on 1MB boundaries for compatibility with probably every known partitioning and/or raid stripe (including software raid) and remove the XP compatibility jumper.


----------

