BTRFS

Migration Guide: Moving from Btrfs to ZFS

Migrating from Btrfs to ZFS enables access to features such as advanced RAID functionality, data integrity through checksumming, and integrated volume management. While Btrfs and ZFS share some similarities, such as snapshots and copy-on-write (COW), ZFS is widely regarded as more stable and reliable for large-scale environments.

This guide outlines the steps for migrating from Btrfs to ZFS, focusing on data preservation and configuring the new ZFS pool.

Why Migrate from Btrfs to ZFS?

Key reasons for migration include:

  • Data Integrity: ZFS provides end-to-end checksumming for better protection against data corruption.
  • RAID-Z Support: ZFS includes RAID-Z1, RAID-Z2, and RAID-Z3, providing more advanced redundancy options than Btrfs.
  • Maturity and Stability: ZFS is considered more reliable for larger environments and workloads that require high data integrity.
  • Advanced Features: ZFS supports deduplication, efficient snapshots, and compression.

Prerequisites

Before starting the migration, it is important to:

  • Backup Data: Back up the data from the Btrfs file system. The migration involves reformatting disks, which will erase data.
  • Ensure Disk Space: Prepare additional disks or ensure enough free space to move the data.
  • Install ZFS Utilities: Install the necessary ZFS packages based on the operating system.

For Ubuntu or Debian-based systems:

$ sudo apt install zfsutils-linux

For RHEL-based systems (CentOS, Fedora):

$ sudo yum install zfs

Step 1: Prepare the New ZFS Pool

  1. Identify Available Disks: Use the lsblk or fdisk -l commands to list available disks and identify the ones to use for the new ZFS pool.
$ lsblk
  1. Create the ZFS Pool: Depending on the desired disk configuration, create the ZFS pool. For a single disk:
$ sudo zpool create mypool /dev/sdb

For a mirrored setup:

$ sudo zpool create mypool mirror /dev/sdb /dev/sdc

For RAID-Z1:

$ sudo zpool create mypool raidz /dev/sdb /dev/sdc /dev/sdd

Replace mypool with the desired pool name.

Step 2: Migrate Data from Btrfs to ZFS

  1. Mount the Btrfs File System: If the Btrfs file system is not already mounted, mount it:
$ sudo mount /dev/sda1 /mnt/btrfs
  1. Copy Data to the ZFS Pool: Use rsync to copy the data from Btrfs to the ZFS pool while preserving file attributes, permissions, and symbolic links:
$ sudo rsync -aHAXv /mnt/btrfs/ /mypool/

This command will transfer all data from the Btrfs file system located at /mnt/btrfs to the new ZFS pool at /mypool.

Step 3: Configure ZFS Features

  1. Enable Compression: ZFS supports various compression algorithms, such as lz4. Enable compression on the new pool:
$ sudo zfs set compression=lz4 mypool

Verify compression status with:

$ zfs get compression,compressratio mypool
  1. Enable Deduplication (Optional): Deduplication can be enabled if necessary for the environment, though it requires significant memory:
$ sudo zfs set dedup=on mypool
  1. Set Additional Pool Properties: Adjust any other required properties, such as encryption, quotas, or mount points, based on the needs of the system.

Step 4: Verifying and Scrubbing the ZFS Pool

  1. Check Pool Status: Verify the pool's health and ensure that the ZFS pool is functioning properly:
$ sudo zpool status
  1. Scrub the Pool: Perform a ZFS scrub to check data integrity:
$ sudo zpool scrub mypool

A scrub reads through all the data, verifies checksums, and fixes any errors.

Step 5: Post-Migration Cleanup

After verifying that the migration is complete and the ZFS pool is working properly, unmount and repurpose the old Btrfs partitions.

  1. Unmount the Btrfs File System:
$ sudo umount /mnt/btrfs
  1. Reclaim or Reformat the Btrfs Partition: Use tools like fdisk or parted to reformat or repurpose the old Btrfs partitions.

Btrfs to ZFS Command and Utility Mapping

FunctionalityBtrfs Command/UtilityZFS Command/Utility
Create File Systemmkfs.btrfs /dev/sda1zpool create mypool /dev/sda1
Mount File Systemmount /dev/sda1 /mntAutomatically mounted by ZFS; use zfs mount mypool if needed
Unmount File Systemumount /mntzfs unmount mypool
Check File System Integritybtrfs check /dev/sda1zpool scrub mypool
Resize File Systembtrfs filesystem resize +10G /mntAutomatically resized with zpool add or zpool attach
View File System Usagebtrfs filesystem df /mntzfs list
Check Disk Usagebtrfs filesystem usage /mntzfs get used,available mypool
Create Snapshotbtrfs subvolume snapshot /mnt /mnt/snapzfs snapshot mypool@snap1
Delete Snapshotbtrfs subvolume delete /mnt/snapzfs destroy mypool@snap1
Compressionbtrfs property set /mnt compression lzozfs set compression=lz4 mypool
DeduplicationExperimental, not recommendedzfs set dedup=on mypool
Create RAID Arraymkfs.btrfs -d raid1 /dev/sda /dev/sdbzpool create mypool raidz /dev/sda /dev/sdb /dev/sdc
Resize RAID Arraybtrfs device add /dev/sdb /mntzpool add or zpool attach
Check RAID Healthbtrfs device stats /mntzpool status
Monitor File System Healthbtrfs scrub status /mntzpool scrub mypool
Backup and Restorebtrfs send and btrfs receivezfs send and zfs receive