Conversion to ZFS

I want to convert my existing partitions to ZFS, excluding /, swap, and /tmp:
/dev/mirror/gm0s1a /
/dev/mirror/gm0s1d /usr
/dev/mirror/gm0s1e /var
/dev/mirror/gm0s1f /tmp
/dev/mirror/gm0s1g /usr/home

What is the optimal procedure for such an operation, on a live system (preferably)? I was thinking of copying /usr, /var, /tmp, and /usr/home to / (it has enough space), umounting gm0s1[d-g], deactivating these mirrors, editing disklabel on both disks to create a s1d /tmp and s1e zfs partition, activating the s1d /tmp mirror, and creating a zpool on s1e. Also, I'm not sure whether it is possible to have a single zpool containing /var and /usr (in spite of a UFS /); I might have to leave /var as UFS.
 
For two disks like you have, you are better off just using gmirror.

While you can run ZFS on partitions, it won't give you any better performance than gmirror.

Unless there are 2 TB disks with tonne of free space, you're probably better off leaving things as they are.

If you really have your heart set on doing this, it's a bit more convoluted than you think. We can come up with a plan, although I'd advice against it.
 
It's not just performance that I'm after, but also the other features (self-healing, snapshots, dedup, etc.) There is enough space on / to temporarily accommodate the other partitions, so it should be feasible to do... Otherwise, I'll just convert /usr/home.
 
The biggest pothole on the road to success: using gmirror on the entire disk.

You'll need to break your gmirror (gm0), boot off one of the drives, move everything off the extra partitions to / filesystem, shrink the size of the slice (s1), create a second slice (s2) from the free space, and then create a new gmirror using s1 on each disk. That will leave s2 to be used for a ZFS mirror vdev.

Be sure to create a good backup of all your data, first. :)

In fact, it may be easier to just re-install, using two slices on each disk.
 
Alternatively, you may add two flash drives for the 'boot' (or root) part of the system set up as an gmirror and convert both existing drives to ZFS mirror. I have done this many times. The only thing, that you need to carefully consider is swap --- it can be done over ZFS, but I always try to make sure swap is not needed (by adding more RAM :). Never tried swap over flash disk, is it asking for disaster?

I usually use pair of USB flash drives. 4GB is more than enough. My usual course of action is like this:

(on an existing FreeBSD system)
- connect both flash drives;
- glabel flash drives, usually boot0 and boot1
- create gmirror on label/boot0 and label/boot1
(to be fair, I actually always populate the first drive, then create the gmirror by adding the second, but it really does not matter)
- install FreeBSD on the gmirror, fix fstab
(move the flash drives to the new system and boot there, after fixing initial setup, reboot single user)
- glabel all disks that will be used for ZFS. This saves you later, when for whatever reason the OS renumbers drives. Do not reference the raw devices when creating the zpool, reference the labels.
- create ZFS mirror (or other if more disks)
- create ZFS filesystems for /usr, /var, /tmp etc. do not set mountpoints yet
- move data from /usr and /var to the ZFS filesystems
- set mountpoints for these filesystems to /usr and /var respectively
- restore your other data
- check if zfs_enable="YES" is in /etc/rc.conf
- enjoy your new flash/ZFS based setup.

If you don't like making and restoring backups (bad idea to skip it), you may do this, converting the system in place:
- create the flash gmirror on the same system;
- copy over /, /usr, /var etc. (you may set up other filesystems as soft links on the flash gmirror)
- set up BIOS to boot off flash, reboot
- break your disk based gmirror. you will then have one 'free' disk
- make sure you destroy labels and filesystem on that disk, so ZFS will accept it without complaints
- glabel the disk
- create non-redundant ZFS on it

# zpool create poolname first_disk_label

- do everything else as above, until you are satisfied with your new ZFS based system. Not bad idea to disconnect your other (still valid gmirror) drive, just to be safe
- when everything is ok to your taste, reconnect the other drive, clear all labels/filesystems, glabel it and add it to the pool with

# zpool attach poolname first_disk_label second_disk_label

- you now have the same system as above, but without going via backup/restore

In any case, having a backup is the better idea.
 
danbi said:
Alternatively, you may add two flash drives for the 'boot' (or root) part of the system set up as an gmirror and convert both existing drives to ZFS mirror. I have done this many times. The only thing, that you need to carefully consider is swap --- it can be done over ZFS, but I always try to make sure swap is not needed (by adding more RAM :). Never tried swap over flash disk, is it asking for disaster?

Swap on USB sticks works nicely. :) I use this at home. A 4 GB USB stick sliced into a 1 GB swap and 3 GB ZFS cache vdev.

- create gmirror on label/boot0 and label/boot1
(to be fair, I actually always populate the first drive, then create the gmirror by adding the second, but it really does not matter)
- install FreeBSD on the gmirror, fix fstab
(move the flash drives to the new system and boot there, after fixing initial setup, reboot single user)

Don't forget to install the boot blocks onto both devices; otherwise, if the primary device fails, the secondary device won't be bootable. :)
 
In the OP's situation, I'd do the following:

- Break the gmirror, running the system from one disk and freeing up the other one.
- Set up the free disk for (almost) exclusive ZFS use, using GPT to give it a freebsd-boot and freebsd-zfs partition.
- Copy all the data across to the new ZFS filesystem structure.
- Try to boot from it
- If successful, wipe the remaining gmirror disk, then GPT partition it the same as the ZFS disk, then attach the freebsd-zfs partition to the zfs mirror.

That's rather simplified, it'd take a lot more work, but it should be possible.
 
Back
Top