# WD20EARS 4k disk



## aka_john (Oct 29, 2010)

Sorry, if this have been discussed before. But I still have several questions.

My hdd: WD20EARS-00MVWB0 51.0AB51

I've found 2 ways of formatting this disk:

`# diskinfo -v ada2`

```
ada2
        512             # sectorsize
        2000398934016   # mediasize in bytes (1.8T)
        3907029168      # mediasize in sectors
        0               # stripesize
        0               # stripeoffset
        3876021         # Cylinders according to firmware.
        16              # Heads according to firmware.
        63              # Sectors according to firmware.
        WD-WCAZA0385160 # Disk ident.
```

1:
`# gpart create -s mbr ada2`
`# gpart add -b 63 -s 3907029105 -t freebsd ada2`
`# gpart create -s bsd ada2s1`
`# gpart add -b 1 -s 3907029104 -t freebsd-ufs ada2s1`
`# gpart show`

```
=>        63  3907029105  ada2  MBR  (1.8T)
          63  3907029105     1  freebsd  (1.8T)

=>         0  3907029105  ada2s1  BSD  (1.8T)
           0           1          - free -  (512B)
           1  3907029104       1  freebsd-ufs  (1.8T)
```

2:
`fdisk -u ad9`

```
******* Working on device /dev/ad9 *******
parameters extracted from in-core disklabel are:
cylinders=3876021 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=3876021 heads=16 sectors/track=63 (1008 blks/cyl)

Do you want to change our idea of what BIOS thinks ? [n] 
fdisk: invalid fdisk partition table found
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 63, size 3907029105 (1907729 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 1;
        end: cyl 180/ head 15/ sector 63
Do you want to change it? [n] y
Supply a decimal value for "sysid (165=FreeBSD)" [165] 
Supply a decimal value for "start" [63] 64
Supply a decimal value for "size" [-387938190] 3907029104
fdisk: WARNING: partition does not start on a head boundary
fdisk: WARNING: this may confuse the BIOS or some operating systems
Correct this automatically? [n] 
Explicitly specify beg/end address ? [n] 
sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 64, size 3907029104 (1907729 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 2;
        end: cyl 180/ head 15/ sector 63
Are we happy with this entry? [n] y
The data for partition 2 is:
<UNUSED>
Do you want to change it? [n] 
The data for partition 3 is:
<UNUSED>
Do you want to change it? [n] 
The data for partition 4 is:
<UNUSED>
Do you want to change it? [n] 
Partition 1 is marked active
Do you want to change the active partition? [n] 

We haven't changed the partition table yet.  This is your last chance.
parameters extracted from in-core disklabel are:
cylinders=3876021 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=3876021 heads=16 sectors/track=63 (1008 blks/cyl)

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
    start 64, size 3907029104 (1907729 Meg), flag 80 (active)
        beg: cyl 0/ head 1/ sector 2;
        end: cyl 180/ head 15/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
Should we write new partition table? [n]
```

But there are still questions:
The second way (fdisk) end: cyl 180 while having cylinders=3876021(diskinfo)

For the both variants:

64 sectors * 512 B = 32768 B
64 sectors * 4096 B = 262144 B (512 sectors * 512 B)

The offset was taken as mush as 64. Is this correct? Or it should be 512.

Which of the methods (fdisk, gpart) is more correct? And (if possible) what is the difference?


----------



## salvo2002 (Nov 11, 2010)

I know this doesn't answer your question but this post is what I used to format my WD20EARS

http://forums.freebsd.org/showpost.php?p=76148&postcount=38


----------



## predi-ger-many (Dec 15, 2010)

hello,

it's so easy.

