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
- Identify Available Disks: Use the
lsblk
orfdisk -l
commands to list available disks and identify the ones to use for the new ZFS pool.
$ lsblk
- 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
- Mount the Btrfs File System: If the Btrfs file system is not already mounted, mount it:
$ sudo mount /dev/sda1 /mnt/btrfs
- 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
- 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
- Enable Deduplication (Optional): Deduplication can be enabled if necessary for the environment, though it requires significant memory:
$ sudo zfs set dedup=on mypool
- 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
- Check Pool Status: Verify the pool's health and ensure that the ZFS pool is functioning properly:
$ sudo zpool status
- 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.
- Unmount the Btrfs File System:
$ sudo umount /mnt/btrfs
- Reclaim or Reformat the Btrfs Partition: Use tools like
fdisk
orparted
to reformat or repurpose the old Btrfs partitions.
Btrfs to ZFS Command and Utility Mapping
Functionality | Btrfs Command/Utility | ZFS Command/Utility |
---|---|---|
Create File System | mkfs.btrfs /dev/sda1 | zpool create mypool /dev/sda1 |
Mount File System | mount /dev/sda1 /mnt | Automatically mounted by ZFS; use zfs mount mypool if needed |
Unmount File System | umount /mnt | zfs unmount mypool |
Check File System Integrity | btrfs check /dev/sda1 | zpool scrub mypool |
Resize File System | btrfs filesystem resize +10G /mnt | Automatically resized with zpool add or zpool attach |
View File System Usage | btrfs filesystem df /mnt | zfs list |
Check Disk Usage | btrfs filesystem usage /mnt | zfs get used,available mypool |
Create Snapshot | btrfs subvolume snapshot /mnt /mnt/snap | zfs snapshot mypool@snap1 |
Delete Snapshot | btrfs subvolume delete /mnt/snap | zfs destroy mypool@snap1 |
Compression | btrfs property set /mnt compression lzo | zfs set compression=lz4 mypool |
Deduplication | Experimental, not recommended | zfs set dedup=on mypool |
Create RAID Array | mkfs.btrfs -d raid1 /dev/sda /dev/sdb | zpool create mypool raidz /dev/sda /dev/sdb /dev/sdc |
Resize RAID Array | btrfs device add /dev/sdb /mnt | zpool add or zpool attach |
Check RAID Health | btrfs device stats /mnt | zpool status |
Monitor File System Health | btrfs scrub status /mnt | zpool scrub mypool |
Backup and Restore | btrfs send and btrfs receive | zfs send and zfs receive |