DEV Community

loading...

How to Recover Data from a BtrFS Drive or RAID System

Michael Mirosnichenko
Hetman Software develops specialized data recovery and file repair tools. Years of experience in this field allow us to develop the most efficient and high-quality solutions.
・5 min read

From this article, you’ll learn how to recover data from a software BtrFS RAID on Linux. How to create a BtrFS RAID, replace a faulty disk, and how to recover lost data from a damaged disk array.

How to Recover Data from a BtrFS Drive or RAID System

Usually, mdadm and lvm are used to create a RAID system in Linux, and you can learn more about them from other videos on our channel.

YouTube:

In addition to the tools described in this video, another helpful thing you can discover is the integrated RAID support in BtrFS file system. It uses its own means to build and manage disk arrays, so let’s have a closer look at all of its features.

BtrFS file system

BtrFS is a modern file system with the integrated Copy on Write feature and RAID support. The core of this option is that old data does not have to be overwritten when copied. As a huge bonus, it makes file recovery after failures and crashes much easier, because an error or interruption during the copying process does not affect the previous condition of the files.

BtrFS stores metadata separately from the file system data, and its main advantage is that you can use various RAID levels for data and metadata. Another purpose of this journaled file system is to provide a more effective way to manage the storage system and improve data integrity features in Linux.

Before you can start using BtrFS, it is required to install several tools for file system management, by running the following command:

sudo apt install btrfs-tools
Enter fullscreen mode Exit fullscreen mode

sudo apt install btrfs-tools

Create a mount point

You have to create a mount point directory for BtrFS file system before you can build a RAID array.

Let’s create the directory:

Sudo mkdir –v /data
Enter fullscreen mode Exit fullscreen mode

Where “data” is the directory name.

Sudo mkdir –v /data

Now let’s move on to create a disk array.

How to create a RAID 5

When you create an array, you don’t have to divide drives into partitions, as this file system has no such requirement. You can unite both entire drives or specific partitions into a disk array, and even combine drives and partitions. For illustration, I’ll show you how to use five hard disks to create a RAID5 system.

To save the trouble of having to enter the root password every time, run the sudo -i command and type the password, and now you can run all commands as administrator.

enter the root password every time

To build a RAID system, type this command in the terminal:

sudo mkfs.btrfs -L data -m raid5 -d raid5 -f /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf
Enter fullscreen mode Exit fullscreen mode

where:

  • L is the mark or name of the file system

Index:

  • d sets the type of RAID5 for data.

  • m sets the type of RAID5 for metadata.

  • f forces creation of BtrFS even if any of the drives is already formatted into a different file system.

sudo mkfs.btrfs -L data -m raid5 -d raid5

Now you can mount this BtrFS RAID using any of the drives included in your array.

How to mount a RAID drive

In my case, I used 5 drives to create a RAID: sdb, sdc, sdd, sde, and sdf. That is why I can mount the file system data with the help of drive sdb in the directory with the name “data”. Open Disk Management and mount the drive, and then it becomes available.

How to mount a RAID drive

Otherwise, you can use the following command to mount the drive in the terminal.

sudo mount /dev/sdb1 /data
Enter fullscreen mode Exit fullscreen mode

Check the result by typing this command: sudo df -h

Now the array is mounted in the directory /data

sudo mount /dev/sdb1 /data

To view the information on the amount of used and free space in this array, type the following:

sudo btrfs filesystem usage /data
Enter fullscreen mode Exit fullscreen mode

sudo btrfs filesystem usage /data

To unmount the array, just type this command:

sudo umount /data
Enter fullscreen mode Exit fullscreen mode

sudo umount /data

How to replace or add a drive

To replace a drive, type this in the Terminal: btrfs replace. The operation is run asynchronously, that is, in a step-by-step manner:

  • start - to launch the process,
  • cancel - to stop it,
  • status - and to view the operation status. First of all, you need to identify the number of the damaged drive with the help of this command:
sudo btrfs filesystem show
Enter fullscreen mode Exit fullscreen mode

sudo btrfs filesystem show

Then replace it with a new one:

btrfs replace start <removed device or its ID> <added device> <the path where btrfs is mounted>
Enter fullscreen mode Exit fullscreen mode

In my case, I type this:

btrfs replace start 3 /dev/sdg
Enter fullscreen mode Exit fullscreen mode

where: 3 – the number of the missing drive, and sdg – the code of the new drive.

btrfs replace start 3 /dev/sdg

How to recover a damaged volume

To recover a BtrFS array you need to use the integrated mounting option - recovery:

sudo mount -o recovery /dev/sdb /mnt
Enter fullscreen mode Exit fullscreen mode

sudo mount -o recovery /dev/sdb /mnt

It starts the recovery process.

Data recovery from BtrFS RAID 5

Even the most reliable and fault-tolerant system may fail someday. A system error, drive failure, hardware issues, damaged metadata, accidental removal or wrong settings - any of these may result in knocking the RAID down and causing a loss of important information. If you face anything from that list, just use Hetman RAID Recovery. It is capable of recovering any information from inoperable disk arrays or drives that used to be a part of the array. The utility will rebuild the damaged RAID, reading all available information step by step, and then you’ll be able to copy all the detected data elsewhere.

Connect the drives to a Windows computer, or use a virtual machine, or install Windows as the second operating system.

The program will scan the drives automatically and display all the information about your array.

program will scan the drives automatically and display all

As you can see, in the case with BtrFS RAID the program doesn’t collect the drives into a single array (this can be explained by peculiarities of building this array type), but all the information is stored according to the RAID type which is used.

Watch the full article with all additional video tutorials. Also visit our Youtube channel, there are over 400 video tutorials.

Discussion (0)