[FreeNAS] Data Drive with 4096B sectors

Hello, I am new to FreeBSD and I was wondering if anyone could tell me how set up a data drive with 4096B sectors. This will be a data only drive. And it will be 1.5 terabytes. I have tried to get the geometry to use 4096B sectors but no matter what I do I wind up with 512B sectors. I am assuming that I need to use fdisk to set up the geometry but I can't figure out how to set up 4096B sectors. Then I need to use newfs to format the drive. And finally I believe I will need to use BSDlabel to label and create the partition. I have tried using the following command for newfs:

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

But, I still don't get 4096B sectors. This is the output from 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 according to firmware
   ad:WD-WMAVU1303392   #diskident

Also, when I tried to set up this disk I attempted to do it from the FreeBSD
install DVD. I would like to do it now from the command line. Any help will be
appreciated.
 
Discinfo will allways report 512k because the disc lies to the OS. Not to mention that you can have XYZ sector size on disk and ZYX on partition, they are not the same thing, but you should use matching size for performance reasons.
 
Data Drive with 4096B sectors

My drive is one of the new advanced format drives. It has 4096B sectors native.
That is why I want to format it to 4096B sectors. Can you tell me how to to this?
 
I have been reading about this as well. The problem is that the drive still presents itself to the OS as having 512B sectors. The only thing you need to do is make sure you create partitions on 4K boundaries and you won't have performance issues.
 
SSDs have similar partition boundary requirements, and I wrote this script which helps calculate the correct byte offsets that fall on both the SSD erase boundary and the 63 sectors/track boundary.

Code:
#!/bin/sh

# erase boundary in 512 byte blocks
# eg. for a 128KiB erase boundary:
# 131072 / 512 = 256
ERASEB=256

echo "enter byte offset of partition"
read boffset

if [ -z "${boffset}" ]; then exit 1; fi

if [ ${boffset} -lt $(( ${ERASEB} * 512 )) ]; then
	ssdlbahigh=$(( ${ERASEB} * 63 ))
	ssdlbalow=0
else
	sectors=$(( ( ${boffset} - ( ${boffset} % 512 ) ) / 512 ))
	stb=$(( ${sectors} - ( ${sectors} % 63 ) ))
	ssderr=$(( ${stb} % ${ERASEB} ))
	ssdlbahigh=$(( ${stb} + ( ${ssderr} * 63 ) ))
	ssdlbalow=$(( ${stb} - ( ( ${ERASEB} - ${ssderr} ) * 63 ) ))
fi

echo
echo "Corrected offsets:"
echo "High: ${ssdlbahigh} blocks, $(( ${ssdlbahigh} / 63 )) tracks @ 63 s/t ($(( ${ssdlbahigh} * 512 )) bytes)"
echo "Low: ${ssdlbalow} blocks, $(( ${ssdlbalow} / 63 )) tracks @ 63 s/t ($(( ${ssdlbalow} * 512 )) bytes)"

You need to set ERASEB to 8 for your 4096 byte boundary.
 
Data Drive with 4096B sectors

Sylgeist said:
I have been reading about this as well. The problem is that the drive still presents itself to the OS as having 512B sectors. The only thing you need to do is make sure you create partitions on 4K boundaries and you won't have performance issues.

Thank you Sylgeist I appreciate your input. There is much discussion about the 4K drives that are recently arriving. I have been trying to get my head around the particulars for a short time. And, I must admit that I am new to FreeBSD. I believe that when you talk about partitions in this case you are talking about slices. This is a new concept for me. But, what you say about 4K boundaries makes things clearer for me. As I understand it FreeBSD and many other OS's place there MBR at Sector zero. And, theoretically the entire boot code can reside in that first sector. But, this depends on the boot loader used. But, I would be safe to start my first partition at sector eight which would be the first 4k boundary after, given that at least one 512B sector is used by the MBR. Then as long as my partitions are a multiple of eight I won't wind up with misaligned logical sectors with regard to the physical sectors of the "Advanced Format Drive" I am using.

