Migrating from BTRFS to mdadm RAID requires a complete data evacuation, physical reconfiguration of disk arrays, and reconstruction of the filesystem layer. This process ensures hardware-level redundancy through
mdadm while allowing you to choose a simpler filesystem like ext4 or XFS for your home NAS. The following guide details the safe steps to preserve your data during this transition.
Planning and Preparing Your Environment
Before touching any disks, you must ensure that all critical data is backed up externally. While BTRFS offers features like snapshots and self-healing, migrating to a software RAID solution managed by
mdadm fundamentally changes how redundancy is handled. You will be moving from a filesystem-aware RAID implementation to a block-device level RAID. This means the operating system sees the array as a single virtual disk rather than individual drives with their own metadata.
It is crucial to verify that your new setup meets your performance and capacity requirements. For a typical home NAS, a RAID-1 configuration (mirroring) is often preferred over RAID-5 or RAID-6 due to write penalties and rebuild complexities on smaller arrays. Ensure you have identical replacement drives if you are expanding, or plan to use existing drives in a mirrored pair. Check your motherboard’s BIOS/UEFI settings to ensure the SATA ports are configured in AHCI mode, not RAID mode, so the Linux kernel can manage the
mdadm arrays directly.
For users considering alternative approaches, such as keeping BTRFS but using mdadm underneath, see
BTRFS Self-Healing with MDADM RAID: A Solution for Bitflip Detection. This hybrid approach might suit those who want filesystem-level scrubbing without abandoning BTRFS entirely. However, if you prefer a more traditional, stable stack, proceeding with a clean migration to a standard filesystem on top of mdadm is the robust choice.
Evacuating Data from BTRFS
The first technical step is to unmount the existing BTRFS filesystems and copy all data to a temporary storage location. This could be an external USB drive, a different internal partition, or a network share. Do not attempt to migrate while the filesystem is mounted; this risks severe data corruption.
Use
rsync for reliable data transfer. It preserves permissions, timestamps, and handles incremental copies well. If your BTRFS pool contains multiple subvolumes, ensure you copy each one separately to maintain your directory structure.
# Example command for rsync
sudo rsync -avh --progress /mnt/btrfs/source/ /tmp/backup_destination/
Verify the integrity of the copied data. Check file counts and sizes between the source and destination. Once verified, you can safely wipe the original BTRFS partitions. Be extremely careful at this stage; selecting the wrong device identifier (
/dev/sda vs
/dev/sdb) will result in permanent data loss. Use
lsblk to visually confirm which devices correspond to your old BTRFS drives before proceeding.
Initializing mdadm RAID Arrays
With the old data moved and the old filesystems wiped, you can begin creating the new
mdadm arrays. Start by wiping any residual superblocks from the target drives to prevent confusion during assembly.
sudo mdadm --zero-superblock /dev/sdX
sudo mdadm --zero-superblock /dev/sdY
Next, create a RAID-1 array using the two drives. This creates a mirror where both drives contain identical data. Replace
sda and
sdb with your actual device identifiers.
sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda /dev/sdb
Wait for the resynchronization process to complete. You can monitor the progress via
/proc/mdstat. Do not proceed to formatting until the sync is finished. An incomplete array may lead to degraded performance or data inconsistency if formatted prematurely.
If you are dealing with larger arrays or specific size discrepancies, refer to
Troubleshooting: Mdadm RAID 5 Array Size is Smaller than Expected for insights on handling edge cases in array creation, although this guide focuses on RAID-1.
Formatting and Mounting the New Filesystem
Once the
mdadm array is fully synchronized, format it with your chosen filesystem. For a home NAS, ext4 is highly stable and widely supported, while XFS offers better performance for large files. Avoid BTRFS here unless you specifically want to reintroduce its complexity, as seen in
How to Convert ext4 Partition on RAID 1 to btrfs, which outlines the reverse of this process.
sudo mkfs.ext4 /dev/md0
Create a mount point and add an entry to
/etc/fstab to ensure the array mounts automatically at boot. Use the UUID of the new filesystem for reliability.
sudo mkdir /mnt/nas
sudo blkid /dev/md0 # Copy the UUID
# Add to /etc/fstab:
# UUID=your-uuid-here /mnt/nas ext4 defaults,nofail 0 2
Mount the filesystem and restore your data from the backup. Use
rsync again to move files back to the new mount point. Verify access permissions and application functionality.
Finally, update your
mdadm.conf file to include the new array definition so the system recognizes it on subsequent boots.
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
This migration provides a solid foundation for your home NAS, leveraging hardware-level redundancy with
mdadm and a proven filesystem.
Frequently Asked Questions
Can I convert BTRFS to mdadm without losing data?
No, you cannot directly convert a BTRFS filesystem to an mdadm array while preserving data. The two technologies operate at different layers of the storage stack. You must always backup, wipe, recreate, and restore.
Is RAID-1 slower than BTRFS RAID-1?
In many workloads, mdadm RAID-1 performs similarly or slightly better than BTRFS RAID-1 because it lacks the overhead of checksumming every block and managing complex subvolume trees. However, BTRFS offers superior data integrity verification through scrubbing.
What happens if one drive fails in my new setup?
If a drive fails in an mdadm RAID-1 array, the array continues to operate in a degraded state. You can replace the failed drive later, and
mdadm will resynchronize the data onto the new disk automatically.
Should I use ext4 or XFS for my home NAS?
ext4 is generally easier to manage and recover from if issues arise, making it ideal for general-purpose home NAS usage. XFS is better suited for very large files (multi-terabyte) and high-throughput scenarios, but lacks online shrinking capabilities.
Do I need to enable TRIM for SSDs in mdadm?
Yes, if you are using SSDs, enable discard support in
mkfs and ensure your initramfs supports it. This allows the OS to notify the SSD when blocks are freed, maintaining performance and lifespan over time.