6

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.

8

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.

1
  • 1
    "Data written during a balance may still use the old format so a second balance may be needed." Note that if this happens, you can run the balance command but additionally specify soft on both filters, which will ignore any block groups that already have the profile being converted to. For example: btrfs balance start -dconvert=raid1,soft -mconvert=raid1,soft /mountpoint. This will rebalance (and convert to raid1) only block groups that aren't already raid1. – cdhowie Jun 18 '20 at 0:25
2

OK let this server as a monument to my utter failure.

To confirm RAID config: btrfs fi df /mountpoint

It turns out that I didn't goof, Windows somehow reports twice the data (and twice the space) when you connect to a btrfs RAID1 fs via SAMBA.

If you perhaps did make the error I thought I made when setting up your BTRFS filesystem then this may help, although fortunately I didn't have to try it.

1

You can just use a balance filter while it is mounted

  1. Check to see if you are raid0 and it is the correct array

    $ btrfs fi df /mnt
    
    Data, RAID0: total=16.00GiB, used=14.17GiB
    System, RAID1: total=32.00MiB, used=16.00KiB
    Metadata, RAID1: total=1.00GiB, used=376.92MiB
    GlobalReserve, single: total=39.20MiB, used=0.00B
    
  2. Convert it live
    btrfs fi balance start -dconvert=raid1 /mnt
    
  3. Check if it is now raid1

    btrfs fi df /
    
    Data, RAID1: total=15.00GiB, used=14.22GiB
    System, RAID1: total=32.00MiB, used=16.00KiB
    Metadata, RAID1: total=1.00GiB, used=377.19MiB
    GlobalReserve, single: total=39.41MiB, used=0.00B
    

If your metadata isn't already raid1, make sure to add -mconvert=raid1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.