Migratng a ZFS installation to new disk

Having just installed a fresh 15.0 release of FreeBSD on ZFS and got it configured, I've found a bigger disk which I would like to migrate to.

What are the required steps?

Can I just attach the new disk via a USB enclosure and use the existing installation to copy itself to the new disk?
 
You can mostly do that.
First you partition your bigger disk to have the efi partition, the swap, and a larger freebsd-zfs partition.
I highly suggest to use gpt labels for each of them, this would simplify stuff in the long run.

Then you edit your fstab entry to comment anything that would point to the old drive (like swap, and efi partition)

Then you attach your new freebsd-zfs partition to your zroot to create a mirror.
Once the resilvering complete, do a resilver.
Create an efi fat32 filesystem on the efi partition, then mount it somewhere.
Mount the old efi partition into /boot/efi, and copy the EFI directory inside the new efi filesystem.
Then use efibootmgr to add your new efi boot entry.

Once it is done, use zpool split to split the two drives into 2 distinct pool, so that you still have a backup if something goes terribly wrong.

Shutdown the computer.

Remove your old drive.

Start it again.

If it start, edit back the fstab to use the new drive partition.
 
You can mostly do that.
First you partition your bigger disk to have the efi partition, the swap, and a larger freebsd-zfs partition.
I highly suggest to use gpt labels for each of them, this would simplify stuff in the long run.

This sounds fairly complicated especially for someone not familiar with ZFS, so I think I need to break the process down, because it sounds error prone for a new user.

On my original disk I have the following partitions:

efi
freebsd-boot
freebsd-swap
freebsd-zfs

I presume the sizes, apart from zfs should be the same.
 
This sounds fairly complicated especially for someone not familiar with ZFS, so I think I need to break the process down, because it sounds error prone for a new user.

On my original disk I have the following partitions:

efi
freebsd-boot
freebsd-swap
freebsd-zfs

I presume the sizes, apart from zfs should be the same.

Does this look right?

sh:
gpart destroy -F da0
gpart create -s gpt da0
gpart add -t efi -s 260M -l efi1 da0
gpart add -t freebsd-boot -s 512K -l boot1 da0
gpart add -t freebsd-swap -s 2G -l swap1 da0
gpart add -t freebsd-zfs  -l zfs1 da0
 
I presume I need to create a zpool with a different name on the new disk. The old one has ZROOT, so calling the new one TANK would be OK?

I'm way out of my depth with all this so forgive the newbie type questions
 
If you just want to clone your installation to a bigger drive, then you just clone your disk with dd and then run gdisk repair to update GPT header stuff, and that's it. Somebody correct me if I'm wrong. I did this with Linux, I think, so there's no reason it shouldn't work with FreeBSD.
Oh, I guess you'd also need to grow your gpt partition and grow your ZFS to fill the extra space.
 
Does this look right?

sh:
gpart destroy -F da0
gpart create -s gpt da0
gpart add -t efi -s 260M -l efi1 da0
gpart add -t freebsd-boot -s 512K -l boot1 da0
gpart add -t freebsd-swap -s 2G -l swap1 da0
gpart add -t freebsd-zfs  -l zfs1 da0
This looks right, don't forget to create the efi filesystem.

Doesn't zpool split require a mirror to start ?
It does that is why the previous instruction is to make a mirror.

If you just want to clone your installation to a bigger drive, then you just clone your disk with dd and then run gdisk repair to update GPT header stuff, and that's it. Somebody correct me if I'm wrong. I did this with Linux, I think, so there's no reason it shouldn't work with FreeBSD.
Oh, I guess you'd also need to grow your gpt partition and grow your ZFS to fill the extra space.
This is not recommended if you are not extra cautious about which pool you import since then when doing the copy with dd the two pools will be the same, with the same unique id which can be messy.
And growing up the size of zfs like this will likely result in a kernel panic. I had to disable the auto grow feature enabled in cloud ready image just for that.
 
I presume I need to create a zpool with a different name on the new disk. The old one has ZROOT, so calling the new one TANK would be OK?

I'm way out of my depth with all this so forgive the newbie type questions

You don't need to rename your pool if I recall, you just give another name for the old one.
zpool split [-gLlnP] [-o property=value]… [-R root] pool newpool
[device]…

Splits devices off pool creating newpool. All vdevs in pool must be
mirrors and the pool must not be in the process of resilvering. At the
time of the split, newpool will be a replica of pool. By default, the
last device in each mirror is split from pool to create newpool
The optional device specification causes the specified device(s) to
included in the new pool and, should any devices remain unspecified, the
last device in each mirror is used as would be by default.
So basically: zpool split zroot old-zroot gpt/zfs0
 
Do I need to install FreeBSD on the new disk?

Or a freebsd-boot partition?

I have one on my current disk and installed using bsdinstall.
 
If you are booting with uefi, you just need to copy the uefi stuff, and update the efi entries in the bios.
As for legacy boot, you need to run the appropriate commands.
 
Having just installed a fresh 15.0 release of FreeBSD on ZFS and got it configured, I've found a bigger disk which I would like to migrate to.

What are the required steps?

Can I just attach the new disk via a USB enclosure and use the existing installation to copy itself to the new disk?
Have done it many times. This is just straightforward. Partition a new disk. Add new partition as a mirror to an existing pool with
zpool attach zpool-attach(8). Also set the zpool set autoexpand=on for your pool. Then let it resilver and remove the old disk and delete it from mirror..

Do not forget to copy boot loader to the disk.
 
