# ZFS on SSD



## kr651129 (Sep 4, 2012)

I recently formatted my SSD to install ZFS on FreeBSD 9 after I ran through the setup on VirtualBox to make sure I knew how to do it.  The install on VirtualBox worked fine, using the same guide I installed ZFS after reformatting my drive an it wouldn't boot, it kept telling me that it couldn't find any ZFS pool to boot from.  Is there anything special I need to take into account when installing ZFS on a SSD?


----------



## vermaden (Sep 4, 2012)

I use ZFS on SSD from more then a year, works like a charm, I never changed anything specially for SSD.


----------



## avilla@ (Sep 4, 2012)

kr651129 said:
			
		

> it kept telling me that it couldn't find any ZFS pool to boot from.  Is there anything special I need to take into account when installing ZFS on a SSD?



Be sure *not* to export the pool before rebooting.


----------



## anton (Sep 4, 2012)

Bear in mind that ZFS doesn't support TRIM yet as far as I'm concerned. This means you should better use an SSD with good background garbage collection, otherwise you'll experience performance degradation as time passes by.
This is what pjd (the man who ported ZFS to FreeBSD) had to say about this:
http://permalink.gmane.org/gmane.os.solaris.opensolaris.zfs/44978


----------



## kr651129 (Sep 13, 2012)

I can't boot to my zfs install, here is the error I'm getting


```
Gptzfsboot: error 1 lba 48
Gptzfsboot: error 1 lba 1
Gptzfsboot: no zfs pools located, can't boot
```


----------



## wblock@ (Sep 13, 2012)

Was that drive partitioned as GPT?


----------



## kr651129 (Sep 14, 2012)

I format the drive and create the partitions as follows


```
dd if=/dev/zero of=/dev/ada0
gpart create -s gpt ada0
gpart add -b 34 -s 94 -t freebsd-boot ada0
gpart add -t freebsd-zfs -l disk0 ada0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0
```


----------



## Sebulon (Sep 14, 2012)

@kr651129

Maybe a slight modification to the boot partition, I think it looks a little small, and can start right from the beginning, without "-b". And I always set the first data partition aligned to start at 1MiB "-b 2048" and made to end aligned with 4k.

`# gpart destroy -F ada0`
`# gpart add -t freebsd-boot -s 64k ada0`
`# gpart add -t freebsd-zfs -b 2048 -a 4k -l disk0 ada0`
`# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0`

Then there are some things you need to have done to make this work, so I typed them up, in case there is something you may have missed. Remember gnop when making the pool to get ashift=12
`# gnop create -S 4096 /dev/gpt/disk0`

Save your zpool.cache somewhere writeable, if yourÂ´re making it from the bsdinstaller:
`# zpool create -O mountpoint=none -o cachefile=tmp/zpool.cache rpool gpt/disk0.nop`
`# zfs create -o mountpoint=legacy rpool/root`
`# zpool set bootfs=rpool/root rpool`

`# zpool export rpool`
`# gnop destroy /dev/gpt/disk0.nop`
`# zpool import -o cachefile=/tmp/zpool.cache -d /dev/gpt rpool`

Copy zpool.cache to /mnt/boot/zfs/.
`# mount -t zfs rpool/root /mnt`
`# mkdir -p /mnt/boot/zfs`
`# cp /tmp/zpool.cache /mnt/boot/zfs/`

And finish off by putting entries in fstab and loader.conf

```
[CMD="#"]ee /tmp/bsdinstall_etc/fstab[/CMD]
rpool/root              /               zfs   rw  0  0

[CMD="#"]ee /mnt/boot/loader.conf[/CMD]
zfs_load="YES"
vfs.root.mountfrom="zfs:rpool/root"
```

Works for meâ„¢

You can of course add filesystems according to your own liking. Just remember to handle their mounts, either with zfs mounting them, or with fstab.

/Sebulon


----------



## wblock@ (Sep 14, 2012)

With the data partition starting at 1M, might as well make the freebsd-boot partition as large as possible to avoid having to increase it later if the bootcode gets bigger.  At present, that means 512K.  Also, it won't hurt to make that partition 4K-aligned, starting at block 40.  Probably won't help, either, but the extra space is unused anyway.
`# gpart add -t freebsd-boot -b40 -s512k ada0`

For FreeBSD 9.1, and 9-stable now:
`# gpart add -t freebsd-boot -a4k -s512k ada0`


```
# gpart show ada0
=>       34  500118125  ada0  GPT  (238G)
         34          6        - free -  (3.0k)
         40       1024     1  freebsd-boot  (512k)
       1064        984        - free -  (492k)
       2048    ...
```


----------



## gkontos (Sep 14, 2012)

I think that for a 4K alignment the freebsd-boot partition should be added like this:

[CMD=""]# gpart add -b 34 -s 94 -t freebsd-boot adaX[/CMD]

I haven't seen any changes since  r230059 but of course I could be wrong.


----------



## kpa (Sep 14, 2012)

I see no reason to specify -b for the boot partition, gpart(8) will use the next available sector automatically.

I do recall that there was some talk about -a and -b options conflicting, is that you are referring to? My take on that is that the -a option is a stronger requirement than -b. So if you say:

`# gpart add -t freebsd-boot -b 34 -a 4k -s 128k ada0`

This should always create a partition that starts from sector 40, the next sector after 34 that is divisible by 8.


----------



## wblock@ (Sep 15, 2012)

-a rounds the start and size to even multiples of the value given.  Up until a couple of months ago, the -b value was ignored if -a was used.  The version of gpart(8) in 9-STABLE now and 9.1-RELEASE has that fixed.

With the fixed version, this command will do as you'd expect, creating a 4K-aligned partition starting a 1M:
`# gpart add -t freebsd-ufs -a4k -b 1m -s 20g ada0`

The earlier version of gpart(8) would create a 20g aligned partition, but it would start at the next available aligned block.


----------