I was wondering if I was just going to use this drive as a data drive would GPT be better than MBR in this case? I am guessing that the slice table still needs one of them even without boot code or an active partition? And, it needs to be at sector zero.

aragon wrote:
You need to set ERASEB to 8 for your 4096 byte boundary.

Thanks aragon I will give it a try.

When I finally get this done I will post some simple before and after disk benchmarks.
 
Data Drive with 4096B sectors

I attempted to set up my single data partition on 4k boundarys but fdisk wanted to use sector 63 for the start offset. And, it changed the size of the partition from 3662880 to 3662001. Neither of these fall on the 4k boundary. Am I missing something?

This is the fdisk configuration file I used:
Code:
# datadrive.cfg
# datadrive fdisk configuration file
# usage - single partition data only drive
#	fdisk -f datadrive.cfg ad4
g c2907021 h16 s63
p 3 0 0 0
p 2 0 0 0
p 1 165 8 3662880

This is the command line that I used:
Code:
fdisk -f datadrive.cfg -itv ad4

This was the output:
Code:
fdisk: WARNING: adjusting start offset of partition 1
     from 8 to 63, to fall on a head boundary
fdisk: WARNING: adjusting size of partition 1 from 3662880 to 3662001
     to end on a cylinder boundary
parameters extracted from in-core disklabel are:
cylinders=2907021 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=2907021 heads=16 sectors/track=63 (1008 blks/cyl)

Information from DOS bootblock is:
1: sysid 165 (0xa5),(FreeBSD/NetBSD/386BSD)
      start 63, size 3662001 (1788 Meg), flag 0
            beg: cyl 0/ head 1/ sector 1;
            end: cyl 560/ head 15/ sector 63
2: <UNUSED>
3: <UNUSED>
4: <UNUSED>
When I do:
Code:
diskinfo -v ad4
I get:
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

My harddrive is a 1.5 TB Western Digital Cavier Green model WD15EARS. What am I doing wrong? Any help will be appreciated.
 
Data Drive with 4096B sectors

aragon Can you try use gpart instead?

I am looking into it. I only just now managed to get a small understanding of fdisk. I am hoping someone can tell me what I am missing with fdisk.
 
It is not necessary to do alignment on fdisk level. It may be easier to to it later on disklabel level. So let fdisk do it's ugly 63 sector thing, you can compensate it later with disklabel.
 
Data Drive with 4096B sectors

Thank you for the reply mav@.

mav@ said:
It is not necessary to do alignment on fdisk level. It may be easier to to it later on disklabel level. So let fdisk do it's ugly 63 sector thing, you can compensate it later with disklabel.

I will read up on it in the morning to try to figure out how to use it. I guess I don't understand what the purpose of fdisk is if another utility is needed to create the slice?

I was working with fdisk some more earlier tonight and I realized that the size I had used (3662880) was for 4K sectors. I should have used (2930277168) 512B sectors which is the actual number of sectors in my drive. Also, I set the start sector to 0 to see of that would work. It did seem to work. But, the 2930277168 size did not work. Fdisk only saw it as 2147483647 which is the upper limit for 4 byte integers. It then adjusted that down to 2147483520 which is end of the nearest cylinder boundary. Consequently, it was not using the entire drive for the partition.
 
fdisk needed only for compatibility with other OSes. It is OK to use disklabel over the physical disk. I personally do so when possible. I am not sure if it is possible to use fdisk without disklabel for boot partitions.
 
For booting I think a bsdlabel is required... it contains boot1+boot2 stage code AFAIK?

Doing this with the label is possibly easier. I think you'll need to start partition "a" at 512 bytes offset from the start of the label. That should fall on byte offset 32768 of the physical disk. (label would start at start of second track, or 63*512 bytes)
 
Data Drive with 4096B sectors

Thanks mav@ I will give BSDlabel a try.

