BTRFS filesystem owners beware: Linux Kernels <5.14 creates BTRFS filesystems with single-copy metadata only. This is apparently known in BTRFS circles as a huge whoopsie. If you are in the group of users who created your btrfs filesystem using a kernel earlier than 5.14, then you should DUP (duplicate) your metadata as soon as possible. You can also enable this feature on existing filesystems without risk to data loss with the instructions below.

When performing any commands on the BTRFS filesystem, make sure you really know what you’re doing

If you were curious about btrfs but have held off because it was unstable, you should know it is now stable, has built-in support in the Linux Kernel and is being used by many production servers right this second. In fact it’s the default filesystem on Fedora and is optionable on many others including Ubuntu and Linux Mint.

  1. Determine whether your metadata is single-copy or duplicated/DUP (line 4):
    $ btrfs filesystem df /
    Data, single: total=99.01GiB, used=65.99GiB
    System, single: total=32.00MiB, used=16.00KiB
    Metadata, single: total=4.00GiB, used=2.08GiB
    GlobalReserve, single: total=193.25MiB, used=0.00B

    If your metadata is already duplicated, the output for System and Metadata is DUP instead of single (line 3 & 4).

    $ btrfs filesystem df /
    Data, single: total=99.01GiB, used=65.99GiB
    System, DUP: total=32.00MiB, used=16.00KiB
    Metadata, DUP: total=4.00GiB, used=2.08GiB
    GlobalReserve, single: total=193.25MiB, used=0.00B
  2. Make sure your filesystem does not have any errors prior to dup’ing metadata:
    $ sudo btrfs check --readonly --force </dev/XXX> #replace /dev/XXX with your btrfs device partition

    This should output something similar:

    Opening filesystem to check...
    WARNING: filesystem mounted, continuing because of --force
    Checking filesystem on /dev/nvme0n1p5
    UUID: 1fd193f1-d1fa-4e64-a719-ccde271dff8f
    [1/7] checking root items
    [2/7] checking extents
    [3/7] checking free space cache
    [4/7] checking fs roots
    [5/7] checking only csums items (without verifying data)
    [6/7] checking root refs
    [7/7] checking quota groups skipped (not enabled on this FS)
    found 73082724352 bytes used, no error found
    total csum bytes: 69072356
    total tree bytes: 2236448768
    total fs tree bytes: 2033647616
    total extent tree bytes: 112672768
    btree space waste bytes: 508260256
    file data blocks allocated: 262073368576
     referenced 228218974208

    If there are errors, do not continue to the next step.

  3. ย Using the BTRFS Balance command will enable you to duplicate the metadata:
    $ sudo btrfs balance start -mconvert=dup /
  4. If your disk is the average SSD, whether SATA or NVMe then the Balance operation should completely fairly quickly.

If you have any questions/comments regarding this article, click here or scroll down below (login isn't required to post comments and there's no waiting period).