whe windows way x(

- insert a windows vista or 7 dvd (they handles 4k-drives correctly)
- start setup
- format the disk
- abort the setup
- insert a FreeBSD disk and start the fixit-environment
- run gpart show

you will see that windows creates the first partition starting at sector
2048 (= 4096 bytes = 4k).


```
==> gpart add -b 2048...
```

The easy way

block size of old disks: 512b
block size of 4k disks: 4096b

4096 / 512 = 8

you can use each starting block that you can devide by 8 (8, 16, 32, 64...)


```
==> gpart add -b 8...
```

recommendation:f

for first partition: gpart add -b 2048...
following partitions: gpart add -b "xxx/8"...

... it's easy. it's safe. it's alligned.

greetings
predi-ger-many


----------



## aka_john (Jan 7, 2011)

To *salvo2002*: There is no answer to my question. But there are some params for _newfs_
To *predi-ger-many*: I do not understand the sizes of offsets and calculations that you wrote.

So I desided to do my own calculations:

If we have "normal" disk: 64 sectors * 512  B = 32768 B
If we have "ears"   disk: 64 sectors * 4096 B = 262144 B
                          (or 512 sectors * 512 B)
So to have 64 sectors with 4k block size we have to do 512 sectors with 512B block size.


```
gpart create -s gpt ad9
gpart add -b 512 -t freebsd-ufs -l data1 ad9
newfs -U -O 2 -S 4096 -b 32768 -f 4096 ad9p1
```


----------



## predi-ger-many (Jan 8, 2011)

Hi,

I think you doesn't understand this.



			
				predi-ger-many said:
			
		

> The easy way
> 
> block size of old disks: 512b
> block size of 4k disks: 4096b
> ...



4k-disks only works internally with 4k-sectors. They are emulating 512b-sectors on the controller. 

4096 / 512 = 8 --> this calcs the emulation.

If you use my recommendation then your partitions are every aligned.

It's not required to understand all. It's required to do the right think. :e


----------



## aka_john (Jan 8, 2011)

Hi,

If I understand you right, 4k disks use blocks of 4096 sectors of 4096 Bytes each.
Is that correct?
Why then you suggest to make first partition of 2048 sectors (512 Bytes each).


----------



## predi-ger-many (Jan 9, 2011)

Hi,

4K-drives: 1 *physical* sector = 4 *Kilobytes*
512b-drives: 1 *phyiscal* sector = 512 *Bytes*

The emulation

I said that a 4k-drive emulates 512 byte sectors. The disk is seeing one *physical* sector (4 kb). This sector will be reported to OS as 8 *logical* sectors (each 512 bytes). The OS doesn't know that it is a 4k-drive. The OS is seeing a normal drive that uses sector with 512 b.

That's the cause I said that each partition should start on a sector that you can devide by 8.

You can also take a look at http://www.anandtech.com/show/2888. There you can see graphics that illustrate that.

The best practice

Start the first partion on sector 2048. All following partions should by start on a sector that you can devide by 8.

You can do that on 512b-drives, 4-drives and SSDs. You will every get a aligned partition with optimal performance!





I think now you understand it. 

regards
Predi


----------



## aka_john (Jan 13, 2011)

Thank you for your answers,

Everything is clear for me but for only 1 thing.
Why the first partition is to start from 2048? - It may start from 1096 or 512 or 32768, isn't it?

I just do not understand the purpose of such grate gap.
In case of "normal" disks we have our first partition from 63 sector. In our case we should start it from 64 sector. But if we have sector size 4096 this 64 sectors -> 512 sectors of 512b sector size.


----------



## ahavatar (Jan 14, 2011)

This is an off-topic question but I can't resist. 

Is there a way to check if a HDD is 4k-sector internally? Or is there some place where 4k drives are listed? I'd like to know if a HDD is 4k drive before purchase.


----------



## AndyUKG (Jan 14, 2011)

ahavatar said:
			
		

> Is there a way to check if a HDD is 4k-sector internally?



Look up the manufacturers specs on the HD you are interested in. Look for either the physical block size or whether the drive is described as using "advanced format".

ta Andy.


----------



## troberts (Jan 14, 2011)

predi-ger-many said:
			
		

> recommendation:f
> 
> for first partition: gpart add -b 2048...
> following partitions: gpart add -b "xxx/8"...
> ...


Is this recommendation for a disk that has FreeBSD only or does it pertain to a FreeBSD slice? I have a computer that came with Windows already installed so the first two partitions are already taken. I used GParted to shrink the Windows partition and GParted reports the following:

sda1 (Windows "d" (rescue) drive)
first sector 63
last sector 11324879

sda2 (Windows "c" drive)
first sector 11324880
last sector 93245439

unallocated/freed space
first sector 93245440

Using the recommendation above to find my starting sector, I subtract 2048 from the value of the starting sector in the unallocated space, then take the difference and divide by 8 to see if the answer is a whole number. If not, then I keep adding 1 until I get a whole number. Below is the math:

(93245440 - 2048) / 8 = 11655424

Since I got a whole number I can start my first partition at sector 93245440, correct? Does the starting point of the slice make a difference?


----------



## predi-ger-many (Jan 15, 2011)

troberts said:
			
		

> Is this recommendation for a disk that has FreeBSD only or does it pertain to a FreeBSD slice?



You can use this recommendation for BSD only system, for sliced systems and ZFS systems.



			
				troberts said:
			
		

> Since I got a whole number I can start my first partition at sector 93245440, correct?



Yes.



			
				troberts said:
			
		

> Does the starting point of the slice make a difference?



It's not required that the starting point of a slice is aligned. But the partitions that are included in the slice should be aligned.


----------



## predi-ger-many (Jan 15, 2011)

aka_john said:
			
		

> Everything is clear for me but for only 1 thing.
> Why the first partition is to start from 2048? - It may start from 1096 or 512 or 32768, isn't it?



An offset of 2048 is a *best practice* and it's an *recommendation*!!! The reason for this recommendation are SSDs. They are using "pyhsical" sector sizes up to 1 megabyte. If you use this recommendation is not necessary to know what "physical" sector size the disk is using. 2048 is ever aligned! 



			
				aka_john said:
			
		

> I just do not understand the purpose of such grate gap.
> In case of "normal" disks we have our first partition from 63 sector. In our case we should start it from 64 sector. But if we have sector size 4096 this 64 sectors -> 512 sectors of 512b sector size.



2048 logical sectors is only *ONE* megabtye. You can buy disk that are greater than 2 TB. 2 TB are 2.097.152 megabytes. Sorry but this gap is not big.


----------



## troberts (Jan 15, 2011)

predi-ger-many said:
			
		

> 2048 logical sectors is only *ONE* megabtye. You can buy disk that are greater than 2 TB. 2 TB are 2.097.152 megabytes. Sorry but this gap is not big.


My drive is 5 years old so does the information above still apply to my drive? If so, are the following formulas correct?

Partitions that are megabytes in size:
2048 x MB = partition size

Partitions that are gigabytes in size:
(2048 x 1024) x GB = partition size

2048 is one megabyte and there are 1,024 megabytes in a gigabyte so I multiply that number by how many gigabytes I want my partition.

While reading the GUID Partition Table on Wikipedia it mentions Windows XP cannot boot from GPT. The article also mentions 4096-byte sectors so now I am wondering if I can use gpart to create my partitions since Windows XP is installed. If I cannot use gpart, I should still be able to create partitions that are aligned properly, correct?


----------



## apollo567 (Jan 16, 2011)

Hello,
I have a question to this topic:

In FreeNAS these format problems are solved and automated, starting which FreeBSD version this is true for FreeBSD also ?

Kind Regards
apollo


----------



## predi-ger-many (Jan 16, 2011)

troberts said:
			
		

> My drive is 5 years old so does the information above still apply to my drive?



Yes.



			
				troberts said:
			
		

> While reading the GUID Partition Table on Wikipedia it mentions Windows XP cannot boot from GPT. The article also mentions 4096-byte sectors so now I am wondering if I can use gpart to create my partitions since Windows XP is installed. If I cannot use gpart, I should still be able to create partitions that are aligned properly, correct?



Well, XP can't boot from GPT. You need to use fdisk instead gpart to create non-gpt partitions.


----------



## aka_john (Jan 16, 2011)

predi-ger-many said:
			
		

> An offset of 2048 is a *best practice* and it's an *recommendation*!!! The reason for this recommendation are SSDs. They are using "pyhsical" sector sizes up to 1 megabyte. If you use this recommendation is not necessary to know what "physical" sector size the disk is using. 2048 is ever aligned!
> 
> 2048 logical sectors is only *ONE* megabtye. You can buy disk that are greater than 2 TB. 2 TB are 2.097.152 megabytes. Sorry but this gap is not big.



Thank you very much for explaining this. Now everyting is clear.

Best regards,
John


----------



## Nukama (Jan 16, 2011)

gpart() also supports MBR partition scheme. The g in gpart stands for GEOM(), not GPT.
`# gpart create -s mbr adx`


----------

