Installing new disk using ZFS to clone


The background of this was replacing an existing mechanical drive with a new ssd.

You could also use this to upgrade to a larger drive but will likely need to do some additional steps.

Note: When doing something like this make sure you back up any critical data first.


Backup Partitions from existing drive

gpart backup ada0 > ada1.backup

Restore Partitions to new drive

gpart restore -l da0 < /root/ada1.backup

Duplicate efi boot

dd if=/dev/ada0p1 of=/dev/da0p1 bs=1M

Encrypt data volume

sudo geli init -g /dev/da0p3

Attach geli volume

geli attach /dev/da0p3

Check status for geli volumes

geli status

Attach geli volume in zfs zroot pool

zpool attach zroot ada0p3.eli da0p3.eli

Wait for it to resilver then you should be good to boot from the new drive. Next step is to remove/disconnect the original drive and see if it boots.

If successful you can detach the original drive from the zpool.

If you've replaced the original drive and the system detects it as the same drive name as the original drive then you'll likely see somethink like below once the machine boots.

NAME            STATE     READ WRITE CKSUM
zroot           DEGRADED     0     0     0
mirror-0        DEGRADED     0     0     0
ada0p3.eli      FAULTED      0     0     0  corrupted data
ada0p3.eli      ONLINE       0     0     0

Even though the names appear to be duplicated you can just detach the drive as per below

sudo zpool detach zroot ada0p3.eli

You should now have something like the following

pool: zroot
state: ONLINE
scan: resilvered 68.2G in 00:30:54 with 0 errors on Thu Jan  2 15:00:10 2025
config:

NAME            STATE     READ WRITE CKSUM
zroot           ONLINE       0     0     0
ada0p3.eli      ONLINE       0     0     0

errors: No known data errors

Now you should be done.

Copyright © 2020 | Ben Hutton