Is btrfs ready for the prime time. In this howto for btrfs I will explore setting up some old hardware to get cheap storage.
One time I was a Solaris admin and as part of that I managed ZFS . Before ZFS, the main tool for handling storage on Sun systems was Disksuite. A perfectly good tool for the job but could be a bit over complicated. ZFS was like a breath of fresh air. Not only was it new, useful and easy to use, it was a Enterprise level tool. There was nothing quite like it. And it took a long time for anything else quite like it to appear.
For this set up I using a HP Gen 7 MicroServer that I got cheap on ebay. It’s got 8Gb of RAM, a dual core 1.6Ghz AMD processer and a 320Gb disk for the OS. I also got 3 super cheap 500GB disks that I can use for btrfs file systems. Not the most powerful system in the world but super reliable.
I install Arch Linux on onto this. If you have to install Arch then you can follow along my BlackArch installation guide.
You can use any hardware that has slots for multiple disks or any Modern Linux OS. If you are doing this to learn about btrfs then you can also just use a vm inside Virtual box. However I build this dedicated hardware to create a “seedbox“. I will expand on this in future posts.
Install btrfs couldn’t be easier. As I am using ArchLinux, the command is below. If you are using fedora, ubuntu or Centos just use the native package manager. btrfs is in all modern distributions.
pacman -S btrfs-progs
As I have 3 500G disks we can do a few things.
- Create a RAID1 stripe across all of them so it looks like one big storage volume.
- This gives you access to all the storage but has no redundancy.
- Mirror two of the disks with RAID0
- This give you access to 50% of the storage but has high redundancy.
- Or create a RAID5 with the three disks.
- This also has redundancy and give you access to about 70% of the storage.
So although there are a lot of improvements around RAID5, its not recommended to use it as certain conditions can lead to data-loss.
So I am left with creating a mirror for 2 x 500Gb. And that leaves me with 500Gb of storage that has no redundancy.
Creating a btrfs File System
Like other files systems in Linux the mkfs command can be used to create a btrfs file system.
mkfs.btrfs -f /dev/sdb
This creates a simple brtfs file system on one disk.
Like anyother file system it can be mounted via the mount command.
mount -t btfs /dev/sdb /mnt
Creating a Mirrored File-System
Now I have two 500Gb disks left I can create a mirrored volume. The btrfs tools makes this really easy.
mkfs.btrfs -L myMirror01 -m raid1 -d raid1 /dev/sdc /dev/sdd
Lets break down this command.
|-L myMirror01||Label or name of the mirror|
|-f||Overwrites existing file systems (Careful with this)|
|-m raid1||mirror metadata|
|-d raid1||mirror the data|
|/dev/sdc /dev/sdd||Disks to be used|
After the device is created we can get this information again by running
btrfs filesystem show
This mirrored filesystem can be mounted by using any of the underlying devices.
mount -t btrfs /dev/sdc /mnt
A BTRFS subvolume is a part of filesystem with its own independent file/directory hierarchy and inode number namespace. A subvolume looks like a normal directory, with some additional operations which allows them to be moved, copied or snapshots taken with ease. For this set I will two subvolumes.
- Docker – Where I will store docker configuration files
- Downloads – A subvolume folder where Downloads are kept
btrfs subvolume create /mnt/downloads btrfs subvolume create /mnt/downloads/config btrfs subvolume create /mnt/docker
To list the new subvolumes
btrfs subvolume list /mnt
Automounting at boot time.
The file systems and subvolumes can be mounted as separate file systems. First we get the UUID of the file system with the label “myMirror01” and mount it via /etc/fstab
btrfs filesystem show
In the file “/etc/fstab” we can make the below entry.
UUID=e896b435-5da4-433a-9a3a-ab6725152168 /data btrfs defaults 0 1
Then we can mount it via the mount command. (umount /mnt if you mounted it)
umount /mnt mount /data
Mounting the subvolumes.
Subvolumes can also be mounted by using a mount option “subvol=”. So the entries for adding our three subvolumes would be,
UUID=e896b435-5da4-433a-9a3a-ab6725152168 /data btrfs defaults 0 1 UUID=e896b435-5da4-433a-9a3a-ab6725152168 /data/downloads btrfs subvol=downloads,defaults 0 1 UUID=e896b435-5da4-433a-9a3a-ab6725152168 /data/downloads/config btrfs subvol=downloads/config,defaults 0 1 UUID=e896b435-5da4-433a-9a3a-ab6725152168 /data/docker btrfs ubvol=docker,defaults 0 1
btrfs has a great snapshotting tool. We can create snapshots of subvolumes easily. As this storage will eventually be shared to windows systems, then ransomware is always a risk. So regular snapshots can save you a lot of trouble in the long run.
I like to put my snapshots in hidden folders so I will use the naming convection “.snapshot”. But you can use what ever you like.
Create a snapshot of the /data/docker subvolume.
btrfs subvolume snapshot /data/docker /data/docker/.snapshot
This creates a snapshot into the folder “/data/docker/.snapshot”. Navigate to that directory and you’ll find all the data that was in the directory you took a snapshot of in the same structure
While create this I found a lot of usful links that I will share as you might also find them useful.
btrfs could possibly be the future of Linux filesystems as it has some very advanced features. However, it has not yet caught up with zfs but its getting there. So far I am happy with the results I got from and only time will tell if it performs as expected.
I hope this btrfs howto was useful and if so, then please leave any comments in the section below.
Be First to Comment