My standard Linux server setup usually consists of a software raid1 with two disks syncing. The problem with traditional raid, both software and hardware raid, is that it is only useful if one of your drives completely dies. If you experience Silent Data Corruption or if your drive goes bad you might end up with the raid syncing junk across your disks.
In BTRFS, checksums are computed for both data and metadata, if the file system detects a checksum mismatch while reading a block, it first tries to obtain (or create) a good copy of this block from another device in the RAID.
In this article i will try out this next generation filesystem.
Prepare the disks
Start by emptying the disks, there is also an EXT4 converter but i haven’t tried it.
# dd if=/dev/zero of=/dev/sdb bs=512 count=1024 # dd if=/dev/zero of=/dev/sdc bs=512 count=1024
Create FS & RAID
I will use both -m (metadata) and -d (data) in RAID1 mode.
# mkfs.btrfs -m raid1 -d raid1 /dev/sdb /dev/sdc
Another way of usage is RAID0 (striping) for the DATA and RAID1 (mirroring) for the META, corruption in the META could result in the entire disk being unreadable while corruption in the data part usually only effect some of the files.
You should be running incremental rsync backups to a remote server and if you keep a close eye on the transfers you should also be able to detect if files that shouldn’t change is in the transfer list.
Mounting the new device
# btrfs filesystem show Label: none uuid: a4f2206b-6970-4095-9ba8-... Total devices 2 FS bytes used 128.00KiB devid 1 size 1.82TiB used 2.01GiB path /dev/sdb devid 2 size 1.82TiB used 2.01GiB path /dev/sdc
grab the uuid and mount your new raid
# mount /dev/disk/by-uuid/a4f2206b-6970-4095-9ba8-... /mnt
Use the drive for LXC
# rsync -avz /var/lib/ /mnt/ # umount /mnt # mount /dev/disk/by-uuid/a4f2206b-6970-4095-9ba8-... /var/lib/
Add the new disk to the filesystem table /etc/fstab
# vim /etc/fstab
UUID=a4f2206b-6970-4095-9ba8-... /var/lib btrfs defaults 0 0