[FreeNAS] Data Drive with 4096B sectors

Data Drive with 4096B sectors

Thank you aragon I appreciate all of the help.

aragon saod: That might not be serious. Check if it created the label?

When I checked to see if the label was being created I found that there was an old label that I had created before I got the offset right. The offset was set to "0". The new label was not created. It seems like I am close to getting this but for this problem. Is there a utility that will let me delete the partition and start over?

aragon said: You really should use gpart(8). These old tools are probably on the chopping block.

I have been thinking about going to gpart. But, the install that I am working with is the embedded version of freeBSD. And, when I do:

Code:
pkg_add -r gpart

It appears that it is being installed. But, when I check it is not there. After some reading I discovered that the embedded version was not supposed to use pkg_add.

Note: My install of FreeBSD was via FreeNAS.
 
turb013 said:
Is there a utility that will let me delete the partition and start over?
Zero out the beginning of the disk with dd:

Code:
dd if=/dev/zero of=/dev/ad4 bs=1M count=10

As for gpart, it's part of FreeBSD base and not a port/package. It is not sysutils/gpart! If it's missing from FreeNAS then I guess they've removed it...
 
Data Drive with 4096B sectors

Thanks aragon. I had tried to use:

Code:
dd if=/dev/zero of=/dev/ad4 bs=1M count=10

earlier but I kept getting the error, "action not permitted". I finally figured out what the problem was. I had tried to unmount the drive but it would not let me. Finally, I figured out that the FreeNAS GUI had the mount point open. When I deleted the mount point I was able to use dd and was then able to use bsdlabel and newfs. I think I have it now. I have some simple benchmark results below:

Code:
Note: Numbers are all averages for three tries.

Copy a single 1.04GB file from Windows XP via SMB to the server.
512B sectors          4096B sectors          Percent Improvement
------------          -------------          -------------------
43 seconds            36 seconds             16.28%

Copy a single 1.04GB file from the server via SMB to Windows XP he server.
512B sectors          4096B sectors          Percent Improvement
------------          -------------          -------------------
36 seconds            28 seconds             22.22%

Copy a 7.91GB video.ts folder from Windows XP via SMB to the server.
512B sectors          4096B sectors          Percent Improvement
------------          -------------          -------------------
5:50                  4:24                   22.65%

Copy a 7.91GB video.ts folder from the server via SMB to Windows XP he server.
512B sectors          4096B sectors          Percent Improvement
------------          -------------          -------------------
4:29                  3:25                   23.79%
 
Data Drive with 4096B sectors

aragon said:
Code:
How did you switch between 512 and 4096 byte sectors? Hard drive jumper?

The drive has native 4096B sectors. It is 1.5 TB Western Digital Cavier Green model WD15EARS. Which is one of the new advanced format drives. Unfortunately, the drive reports 512B sectors to the BIOS. The only jumper related to the 512B sector situation is for telling the BIOS that the drive has 64 sectors per track. This is used for "alignment" in Windows XP.

The System is used as a backup and media server. It was designed with low power operation in mind.

ASUS AT3N7A-I MB
Intel Atom 330 Processor
NVIDIA ION graphics
1.5 TB Western Digital Caviar Green HD Model WD15EARS
Antec EarthWatts Green Model EA-430D
1 gig Geil 533GB Memory

Thank you aragon and mav@ for all of the help. I would be happy to give you any more information about this project you would like.
 
Yes thanks for providing all that information! I know the question was asked, but I didn't see an answer:

Does it matter if you are not putting down a partition table, just using bsdlabel on the raw drive?

I'm using ZFS with new WD drives and obviously there is no partitioning done before creating the pool. Is ZFS being impacted by the 4K sectors or does it not matter?
 
If you're putting a BSD label onto the raw disk device then it's just up to aligning your partition boundaries within the label correctly. That's a lot easier than with a BIOS partition table because you aren't also constrained to track alignment (63 sectors) anymore.

I don't know about ZFS.
 
Hi everyone, i have failed to see how this is solved.
I have one of these drives and FreeBSD and it looks like i simply cannot use it.

Drive is brand new , but i cannot find out anywhere how simply fdisk and label this darn thing.


