Data Drive with 4096B sectors
This tutorial uses the freeBSD command "BSDlabel" to align and partition a drive. I
then used the freeBSD command "newfs" to format the drive.
Just to clarify what this is about precisely, I am referring to the new
hard drives that use 4096B (4K) sectors as opposed to more traditional
512B sectors. Currently, the Western Digital Green drives with "wears"
in their model number are examples of 4K sector drives. And, this "how to"
will show you how to align your partition to 4K boundaries and format the
drive to 4K sectors. This will give you the best performance.
I used the freeBSD command "BSDlabel" to align and partition my drive. I
then used the freeBSD command "newfs" to format the drive.
The first step is to determine the physical characteristics of your drive.
To do this type the following command into your console:
Code:
diskinfo -v ad4 <-- replace ad4 with your drive identifier
You will get something like this:
Code:
/dev/ad4
512 # sector size
15003191006 #media size in bytes (1.4T)
2930277168 #media size in sectors
2907021 #Cylinders according to firmware
16 #Heads according to firmware
63 #Sectors according to firmware
ad:WD-WMAVU1303392 #diskident
Notice that the drive reports that it uses 512B sectors when it actually uses
4096B sectors. This does not make this process any easier. Are you listening
Western Digital?
The first thing we want to take a look at is the reported media size in sectors.
The drive reports that for my drive (The Western Digital 1.5 gig WD-15EARS) it
has a total of 2930277168 512B sectors (your drive may have a different number
if it is for example a 2 terabyte drive) . I choose to use a block size of 32768
because it is evenly divisible by both 512 and 4096. So the next step I took was
to divide 2930277168 by 32768.
Code:
2930277168 / 32768 = 89424.96240234375
Obviously, 32768 does not divide evenly into 2930277168. So to get the largest
number of 512B sectors that would be evenly divisible by 32768 I simply took
89424 (the integer part of 89424.96240234375) and multiplied it by 32768.
Code:
89424 * 32768 = 2930245632 <-- We will use this number to calculate the
size of the drive in sectors. The number we come up with will be the size
parameter needed by "BSDlabel".
Those who are paying attention will notice that I am not using the entire drive:
Code:
2930277168 - 2930245632 = 31523 <-- Approximately 15.4 MB at the end of the
drive are not being used. For me the performance gains are worth the loss of
a few megabytes on a 1.5 terabyte drive.
Before we can get a final size we need to determine the offset. When "BSDlabel"
creates a slice/partition it does not start it at the first sector it starts it
at sector 63.
So in order to align the start of the slice/partition to a 4K boundary you need
an offset of 1 (512B sector).
Code:
32256 + 512 = 32768 <-- 4K boundary since 32768 can be evenly divided by 4096
So now that we have the major parameters for "BSDlabel" we need to make a
configuration file. I called mine datadrive.cfg. It is a simple text file. But,
it requires the parameters to be presented in the following format (Lines starting
with "#" are comments):
Code:
# datadrive.cfg
8 partitions:
# size offset fstype [fsize bsize bps/cpg]
a: 2930212864 1 4.2BSD 4096 32768
In this example I created a single data partition covering the entire drive. And, it is
not a boot partition. The first parameter is the slice/partition name "a:". The second
parameter is the size of the partition in 512B sectors. The number I used is 2930245632
minus 32768. This is because I had to subtract the start sector of the slice/partition
(sector 63) plus the offset (one 512B sector). We lost another 512B of space of the
total drive space here...Oh well
Code:
63 * 512 = 32256
32256 + 512 = 32768
2930245632 - 32768 = 2930212864 <-- sector size of my 1.5TB drive)
The next parameter is the file system type (fstype) here I used 4.2BSD. The last three
parameters are not required. But, I used 4096 for the fragment size (fsize) and 32768
for the block size (bsize). Once you have created this file you are ready to use "BSDlabel"
to create your slice/partition and align the drive. Here is the command line:
Code:
bsdlabel -R /dev/ad4 datadrive.cfg <-- Replace ad4 with your drive identifier
Note: You will not be able to create this slice if the drive you are creating it on is
mounted.
See FreeBSD man pages BSDlabel(8) for more information on "BSDlabel".
The next step is to format the drive with "newfs". Here is the command line that I used:
Code:
newfs -S 4096 -b 32768 -f 4096 -O 2 -U -m 8 -o space -L datadrive /dev/ad4
Note: The newfs example above uses UFS2 as the file system ("-O 2"). If you want to use UFS1 then use "-O 1".
Details:
Code:
-S 4096 = sector size
-b 32768 = block size
-f 4096 = fragment size
-O 2 = UFS2 file system
-U = Enable soft updates on the new file system
-m 8 = The percentage of space reserved from normal users; the minimum
free space threshold.
-o space = Optimize for space rather than time
-L datadrive = Label the drive as "datadrive"
/dev/ad4 = This is your drive identifer.
See FreeBSD man pages newfs(8) for more information on "newfs".