aragon said:
I think you'll need to start partition "a" at 512 bytes offset from the start of the label. That should fall on byte offset 32768 of the physical disk. (label would start at start of second track, or 63*512 bytes)
Thanks aragon, I see that 32768 is at a 4k boundary. If I understand BSDlabel correctly I would use the following settings for my drive:
Code:
# datadrive.cfg
8 partitions:
	 #	       size	 offset    fstype   [fsize bsize bps/cpg]
	   a:	 2930277168	  32768    4.2BSD     4096 32768      ???
I am not sure what to use for bps/cpg. How would I go about determining the number of cylinders in a cylinder group? And, can BSDlabel handle 64bit integers (ie. for the size)? Also, will I need to delete the current partitions before I use BSDlabel?

I believe the BSDlabel command line would look something like this:
Code:
bsdlabel -w ad4 -f datadrive.cfg

Then I would format the drive with:
Code:
newfs -S 4096 -b 32768 -f 4096 -O 2 -U -m 8 -o space / dev/ad4
 
bsdlabel's offset measured from the odd (63*512) fdisk's partition beginning. So to allign it you should add 512 to the 32768. Last three fields are not required to fill.
 
mav@ said:
bsdlabel's offset measured from the odd (63*512) fdisk's partition beginning. So to allign it you should add 512 to the 32768. Last three fields are not required to fill.
Don't you think just 512 is enough? 63*512 = 32256, 32256+512 = 32768. So an aligned label could look like this:

Code:
	 #	       size	 offset    fstype   [fsize bsize bps/cpg]
	   a:	 2930277168	  1    4.2BSD

(offset 1 for 1 block of 512 bytes)
 
Data Drive with 4096B sectors

My understanding of offsets are limited. But, I believe that the offset is the starting sector. As far as I can see neither and offset of 1 or 33280 are on a 4k boundary right?
 
Data Drive with 4096B sectors

Thank you for your input mav@!

OK I have three questions:

Is the offset necessary in order to leave room for the slice table?

Am I right when I say that an offset of 1 will not be on a 4k boundary?

Is BSDlabel able to handle 64bit integers? I ask because 2930277168 (the number of physical sectors on my drive) needs a 64 bit integer to hold it. And, I have read that some of the FreeBSD utilities are only capable of using 32bit integers. I ran into this problem with fdisk.
 
turb013 said:
Is the offset necessary in order to leave room for the slice table?
You're not leaving room for the slice table, you're aligning to 4K. The BSD label doesn't start at the start of the disk, it starts at the start of the slice, ie. offset 0 is after the slice table at the beginning of the slice.

turb013 said:
Am I right when I say that an offset of 1 will not be on a 4k boundary?
No...


turb013 said:
Is BSDlabel able to handle 64bit integers? I ask because 2930277168 (the number of physical sectors on my drive) needs a 64 bit integer to hold it. And, I have read that some of the FreeBSD utilities are only capable of using 32bit integers. I ran into this problem with fdisk.
Should be fine, but you could use K, M, and G notation too. See bsdlabel(8), eg:

Code:
	 #	       size	 offset    fstype   [fsize bsize bps/cpg]
	   a:	       1024G	  1    4.2BSD
 
Data Drive with 4096B sectors

Thank you mav@ and aragon. I think I am close to getting this done. The problem I am having now is that when I run:

Code:
bsdlabel -w /dev/ad4 datadrive.cfg

I get: unknown disk type
 
You're using invalid syntax. There is no disk type called "datadrive.cfg". What are you trying to accomplish? I'm guessing this:

Code:
bsdlabel -R /dev/ad4 datadrive.cfg
 
Data Drive with 4096B sectors

Thanks again aragon. That took care of the "unknown disk type" error. But, now when I use:

Code:
bsdlabel -R /dev/ad4 datadrive.cfg

I get:

Code:
 Geom not found : "ad4"
 
Back
Top