Btrfs raid6


See archlinux for more…
Create btrfs filesystem using raid6 for data and and raid 10 for metadata

mkfs.btrfs -d raid6 -m raid10 -L alexandria_btrfs /dev/vd[bcdefghijk]

Mount newly created partition with

mount /dev/sdb /mnt/md0

Check file system usage with:

btrfs filesystem df /mnt/md0

Removing devices

Remove a drive from the file system. This should rebalance the data across the other devices. btrfs device delete is used to remove devices online. It redistributes the any extents in use on the device being removed to the other devices in the filesystem.

# mount fs first
btrfs device delete /dev/vdX /mnt/md0

Adding devices

btrfs device add is used to add new devices to a mounted filesystem.
btrfs filesystem balance can balance (restripe) the allocated extents across all of the existing devices. For example, with an existing filesystem mounted at /mnt/md0, you can add the device /dev/vdX to it with:

btrfs device add /dev/vdX /mnt/md0

This should commence a resync.

At this point we have a filesystem with two devices, but all of the metadata and data are still stored on the original device(s). The filesystem must be balanced to spread the files across all of the devices.

btrfs filesystem balance /mnt/md0

List of all the btrfs filesystems

btrfs filesystem show gives you a list of all the btrfs filesystems on the systems and which devices they include.

btrfs filesystem show

Label: 'alexandria_btrfs'  uuid: abdef71f-d813-4128-bc39-de3df7e6c673
        Total devices 10 FS bytes used 217.73GiB
        devid    1 size 1.82TiB used 29.42GiB path /dev/sdb
        devid    2 size 1.82TiB used 29.40GiB path /dev/sdc
        devid    3 size 1.82TiB used 29.40GiB path /dev/sdd
        devid    4 size 1.82TiB used 29.40GiB path /dev/sde
        devid    5 size 1.82TiB used 29.40GiB path /dev/sdf
        devid    6 size 1.82TiB used 29.40GiB path /dev/sdg
        devid    7 size 1.82TiB used 29.40GiB path /dev/sdh
        devid    8 size 1.82TiB used 29.40GiB path /dev/sdi
        devid    9 size 1.82TiB used 29.40GiB path /dev/sdj
        devid   10 size 1.82TiB used 29.40GiB path /dev/sdk

btrfs-progs v4.0.1

Replacing failed devices

The example above can be used to remove a failed device if the super block can still be read. But, if a device is missing or the super block has been corrupted, the filesystem will need to be mounted in degraded mode:

btrfs filesystem show

Label: 'alexandria_btrfs'  uuid: abdef71f-d813-4128-bc39-de3df7e6c673
        Total devices 10 FS bytes used 14.50TiB
        devid    1 size 1.82TiB used 1.82TiB path /dev/sdb
        devid    2 size 1.82TiB used 1.82TiB path /dev/sdc
        devid    3 size 1.82TiB used 1.82TiB path /dev/sdd
        devid    4 size 1.82TiB used 1.82TiB path /dev/sde
        devid    5 size 1.82TiB used 1.82TiB path /dev/sdf
        devid    6 size 1.82TiB used 1.82TiB path /dev/sdg
        devid    7 size 1.82TiB used 1.82TiB path /dev/sdh
        devid    8 size 1.82TiB used 1.82TiB path /dev/sdi
        devid   10 size 1.82TiB used 1.82TiB path /dev/sdk
        *** Some devices missing


# sdd is destroyed or removed, use -o degraded to force the mount
# to ignore missing devices#
mount -o degraded /dev/sdX /mnt/md0
#
btrfs device delete missing /mnt/md0
btrfs replace start 9 /dev/sdX_new_disk /mnt/md0
btrfs replace status /mnt/md0
#
# cancel replacement with
# btrfs replace cancel /dev/md0

Conversion

A non-raid filesystem is converted to raid by adding a device and running a balance filter that will change the chunk allocation profile.
For example, to convert an existing single device system (/dev/sdX1) into a 2 device raid1 (to protect against a single disk failure):

mount /dev/sdX1 /mnt/md0
btrfs device add /dev/sdY1 /mnt/md0
btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt/md0

If the metadata is not converted from the single-device default, it remains as DUP, which does not guarantee that copies of block are on separate devices. If data is not converted it does not have any redundant copies at all.

Scrub

Scrub is an online file system checking tool. Reads all the data and metadata on the file system, and uses checksums and the duplicate copies from RAID storage to identify and repair any corrupt data.

btrfs scrub start /
btrfs scrub status /

(from archlinux)
Warning: The running scrub process will prevent the system from suspending, see this thread for details.
If running the scrub as a systemd service, use Type=forking. Alternatively, you can pass the -B flag to btrfs scrub start to run it in the foreground and use the default Type value.

Balance

Balance passes all data in the filesystem through the allocator again. It is primarily intended to rebalance the data in the filesystem across the devices when a device is added or removed. A balance will regenerate missing copies for the redundant RAID levels, if a device has failed. As of linux kernel 3.3, a balance operation can be made selective about which parts of the filesystem are rewritten.

btrfs balance start /
btrfs balance status /

Defragment

Btrfs supports transparent compression, meaning every file on the partition is automatically compressed. This not only reduces the size of files, but also improves performance, in particular if using the lzo algorithm, in some specific use cases (e.g. single thread with heavy file IO), while obviously harming performance on other cases (e.g. multithreaded and/or cpu intensive tasks with large file IO).

Compression is enabled using the compress=zlib or compress=lzo mount options. Only files created or modified after the mount option is added will be compressed. However, it can be applied quite easily to existing files (e.g. after a conversion from ext3/4) using the btrfs filesystem defragment -calg command, where alg is either zlib or lzo. In order to re-compress the whole file system with lzo, run the following command:

btrfs filesystem defragment -r -v -clzo /

Tip: Compression can also be enabled per-file without using the compress mount option; simply apply chattr +c to the file. When applied to directories, it will cause new files to be automatically compressed as they come.
When installing Arch to an empty Btrfs partition, set the compress option after preparing the storage drive. Simply switch to another terminal (Ctrl+Alt+number), and run the following command:

mount -o remount,compress=lzo /mnt/target

After the installation is finished, add compress=lzo to the mount options of the root file system in fstab.


Comments are closed.