UPDATE:
I finally swopped them out with non 4096 sector drives... Less hassle in end...
 
thavinci said:
Hi everyone, i have failed to see how this is solved.
I have one of these drives and FreeBSD and it looks like i simply cannot use it.

Drive is brand new , but i cannot find out anywhere how simply fdisk and label this darn thing.

If you are merely using it as a data drive only to be used by FreeBSD don't bother with fdisk(8), try some variation on # glabel label storage /dev/ad8 && newfs -U /dev/label/storage. Otherwise, there are tutorials about gpart, & such, if you search.
 
Thankx

Thank You!!

Much appreciated. I would like to know how this avoids the issues with the 4096B Sector Story and what if any repercussions are of using the drive like this.

Correct me if im wrong but is this whats called dedicated mode and there are in fact no partitions on this drive and will be impossible to share with another os?

I don't need this at all and the drive is only for storage so these questions are simply to understand more.

And Thank You Once Again
 
thavinci said:
Thank You!!

Much appreciated. I would like to know how this avoids the issues with the 4096B Sector Story and what if any repercussions are of using the drive like this.

Correct me if im wrong but is this whats called dedicated mode and there are in fact no partitions on this drive and will be impossible to share with another os?

I don't need this at all and the drive is only for storage so these questions are simply to understand more.

And Thank You Once Again

I believe (I do fully welcome being corrected) that it should start your filesystem with an offset of 0, and since there aren't any partition or slice boundaries for the drive controller and the operating system to fight about when reading or writing it should be a moot point.

I believe the old "dangerously dedicated" mode was slightly different, but this is every bit as incompatible with other operating systems. Especially since the label isn't going to be obvious to tools that assume wrongly.

I just realised that you can skip glabel(8) entirely and just # newfs -U -L labelname /dev/ad99. I don't know that this is practically any different from using glabel (except that it stores the label name in /dev/ufs/ instead of /dev/label/). Maybe makes it easier to see on older versions, I don't know.
 
Data Drive with 4096B sectors

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
   15003191006      #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

So the start sector will be 64.

3) Find the Size of disk in sectors which will fall on a 4k boundary:

The drive reports 2930277168 512B sectors. (even though the drive actually uses 4096B sectors). I decided to use 32768B blocks because they are evenly divisible by 512B and 4096B. Unfortunately 32768 does not go into 2930277168 evenly. The next lower number of sectors that 32768 divides into evenly is 2930245632. Because of the change from 2930277168 to 2930245632 I lose 31536 Bytes or 15.4 MB. (2930277168 - 2930245632 = 31536)

Now we need to subtract the 32768B above from 2930245632 to get actual size of partition in 512B sectors:
Code:
2930245632 - 32768 =  2930212864

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 2930212864 –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".
 
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.
Code:
63 * 512 = 32256

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".
 
Huh..... So does this mean using fronclynne's instructions won't make the drive operate correctly?!

Excuse my ignorance but im really not a drive expert and have never needed to deal with any of this..
 
FYI, this is my drive....

Code:
[root@gw2 /var/db/mysql]# diskinfo -v /dev/label/storage
/dev/label/storage
        512             # sectorsize
        1500301909504   # mediasize in bytes (1.4T)
        2930277167      # mediasize in sectors
        2907020         # Cylinders according to firmware.
        16              # Heads according to firmware.
        63              # Sectors according to firmware.
        WD-WCAVY2852332s0       # Disk ident.
Oh and...

Code:
ad16: 1430799MB <WDC WD15EARS-00S8B1 80.00A80> at ata8-master SATA300
 
Ok i need a mathematical degree to work this all out... :<

But luckily through turb013's guide i think i can literally just copy he's commands.

I really hope WD goes and dies, or alternatively make their drives report the correct info!
 
thavinci said:
Huh..... So does this mean using fronclynne's instructions won't make the drive operate correctly?!

Excuse my ignorance but im really not a drive expert and have never needed to deal with any of this..

Well, I'd be suspicious of my own advice, at least. If I can get ahold of one of these drives I'll try to run some tests, but thousands of others will probably get there first.

