BTRFS convert RAID0 to RAID1

btrfs

Somehow I goofed creating my BTRFS filesystem and ended up with RAID0 instead of RAID1. However I only noticed this after adding 274GB of data (I know, what a moron):

Total devices 2 FS bytes used 136.12GiB
        devid    1 size 465.76GiB used 137.03GiB path /dev/sdb
        devid    2 size 465.76GiB used 137.03GiB path /dev/sdc

I would like a method of A: Confirming that this is indeed RAID0 (I'm sure it is, but I haven't found a command that outputted that explicitly, and I would like to check next time before adding data). And B: If possible, redistributing the data to RAID1.

Best Answer

When making a btrfs filesystem across multiple devices, the default is to use RAID0 for data, and RAID1 for metadata. If you want to change this you can pass arguments to the mkfs command to change RAID level of data (-d) and metadata (-m):

mkfs.btrfs -d raid1 -m raid1 /dev/sda /dev/sdb

To confirm what RAID level is being used on an existing filesystem, you can use the btrfs utility:

$ btrfs fi df /mountpoint
Data, RAID1: total=15.00GiB, used=14.65GiB
System, RAID1: total=8.00MiB, used=16.00KiB
Metadata, RAID1: total=1.00GiB, used=15.59MiB

The example output shows RAID1 used for both data and metadata. Running btrfs fi usage /mountpoint will provide more detail.

You can convert an existing filesystem to a different RAID level by passing arguments to the balance command.

btrfs balance start -dconvert=raid1 -mconvert=raid1 /mountpoint

A balance writes all data to the filesystem again, and adding arguments will cause the data to be converted as it is rewritten. This may take a while, you can run btrfs balance status /mountpoint to see the status. Once it finishes, you can confirm that all data was converted as expected with btrfs fi df. Data written during a balance may still use the old format so a second balance may be needed.

Utilities such as the regular df command or btrfs fi show do not take RAID settings into account, as that is done by btrfs itself. These tools only show the total amount allocated by btrfs on the disks, they don't know what format btrfs is using for the data. This also means sharing via SAMBA or other tools will not account for RAID. For more info, see the btrfs FAQ.

Related Question