FUN WITH LINUX

Btrfs: Turning a mdadm-array into a btrfs

30 August 2015

Btrfs is supposed to be the “better filesystem”. It is easy to use and has a nice feature-list. Since I had some troubles with a raid1 using mdadm in the past, I will try to turn my private raid-array in a btrfs. In this article I will not post the mdadm-commands(and lvm2 commands)…

First I just remove one disk from my array and format it with btrfs:

mkfs.btrfs /dev/sdc

Now I have a single disk in my btrfs. The cool thing about btrfs is, that I can convert my btrfs to any supported raid during runtime. This feature I want to test. So first I will mount mount btrfs but I want to use compression on my filesystem. It’s super easy to use compression since it’s just a mount-option. I just created an entry in my /etc/fstab:

/dev/sdc /mnt/Raid btrfs compress=zlib,defaults 0 0

Now I can mount my btrfs:

mount /mnt/Raid

Now I can easily copy(for example using rsync) my data from the old mdadm-raid to my btrfs. Once this is done, I will just delete my mdadm-array and destroy the raid-meta-data using –zero-superblock( I made a backup of all my data before! ). After that I have a plain disk(/dev/sdb) and I will add this disk to my btrfs:

btrfs device add /dev/sdb /mnt/Raid/

Finally I was very courious if I can convert the btrfs into a raid1 using the following command:

btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt/Raid

This job runs in foreground so I would recommend using screen for it. It might take a long time. If you want to monitor the progress you can just use this command:

watch -n1 btrfs fi df /mnt/Raid

The following one-shot-command gives a good overview about your btrfs:

btrfs fi show; btfrs fi df /mnt/Raid

It really worked like expected. I just converted my single btrfs to a raid1 using 2 disks. But I have one problem: the filesystem is mounted using this fstab-entry:

/dev/sdc /mnt/Raid btrfs compress=zlib,defaults 0 0

What if /dev/sdc gets broken? Then I would have to manually mount /dev/sdb. It does not matter which device I do mount since both get synchronized but if the device doesn’t exist, the system would not be able to mount my filesystem. So I created a filesystem-label:

btrfs filesystem label /mnt/Raid/ RAIDBUTTER

And I changed my fstab-entry into:

LABEL=RAIDBUTTER /mnt/Raid btrfs compress=zlib,defaults 0 0

It’s not the end for me. Until now, I mounted my mdadm-raid and on this partition I had a directory for all my home-directories. This directory I mounted using bind-mount into /home. It was good enough for me, but it just feels like a dirty hack. Btrfs gives me the opportunity to create subvolumes. Those subvolumes I can mount wherever I want and it is just a directory in my normal btrfs. I created my subvolume using this command:

btrfs subvolume create /mnt/Raid/Home

At last I can mount it using this fstab-line:

LABEL=RAIDBUTTER /home btrfs subvol=Home,compress=zlib,auto,user 0 0

Great, isn’t it? In summary I can say that I really like the btrfs. It is very easy to use and has a nice feature list.

[ Linux  Sysadmin  Software-Raid  Filesystem  Btrfs  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti