Playing with btrfs
By wcoekaer on Sep 25, 2011
btrfs is included in Oracle Linux and we are working hard to help make this into a production supportable filesystem and make sure it's going through a huge amount of filesystem testing, recovery scenarios, performance etc.
Let's summarize a few of the features first :
- checksumming of data and metadata (CRC)
- built-in device/space management (spanned across devices) (so multiple device support no need for lvm)
- support for raid0, raid1, raid10 and single at this point (with raid5/6 in the works)
- ability to independently span metadata and data across these devices
- copy on write(COW) for both data and metadata
- writable snapshots
- create filesystem in existing btrfs pool without need to worry about device management
- online resize of filesystem (both grow and shrink)
- transparent compression, you can even specify for each file, or across all (lzo or zlib)
- ability to defrag files and/or directories
- balance command to balance filesystem chunks in a path across multiple devices if needed
- online add and remove devices to/from filesystems
- support for trim and SSD optimizations
- in place conversion from ext3/4 to btrfs
- file-based or object based cloning support with reflink (per file clone)
- file allocation is extent based with B-tree directory structures
- cool feature for cloning is that you can use filesystem seeding on read-only storage to then have a COW btrfs fs)
- for the little details :
- Max file size 16 EiB
- Max number of files 2^64
- Max volume size 16 EiB
Getting started is very easy. btrfs.ko is the kernel module that needs to be loaded and btrfs-progs is the package that has all the needed utilities to get started.
yum install btrfs-progs modprobe btrfs
I added 3 8gb devices to my system, per /proc/partitions output : /dev/sdb, /dev/sdc, /dev/sdd.
# cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 512000 sda1 8 2 20458496 sda2 8 16 8388608 sdb 8 32 8388608 sdc 8 48 8388608 sdd 253 0 16326656 dm-0 253 1 4128768 dm-1
So let's create a btrfs filesystem on those 3 devices and label it btrfstest. I will also use -d raid10 and -m raid10 to show how easy it is to decide your spanning choices for both.
# mkfs.btrfs -L btrfstest -d raid10 -m raid10 /dev/sdb /dev/sdc /dev/sdd WARNING! - Btrfs Btrfs v0.19 IS EXPERIMENTAL WARNING! - see http://btrfs.wiki.kernel.org before using adding device /dev/sdc id 2 adding device /dev/sdd id 3 fs created label btrfstest on /dev/sdb nodesize 4096 leafsize 4096 sectorsize 4096 size 24.00GB Btrfs Btrfs v0.19create a mountpoint /btrfs and mount the filesystem root there :
# mkdir /btrfs # mount -t btrfs /dev/sdb /btrfs /dev/sdb 25165824 28 25151488 1% /btrfs
as you can see, we now have a filesystem mounted that shows the diskspace of the 3 disks we added. btrfs filesystem show gives more detailed information including the device list and use :
# btrfs filesystem show Label: 'btrfstest' uuid: 123e52f9-87f2-4764-a347-5bedb3cb12df Total devices 3 FS bytes used 28.00KB devid 2 size 8.00GB used 0.00 path /dev/sdc devid 3 size 8.00GB used 0.00 path /dev/sdd devid 1 size 8.00GB used 20.00MB path /dev/sdb
Now to quickly show how easy it is to remove/add a device to an existing, mounted volume:
lets remove /dev/sdc
# btrfs device delete /dev/sdc /btrfs # btrfs filesystem show Label: 'btrfstest' uuid: 123e52f9-87f2-4764-a347-5bedb3cb12df Total devices 3 FS bytes used 28.00KB devid 3 size 8.00GB used 0.00 path /dev/sdd devid 1 size 8.00GB used 20.00MB path /dev/sdb *** Some devices missing # df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_wcoekaersrv3-lv_root 16070076 7494668 7759076 50% / tmpfs 1028992 0 1028992 0% /dev/shm /dev/sda1 495844 107990 362254 23% /boot /dev/sdb 16777216 28 16501760 1% /btrfsas you can see, it now shows 8GB less of space available. so, let's add it back in :
# btrfs device add /dev/sdc /btrfs # df Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/vg_wcoekaersrv3-lv_root 16070076 7494668 7759076 50% / tmpfs 1028992 0 1028992 0% /dev/shm /dev/sda1 495844 107990 362254 23% /boot /dev/sdb 25165824 28 24889344 1% /btrfs # btrfs filesystem show Label: 'btrfstest' uuid: 123e52f9-87f2-4764-a347-5bedb3cb12df Total devices 3 FS bytes used 28.00KB devid 4 size 8.00GB used 0.00 path /dev/sdc devid 3 size 8.00GB used 256.00MB path /dev/sdd devid 1 size 8.00GB used 20.00MB path /dev/sdband it's back!
on to snapshots. I created a few files in /btrfs and now want to create a snapshot. so while using sync I will first sync the fs and then create a snapshot under /btrfs/.snapshot:
# btrfs filesystem sync /btrfs # btrfs subvolume snapshot /btrfs /btrfs/.snapshot # ls /btrfs/.snapshot bar baz foo test # ls /btrfs bar baz foo test
and creating a new subvolume (a new possible mountpoint without any files, so not a snapshot just a mknewfs really)
# btrfs subvolume create /btrfs/test # btrfs subvolume list /btrfs ID 256 top level 5 path testSome random commands to play with : 1) filesystem df shows a more detailed explanation of what's going on.
# btrfs filesystem df /btrfs Data: total=8.00MB, used=0.00 System: total=4.00MB, used=8.00KB Metadata: total=264.00MB, used=24.00KB
2) list subvolumes :
# btrfs subvolume list /btrfs ID 256 top level 5 path test ID 257 top level 5 path .snapshot
3) if your filesystem is unbalanced due to tons of file creates and possible add/remove of devices you can rebalance it online :
# btrfs filesystem balance /btrfs
4) use cp to clone files on btrfs with COW (so individual file clones not just volumes) :
# cp --reflink foo1 foo4
5) deferagment filesystem :
btrfs filesystem defragment /btrfs
There you go. A quick 5 minute overview of some of the nifty stuff this FS can do and you have full access to. A lot more is coming and I will make sure to showcase new features as we make them available. Use this to have a backup root filesystem for recovery purposes, to do updates of rpms and the ability to fall back to a good previous known state. Use it for virtual machine files and the power of reflink. So many possibilities and virtually no filesystem or volume limits.
happy btrfs'ing :)