Can a failed Btrfs drive in RAID-1 be replaced live?

15

6

I am trying to decide on a filesystem and would like to know if it is possible to replace a failed drive in btrfs RAID without downtime.

  1. Suppose I create a new btrfs filesystem using the command

    mkfs.btrfs -d raid1 /dev/sdb /dev/sdc
    
  2. Now suppose one day /dev/sdc fails. There are two possibilities: it can fail gradually, showing S.M.A.R.T. errors - in this situation I can add a new device with btrfs device add /dev/sde /mnt; btrfs filesystem balance /mnt and then remove the old one with btrfs device delete /dev/sdc /mnt.

  3. But if it suddenly fails, becoming unreadable... A web search says in this situation I must first unmount the filesystem, mount in degraded mode, add a new device, then remove the missing device.

    umount /mnt
    mount -o degraded /dev/sdb /mnt
    btrfs device add /dev/sdf /mnt 
    btrfs device delete missing /mnt
    

An unmount is obviously a disruptive operation so there would be downtime - any application using the filesystem would get an I/O error. But these kind of "tutorials" on btrfs look outdated, considering btrfs is under heavy development.

Question is: considering current state of btrfs, is it possible to do this online, i.e. without unmounting?

If not, there is a software-only solution that can fulfill this need?

NothingsImpossible

Posted 2013-12-07T21:52:25.750

Reputation: 952

1If one drive catches fire, the rest of your system is probably on fire too – Journeyman Geek – 2013-12-21T14:21:04.090

1@JourneymanGeek Funny you.. :) I just wanted to make it very clear that I meant a catastrophic, sudden and unpredictable failure - the drive simply stops working. This is rather uncommon, hard disk usually fail gradually and with effective monitoring I can replace them before that happens, but what if... – NothingsImpossible – 2013-12-21T15:23:15.720

2In Linux 3.8 btrfs replace mountpoint old_disk new_disk was added. – Brian – 2013-12-28T14:29:42.333

@Brian woow... That is the answer. I googled for "btrfs replace" and this showed up http://lwn.net/Articles/524589/ . It is exactly what I was looking for. Please post it as an answer so I can accept it.

– NothingsImpossible – 2013-12-29T14:38:15.457

Answers

11

In Linux 3.8, btrfs replace mountpoint old_disk new_disk was added. If you're running a recent kernel, it will provide the functionality you are looking for.

Brian

Posted 2013-12-07T21:52:25.750

Reputation: 8 439

4This would now be btrfs replace start /dev/old /dev/new /mountpoint (start has been added). Also see man btrfs-replace. – basic6 – 2015-11-12T12:33:00.300

1

small correction, current syntax is:

btrfs replace start OLDDEV NEWDEV MOUNTPOINT

which then backgrounds.

You can check the status with

btrfs replace status MOUNTPOINT

which will show you a continuously updated status of the replace operation.

Volker

Posted 2013-12-07T21:52:25.750

Reputation: 11

1

This is not an answer to the original question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.

– DavidPostill – 2014-11-05T08:10:30.033