# ZFS pool, 4k sectors, and the need for gpart.



## dev_null (Jan 26, 2014)

Hello
I have 9 drives, 6 are WD 3TB and 3 are 3TB Seagate NAS drives. I have set up a pool of 3 3-drive raidz vdevs. I noticed that these are showing ashift of 9 even though they are advanced format drives (I understand that some drives "lie"), so I started investigating and found this FreeBSD hack:


```
gnop create -S 4096 /dev/da0
zpool create media raidz2 da0.nop da1 da2 da3 da4 da5 da6 da7
zpool export media
gnop destroy /dev/da0.nop
zpool import media
```

That said, I am also seeing the same hack on other sites, but people are using gpart to create properly aligned partitions first.

I am just using whole disks. Is creating properly aligned partitions on the drives first necessary or can I just perform the hack above (modified for my raidz vdev setup), ensuring I have ashift=12, and create my pool without partitioning with gpart first?

Thanks!


----------



## wblock@ (Jan 26, 2014)

A drive with no partitions is automatically aligned, because no matter how big the hardware block size, they all start at the first block.


----------



## dev_null (Jan 26, 2014)

Thanks for the reply. Just to be clear, there is no need to create partitions then?

Thanks.


----------



## wblock@ (Jan 26, 2014)

Not for alignment when using the whole disk, no.


----------



## ralphbsz (Jan 27, 2014)

wblock@ said:
			
		

> A drive with no partitions is automatically aligned, because no matter how big the hardware block size, they all start at the first block.


While you are probably correct in practice, in theory this doesn't have to be true.  The IO standards allow the first block of a disk to be smaller than a regular block.  This was done so that in the standard Windows MBR-based layout, the C-disk happens to fall on 4KB alignment.  One place where this is visible is in the standard definition of the SCSI read capacity(16) command: In the newest standards, bytes 14 and 15 of the response to that command return the LBA of the first full-size aligned block.  If I remember right, Rob Elliot (the HP representative to the SCSI standard committee) had a nice writeup on this; probably in the SCSI T10 archives somewhere.

To check, on Linux with SCSI disks use `sg_readcap --16 /dev/sdxx`, and look for "lowest aligned logical block address" in the output.  It should be zero (and is on all disks I have access to).  On my FreeBSD machine, I can only check how to do with with ATA disks (no SCSI disks at home): Use `camcontrol inquire adax`, and look for the "offset" in the sector size line.

I don't know whether there are any currently shipping drives that still have that odd-sized first block, nor whether any of these odd drives every shipped in the open market for replacement disks (they may have all gone to OEMs that build Windows machines).  I've never seen an unaligned drive in the wild.  But still today, lots of software checks whether the blocks on disk start their correct alignment at sector 0 or not.


----------



## wblock@ (Jan 27, 2014)

Interesting!  I've never encountered one of those drives, but if I do now it will be far less mystifying.  Thanks!


----------



## dev_null (Jan 27, 2014)

Thanks for the good information!

For the record:

root@Baka:/Zpool # camcontrol identify da0 | grep offset
sector size           logical 512, physical 4096, offset 0

I am guessing you meant that offset above. 

I went ahead and checked all my disks and got similar output. I performed the hack successfully without creating partitions first (just used the drives) and things are working smoothly. Hopefully others can benefit from this post.


----------