Hopefully they'll release a firmware patch that lets Real Operating Systems® see the underlying 4k sectors, but I'm not going to hold my breath.
 
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".

In regards to this after doing gpart it creates /dev/ad4p1 , now looking at this command, isnt it supposed to be

Code:
newfs -S 4096 -b 32768 -f 4096 -O 2 -U -m 8 -o space -L datadrive /dev/ad4p1

?

Regards
 
Hello,

Could you please advise me how to make the following changes to bootable drive. I mean how to create that "a:" partition as bootable?

Code:
# datadrive.cfg

8 partitions:
#         size      offset     fstype     [fsize     bsize    bps/cpg]
a:  2930212864           1     4.2BSD       4096     32768

Kind regards
 
What's about `disklabel -B /dev/...`? I just have doubts that single sector offset will be enough for boot loader. I would try 65 instead.
 
thanks for the detailed tutorial. I'm facing the same issue with a new WD drive with advanced format. However I use geli to encrypt the device. Do I have to face the problem on this layer? Or is it sufficient to aligne the partition/label inside the geli container?

regards - reily
 
Just curious, which is true?

- drive has poor performance, when using it with 512b sectors and typical performance when using 4096b sectors;
- drive has typical (for the class) performance when using 512b sectors and improved performance when using 4096b sectors;
- drive has poor performance when using non-4096b aligned I/O.

Whether the drive has (internal) format of 512b or 4096b should not matter, because ATA drives do not expose anything about their internals to the outside world. Also, modern drives do multi-sector PIO and DMA and it is unlikely they will work properly with an old ATA controller, that only supports single-sector transfers.

I also wonder, if the drive has to be 'told' to read on 4096b boundary, because it probably reads lots of adjacent sectors to internal buffer anyway.

Did you try to avoid the partition (slice) table altogether, as fronclynne suggested?

You really need slice (fdisk, gpt) table if you want to boot from the drive. Or perhaps if you plan to have multiple sets of partitions on it.
 
- drive has poor performance, when using it with 512b sectors and typical performance when using 4096b sectors;

I'll bet my money on this one. :)

If you write 512 bytes, the HDD would have to read 3.5KiB, then recalculate checksum and write 4KiB+ECC. Much slower than just writing 512 bytes without reading anything; like regular 512-byte sector drives do. Same thing your filesystem has to do when it wants to write 1 byte or change 1 byte; it has to read the sector size (512 bytes) containing that single byte; then update it by writing 512 bytes instead.
 
Going little off-topic, I really cannot imagine a modern drive, with their current recording density, to be able to read only 512bytes from the plate in single operation. :)

Back on-topic.

But I can imagine, that it may create performance issued if you have two modify requests for partial sectors, especially in NCQ is not in use.

Does FreeBSD issue read/write requests for single (512b) sectors? On UFS?
 
danbi said:
Just curious, which is true?

- drive has poor performance, when using it with 512b sectors and typical performance when using 4096b sectors;
- drive has typical (for the class) performance when using 512b sectors and improved performance when using 4096b sectors;
- drive has poor performance when using non-4096b aligned I/O..

I believe that poor performance when using 512B sectors and Typical performance with 4096B sectors is the best description. But, I have found reads to be faster (not a lot) in some situations when comparing drives with similar spin rates.


Whether the drive has (internal) format of 512b or 4096b should not matter, because ATA drives do not expose anything about their internals to the outside world.

This is not true try:
Code:
diskinfo -v ad4  <-- replace ad4 with your drive identifier

Code:
I also wonder, if the drive has to be 'told' to read on 4096b boundary, because it probably reads lots of adjacent sectors to internal buffer anyway.

According to Western Digital their Advanced Format drives use 4096B sectors natively. Take a look at the links below for a more technical explanation.

http://www.wdc.com/wdproducts/library/WhitePapers/ENG/2579-771430.pdf

http://www.anandtech.com/show/2888

Note: I have tried using fdisk, bsdlabel and gpt to partition my Advanced format drive. Of the three I got the best performance for my application using bsdlabel (My application is a power sipping NAS box using FreeNAS).
 
Back
Top