CORRECTED - [Solved] [FreeNAS] Data Drive with 4096B sectors
Thank you to konstantin and agni for pointing out the errors in my tutorial. When I put together my tutorial I incorrectly copied my notes. I had been testing along the way to be sure that the number I was using for partition size was divisable by my block size. But I actually used bytes in my calculations. For those that used the origional tutorial you should not see any problems with performance with your partitions. They are still valid and lie on 4k boundaries. But, they are 3 blocks smaller. I have corrected it below. This is what I actually used for my drive. My drive(s) are only data drives. I do not boot from them. Sorry for the long post.
How to align, partition and format a drive on 4k boundaries using gpt and newfs
This tutorial is for increasing performance of the new hard drives with native 4k sectors. Specifically, it illustrates how to set up a data drive with only one GPT partition that is NOT bootable.
1) Get the physical characteristics of you drive from your drives firmware:
Code:
diskinfo -v ad4 <--- replace ad4 with your dive identifier
My drive is the 1.5 Western Digital Green model WD-15EARS
Here is the output for my drive using diskinfo:
Code:
/dev/ad4
512 #sector size
1500301910016 #media size in bytes (1.4T)
2930277168 #media size in sectors
2907021 #Cylinders according to firmware
16 #Heads according to firmware
63 #Sectors per track according to firmware
ad:WD-WMAVU1303392 #diskident
2) Find the start sector which will fall on a 4k boundary:
The slice/partition does nor start at the beginning of the drive. With no offset i.e. offset of 0 the slice would start at (63 * 512 = 32256) which is not at a 4k boundary. But when you add an offset of 1 you get:
Code:
(63 (from fdisk) + 1 (here)) * 512 = 32768, which is on 4k boundary
3) Find the Size of disk in bytes which is evenly divisable by 32768 byte blocks and will fall on a 4k boundary. And, then subtract the starting sector from above:
The drive reports 1500301910016 total bytes. I decided to use 32768B blocks because they are evenly divisible by 512B and 4096B. Unfortunately 32768 does not go into 1500301910016 evenly:
Code:
1500301910016 / 32768 = 45785580.75
The next lower number of bytes that 32768 will divide into evenly is 45785580.
Code:
45785580 * 32768 = 1500301885440
Now we need to subtract the 32768 from 1500301885440 to get actual size of partition in bytes less the starting sector (which is 64 and 64 * 512 is 32768):
Code:
1500301885440 - 32768 = 1500301852672
So, 1500301852672 are the total number of bytes for the partition. But, we need to convert that to 512 byte sectors for GPT.
Code:
1500301852672 / 512 = 2930277056
So, 2930277056 is the total size of the partition in 512 byte sectors.
4) I recommend clearing sector zero before creating your partition. WARNING: This will destroy all data on your drive. Be sure to unmount the drive if you have it mounted. If you did not use GPT to create your current partition.
Use this to clear sector zero:
Code:
dd if=/dev/zero of=/dev/ad4 bs=1M count=10
If you used GPT to create your partition(s) use this:
Code:
gpt destroy ad4 <--- replace ad4 with your dive identifier
5) Create an empty GPT partition:
Code:
gpt create ad4 <--- replace ad4 with your dive identifier
6) Align and create your partition:
Code:
gpt add –b 64 –s 2930277056 –t ufs /dev/ad4 <--- replace ad4 with your dive identifier
Note: If you get an error like:
Code:
The secondary GPT table is corrupt or invalid. Using the primary only -- recovery suggested
This may occur if you have attempted to partition your drive unsuccessfully or possibly for other reasons. To fix this type:
Code:
gpt recover ad4 <--- replace ad4 with your dive identifier
7) Format and label your drive:
Code:
newfs -S 4096 -b 32768 -f 4096 -O 2 -U -m 8 -o space -L datadrive /dev/ad4 <--- replace ad4 with your dive identifier
Note: The newfs example above uses UFS2 as the file system ("-O 2"). If you want to use UFS1 then use "-O 1".