FreeBSD and 4k sector drives

HOWTO

by ross at 18:07:41 on April 2, 2015

Partition table

gpart has -a parameter which sets alignment. All you have to do is add -a 4k to your usual gpart commands (and do not use -b parameter):

# gpart create -s gpt ada0
# gpart add -a 4k -s 64k -t freebsd-boot -l newboot0 ada0
# gpart add -a 4k -s 4G -t freebsd-swap -l newswap0 ada0
# gpart add -a 4k -t freebsd-zfs -l newsystem0 ada0

Show the table:

# gpart show ada0
=>        34  1953525101  ada0  GPT  (931G)
          34           6        - free -  (3.0k)
          40         128     1  freebsd-boot  (64k)
         168     8388608     2  freebsd-swap  (4.0G)
     8388776  1945136352     3  freebsd-zfs  (927G)
  1953525128           7        - free -  (3.5k)

Bootcode installation process is the same:

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0

UFS filesystems

First, create a 4k-aligned GPT partition with the type freebsd-ufs (labeled data0 in this example). Then create an UFS filesystem on it using -S (sector size) parameter:

# newfs -U -L data0 -S 4096 /dev/gpt/data0

ZFS pools and filesystems

If you want to check what is the sector size run:

> zdb | grep ashift

Value of 9 means 512-bytes sector size and value of 12 is 4096 bytes sector size. This is set at pool creation time, you can't change it lf the pool was created with the wrong sector size.

In order to force 4k sectors run before creating the pool:

# sysctl vfs.zfs.min_auto_ashift=12

That's it. Now create your pools as ususal. ashift will always be 12.

 

Comments