how-to-replace-a-failed-btrfs-device

The Problem

Originally the btrfs file system is build on multiple disks.

btrfs filesystem show
Label: 'MYBTRFS' uuid: 09138ad8-eb2f-4c7c-aef7-90482a67c45c
Total devices 3 FS bytes used 768.00KiB
devid 1 size 5.00GiB used 1.52GiB path /dev/xvdb
devid 2 size 5.00GiB used 520.00MiB path /dev/xvdc
devid 3 size 5.00GiB used 1.51GiB path /dev/xvdd

For some reason one disk is faulty and needs to be replaced.

# btrfs filesystem show
Label: 'MYBTRFS' uuid: 09138ad8-eb2f-4c7c-aef7-90482a67c45c
Total devices 3 FS bytes used 768.00KiB
devid 1 size 5.00GiB used 1.52GiB path /dev/xvdb
devid 3 size 5.00GiB used 1.51GiB path /dev/xvdd
*** Some devices missing

The Solution

Please note that these instructions assume you have the necessary knowledge and expertise to perform disk operations and work with the command-line interface. Make sure to take appropriate backups before proceeding and exercise caution to avoid data loss.
  1. Create a bootable OS on a USB drive and boot the system using the USB drive. Press Ctrl + Alt + F2 to access the shell.
  2. Mount the btrfs file system with the "-o degraded" option from the existing good volume:
mount -o degraded,rw,skip_balnce /dev/xvdd /mnt
  1. Check which device has failed:
btrfs device stats /mnt
  1. Identify the partition from a healthy disk:
fdisk /dev/sdb
- Enter 'p' to list partitions 
- Enter 'q' to quit
  1. Create a partition on the faulty disk (sdc) similar to the one on the healthy disk (sdb):
fdisk /dev/sdc 
- Delete all partitions using 'd' 
- Create a GPT partition using 'g' 
- Create a new partition using 'n' 
- Enter the same number of sectors as the partition on sdb 
- Change the file system type using 't'
  1. Replace the absent disk with the missing one (2 refers to the ID of the failed disk) : btrfs replace start <id> <new-disk> <mount-point>
btrfs replace start -r 2 /dev/xvdc /mnt/
  1. Check the status of the replace operation:
btrfs replace status /mnt

Remember to replace /dev/xvdd and /dev/xvdc with the appropriate device paths for your system.
also refer : https://wiki.tnonline.net/w/Btrfs/Replacing_a_disk