Have done it many times. This is just straightforward. Partition a new disk. Add new partition as a mirror to an existing pool with
zpool attach zpool-attach(8). Also set the zpool set autoexpand=on for your pool. Then let it resilver and remove the old disk and delete it from mirror..

Do not forget to copy boot loader to the disk.
You may have done it many times, but this my first time and the procedure seems error prone if you don't know what you are doing which I don't.

This is the partitioning:- (da0 is the new disk)

Code:
root@W520:~ # gpart show -l ada1
=>       40  625142368  ada1  GPT  (298G)
         40     532480     1  efiboot0  (260M)
     532520       1024     2  gptboot0  (512K)
     533544        984        - free -  (492K)
     534528    4194304     3  swap0  (2.0G)
    4728832  620412928     4  zfs0  (296G)
  625141760        648        - free -  (324K)

root@W520:~ # gpart show -l da0
=>        40  1953525088  da0  GPT  (932G)
          40      532480    1  efi1  (260M)
      532520        1024    2  boot1  (512K)
      533544     4194304    3  swap1  (2.0G)
     4727848  1948797280    4  zfsdisk1  (929G)
Not sure what is meant by adding a new partition as a mirror to an existing pool....

And how do I copy the boot loader?
 
You may have done it many times, but this my first time and the procedure seems error prone if you don't know what you are doing which I don't.
Last time my sequence was this (my new drive was nda0 and old drive nda1) --

Code:
# Create partition table
gpart create -s GPT nda0

# Add UEFI boot partition
gpart add -i 1 -t efi  -s 200M -b 40 nda0

# Create swap partition (I do not use it on that drive, but for compatibility)
gpart add -i 2 -a 8K -t freebsd-swap  -s 16G nda0

#The rest of the drive for ZFS
gpart add -i 3 -a 8K -t freebsd-zfs nda0

# Now it looks like this
root@Aurum ~# gpart show nda0
=>        40  2000409184  nda0  GPT  (954G)
          40      409600     1  efi  (200M)
      409640           8        - free -  (4.0K)
      409648    33554432     2  freebsd-swap  (16G)
    33964080  1966445136     3  freebsd-zfs  (938G)
  2000409216           8        - free -  (4.0K)

# Then I copied loeder
# created file system for UEFI
newfs_msdos -F 32 -c 1 /dev/nda0p1

# Mounted this
mount -t msdosfs /dev/nda0p1 /mnt

# Created directofy for loader
mkdir -p /mnt/EFI/BOOT

# Copied loader
cp /boot/loader.efi /mnt/EFI/BOOT/BOOTX64.efi
umount /mnt

## Now we have UEFI loader on that drive

# Attached new ZFS partition to existing pool (my existing pool ssd_sys was on nda1)
zpool attach ssd_sys nda1p3 nda0p3

# Now waited for resilver
zpool status

# Check if autoresize is on

zpool get autoexpand ssd_sys
NAME     PROPERTY    VALUE   SOURCE
ssd_sys  autoexpand  on      local

# After that removed the first drive
# When the new drive booted successfully, removed old drive from the pool using its GUID
# to get vdev GUID-s
zpool status -g

# Now removed old partition
zpool detach ssd_sys 3946041219947219899

After that I had cloned my system from 512G pool to 1T pool.
 
Have done it many times. This is just straightforward. Partition a new disk. Add new partition as a mirror to an existing pool with
zpool attach zpool-attach(8). Also set the zpool set autoexpand=on for your pool. Then let it resilver and remove the old disk and delete it from mirror..
Interesting, I never had any concerns just running zpool replace ..., but somehow autoexpand bothers me. I prefer doing an explicit zpool online -e at the end instead.

balanga: When you have a free minute, you might want to take a look at gpart backup/ gpart restore. It really shines when replacing (nearly) identical disks or to consistently setting up a multi-disk pool, but nonetheless good to know about.
 
Interesting, I never had any concerns just running zpool replace ..., but somehow autoexpand bothers me. I prefer doing an explicit zpool online -e at the end instead.
Agree. I have sometimes done the zpool online -e also. zpool replace is probably a good way to do it. I have just wanted to have a little more control over the process, so being hesitant with that. But yes, you are right!
 
Boot from an USB stick or whatever.

dd the whole old drive to the new drive.

Edit the partition table on the new drive to enlarge the last partition, which hopefully is the zfs you want to enlarge.

Set the auto resize parameter in the zpool in the now bigger partition. It'll snap to size.
 
Boot from an USB stick or whatever.

dd the whole old drive to the new drive.

Edit the partition table on the new drive to enlarge the last partition, which hopefully is the zfs you want to enlarge.

Set the auto resize parameter in the zpool in the now bigger partition. It'll snap to size.
Using dd sounded like the simplest option so I thought I would give it a try, but unfortunately I got:-

dd: /dev/da0: Operation not permitted

Maybe this is because I have already partitioned the new disk for ZFS....
 
Using dd sounded like the simplest option so I thought I would give it a try, but unfortunately I got:-



Maybe this is because I have already partitioned the new disk for ZFS....

It could have been because I booted from ZFS based system.
Trying from a UFS based system does not show this error, so I'll see how well this works.
 
Boot from an USB stick or whatever.

dd the whole old drive to the new drive.

Edit the partition table on the new drive to enlarge the last partition, which hopefully is the zfs you want to enlarge.

Set the auto resize parameter in the zpool in the now bigger partition. It'll snap to size.
After several hours of dd, followed by 'gpart recover' and 'gpart resize' I think I'm reading for the next step.

At this point should I be able to boot from the new disk, or is something else required?

Does the dd copy over zpools?
 
Back
Top