Solved Migrate zpool from 1TB HDD to smaller 480GB SSD

Father Grigori

New Member

Reaction score: 3
Messages: 14

Hello all!

I've been using FreeBSD for some time now and I love it, but when it comes to ZFS I am a total n00b and I don't want to risk
losing all my work, so here is my question:

What is the most hassle-free and safe way to migrate my current data from 1TB HDD (ada0) to a smaller sized SSD I just bought,
attached to the same machine on another SATA port, using ZFS commands (not via dd or external cloning software)?

What I really mean is to transfer all data from HDD to the SSD and then remove the HDD from the PC (maybe reusing it to store snapshots and backups only) and
have the SSD as my shiny new ada0.

I am using FreeBSD 12.0-RELEASE-p7 and the zpool is the default RootOnZFS from FreeBSD installation, as follows:

Code:
:~ % zfs list
NAME                       USED  AVAIL  REFER  MOUNTPOINT
zroot-alpha                259G   632G    96K  /zroot-alpha
zroot-alpha/ROOT           105G   632G    96K  none
zroot-alpha/ROOT/default   105G   632G   105G  /
zroot-alpha/tmp           15.1M   632G  15.1M  /tmp
zroot-alpha/usr            153G   632G    96K  /usr
zroot-alpha/usr/home       119G   632G   119G  /usr/home
zroot-alpha/usr/ports     33.7G   632G  33.7G  /usr/ports
zroot-alpha/usr/src         96K   632G    96K  none
zroot-alpha/var            594M   632G    96K  /var
zroot-alpha/var/audit       96K   632G    96K  /var/audit
zroot-alpha/var/crash       96K   632G    96K  /var/crash
zroot-alpha/var/log         15M   632G    15M  /var/log
zroot-alpha/var/mail       144K   632G   144K  /var/mail
zroot-alpha/var/tmp        578M   632G   578M  /var/tmp
Code:
:~ % gpart show
=>        40  1953525088  ada0  GPT  (932G)
          40        1024     1  freebsd-boot  (512K)
        1064         984        - free -  (492K)
        2048    16777216     2  freebsd-swap  (8.0G)
    16779264  1936744448     3  freebsd-zfs  (924G)
  1953523712        1416        - free -  (708K)
Currently using only 14% of the disk, so 480GB available on the SSD is enough to transfer all the data:

Code:
 df -h
Filesystem                  Size    Used   Avail Capacity  Mounted on
zroot-alpha/ROOT/default    737G    105G    632G    14%    /
devfs                       1.0K    1.0K      0B   100%    /dev
/dev/ada2p1                 144G     25G    107G    19%    /BKP-DISK
procfs                      4.0K    4.0K      0B   100%    /proc
zroot-alpha/tmp             632G     15M    632G     0%    /tmp
zroot-alpha/usr/home        751G    119G    632G    16%    /usr/home
zroot-alpha/usr/ports       666G     34G    632G     5%    /usr/ports
zroot-alpha/var/audit       632G     96K    632G     0%    /var/audit
zroot-alpha/var/crash       632G     96K    632G     0%    /var/crash
zroot-alpha/var/log         632G     15M    632G     0%    /var/log
zroot-alpha/var/mail        632G    144K    632G     0%    /var/mail
zroot-alpha/var/tmp         632G    578M    632G     0%    /var/tmp
zroot-alpha                 632G     96K    632G     0%    /zroot-alpha
fdescfs                     1.0K    1.0K      0B   100%    /dev/fd
/dev/fuse                     0B      0B      0B   100%    /var/run/user/1001/gvfs
And I guess TRIM is enable by default when using ZFS, right?

Well, any step-by-step help would be very much appreciated, thank you guys!
 

ucomp

Active Member

Reaction score: 33
Messages: 192

Hi,
there's not much risk because you won't delete your old drive before your new drive is ready to boot as root on zfs.

you can probably skip the export-step.
 

Martin Garcia

Member

Reaction score: 1
Messages: 24

Hello, I have the exact case.

Im another noob, Im not clear about this

"Install bootable root-zfs from install-DVD to your clone-target - disk
(name the zroot whatever you want: e.g zroot2)

boot the newly installed system
zpool export zroot2

now boot back to your source-disk
zpool import zroot2"


What I did is attach a fresh install disk (nothing but the OS) as a secondary. But now its booting the target not the destination.
Also, I was struggling with zfs send and recv but it didnt boot since it doesnt found the zfsboot.
Thanks in advance for the clarification
 

ucomp

Active Member

Reaction score: 33
Messages: 192

But now its booting the target not the destination.
it should.

Code:
zpool get bootfs
example-output :
zrootNEW bootfs zrootNEW/ROOT/default local
zrootOLD boots zrootOLD/ROOT/default local

Code:
zpool set bootfs=zrootOLD/ROOT/default zrootOLD
Code:
init 6
control:
Code:
zpool import
Code:
zpool import zrootNEW
control :
Code:
zpool status
Code:
zfs snapshot -r zrootOLD@whateveryouwant
Code:
zfs send -R zrootOLD@whateveryouwant | zfs recv -F zrootNEW
....
Code:
zpool set bootfs=zrootNEW/ROOT/default NEW
Code:
shutdown -h now
now you can remove your old disk
or do whatever you want with it .
--
I hope I did not mess things up (written from memory)..
good luck !
 

Martin Garcia

Member

Reaction score: 1
Messages: 24

ucomp. Many thanks for it,

Just to let you know it worked!,
It saved us a lot of work.
zpool import zrootNEW <-- I needed to add -f to force
And lastly I discarded the unused the disk and did a zfs export in order to have it clean.

Again, many thanks for it.
 
Top